diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultMemcacheObject.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultMemcacheObject.java
index 2806ffbb40..6e37c17f10 100644
--- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultMemcacheObject.java
+++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/DefaultMemcacheObject.java
@@ -16,7 +16,6 @@
package io.netty.handler.codec.memcache;
import io.netty.handler.codec.DecoderResult;
-import io.netty.util.AbstractReferenceCounted;
/**
* The default {@link MemcacheObject} implementation.
diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheContent.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheContent.java
index afec9a2281..799eb77b09 100644
--- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheContent.java
+++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheContent.java
@@ -16,6 +16,7 @@
package io.netty.handler.codec.memcache;
import io.netty.buffer.ByteBufHolder;
+import io.netty.channel.ChannelPipeline;
/**
* An Memcache content chunk.
@@ -23,7 +24,7 @@ import io.netty.buffer.ByteBufHolder;
* A MemcacheObjectDecoder generates {@link MemcacheContent} after
* {@link MemcacheMessage} when the content is large. If you prefer not to
* receive {@link MemcacheContent} in your handler, place a aggregator
- * after MemcacheObjectDecoder in the {@link io.netty.channel.ChannelPipeline}.
+ * after MemcacheObjectDecoder in the {@link ChannelPipeline}.
*/
public interface MemcacheContent extends MemcacheObject, ByteBufHolder {
diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheObjectAggregator.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheObjectAggregator.java
index e1d75ce18a..430156b28c 100644
--- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheObjectAggregator.java
+++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/MemcacheObjectAggregator.java
@@ -15,25 +15,29 @@
*/
package io.netty.handler.codec.memcache;
+import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.MessageToMessageDecoder;
+import io.netty.handler.codec.memcache.binary.BinaryMemcacheRequestDecoder;
+import io.netty.handler.codec.memcache.binary.BinaryMemcacheResponseEncoder;
/**
- * A {@link io.netty.channel.ChannelHandler} that aggregates an {@link MemcacheMessage}
+ * A {@link ChannelHandler} that aggregates an {@link MemcacheMessage}
* and its following {@link MemcacheContent}s into a single {@link MemcacheMessage} with
* no following {@link MemcacheContent}s. It is useful when you don't want to take
* care of memcache messages where the content comes along in chunks. Insert this
- * handler after a MemcacheObjectDecoder in the {@link io.netty.channel.ChannelPipeline}.
+ * handler after a MemcacheObjectDecoder in the {@link ChannelPipeline}.
*
* For example, here for the binary protocol:
*
*
- * {@link io.netty.channel.ChannelPipeline} p = ...;
+ * {@link ChannelPipeline} p = ...;
* ...
- * p.addLast("decoder", new {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheRequestDecoder}());
+ * p.addLast("decoder", new {@link BinaryMemcacheRequestDecoder}());
* p.addLast("aggregator", new {@link MemcacheObjectAggregator}(1048576));
* ...
- * p.addLast("encoder", new {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheResponseEncoder}());
+ * p.addLast("encoder", new {@link BinaryMemcacheResponseEncoder}());
* p.addLast("handler", new YourMemcacheRequestHandler());
*
*/
@@ -55,7 +59,7 @@ public abstract class MemcacheObjectAggregator extends MessageToMessageDecoder
* The difference in the protocols (header) is implemented by the subclasses.
*/
-public abstract class BinaryMemcacheDecoder
+public abstract class BinaryMemcacheDecoder, H extends BinaryMemcacheMessageHeader>
extends MemcacheObjectDecoder {
public static final int DEFAULT_MAX_CHUNK_SIZE = 8192;
@@ -50,7 +50,7 @@ public abstract class BinaryMemcacheDecoder 0) {
if (toRead == 0) {
return;
- } else if (toRead > chunkSize) {
+ }
+
+ if (toRead > chunkSize) {
toRead = chunkSize;
}
@@ -119,7 +121,7 @@ public abstract class BinaryMemcacheDecoder= valueLength;
+ boolean isLast = alreadyReadChunkSize + toRead >= valueLength;
MemcacheContent chunk = isLast
? new DefaultLastMemcacheContent(chunkBuffer)
: new DefaultMemcacheContent(chunkBuffer);
diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheEncoder.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheEncoder.java
index 242f2c4420..ce2660693a 100644
--- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheEncoder.java
+++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheEncoder.java
@@ -18,20 +18,21 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.memcache.MemcacheObjectEncoder;
import io.netty.util.CharsetUtil;
/**
- * A {@link io.netty.handler.codec.MessageToByteEncoder} that encodes binary memache messages into bytes.
+ * A {@link MessageToByteEncoder} that encodes binary memache messages into bytes.
*/
-public abstract class BinaryMemcacheEncoder
+public abstract class BinaryMemcacheEncoder, H extends BinaryMemcacheMessageHeader>
extends MemcacheObjectEncoder {
@Override
protected ByteBuf encodeMessage(ChannelHandlerContext ctx, M msg) {
ByteBuf buf = ctx.alloc().buffer();
- encodeHeader(buf, (H) msg.getHeader());
+ encodeHeader(buf, msg.getHeader());
encodeExtras(buf, msg.getExtras());
encodeKey(buf, msg.getKey());
@@ -44,7 +45,7 @@ public abstract class BinaryMemcacheEncoder ex
/**
* Increases the reference count by {@code 1}.
*/
- BinaryMemcacheMessage retain();
+ @Override
+ BinaryMemcacheMessage retain();
/**
* Increases the reference count by the specified {@code increment}.
*/
- BinaryMemcacheMessage retain(int increment);
+ @Override
+ BinaryMemcacheMessage retain(int increment);
}
diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheRequest.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheRequest.java
index 7be1b6ee0c..3c8291c674 100644
--- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheRequest.java
+++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheRequest.java
@@ -25,6 +25,7 @@ public interface BinaryMemcacheRequest extends BinaryMemcacheMessage
* Note that while the additional field in the request is called "reserved", it can still be used for a custom
* memcached implementation. It will not be mirrored back like the
- * {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheRequestHeader#getOpaque()} field, because in the
+ * {@link BinaryMemcacheRequestHeader#getOpaque()} field, because in the
* {@link BinaryMemcacheResponseHeader}, the status field is set there instead.
*/
public interface BinaryMemcacheRequestHeader extends BinaryMemcacheMessageHeader {
diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheResponse.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheResponse.java
index 63d623ab44..60f95aaf06 100644
--- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheResponse.java
+++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheResponse.java
@@ -25,6 +25,7 @@ public interface BinaryMemcacheResponse extends BinaryMemcacheMessage {
public BinaryMemcacheServerCodec() {
- this(BinaryMemcacheRequestDecoder.DEFAULT_MAX_CHUNK_SIZE);
+ this(BinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
}
public BinaryMemcacheServerCodec(int decodeChunkSize) {
diff --git a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheMessage.java b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheMessage.java
index 4101e38793..81d4c581bd 100644
--- a/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheMessage.java
+++ b/codec-memcache/src/main/java/io/netty/handler/codec/memcache/binary/DefaultBinaryMemcacheMessage.java
@@ -17,8 +17,6 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.memcache.DefaultMemcacheObject;
-import io.netty.util.AbstractReferenceCounted;
-import io.netty.util.ReferenceCounted;
/**
* Default implementation of a {@link BinaryMemcacheMessage}.
@@ -49,7 +47,7 @@ public abstract class DefaultBinaryMemcacheMessage retain() {
if (extras != null) {
extras.retain();
}
@@ -87,7 +85,7 @@ public abstract class DefaultBinaryMemcacheMessage retain(int increment) {
if (extras != null) {
extras.retain(increment);
}
diff --git a/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheDecoderTest.java b/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheDecoderTest.java
index da4f3c772c..32bcd855e2 100644
--- a/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheDecoderTest.java
+++ b/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheDecoderTest.java
@@ -23,9 +23,8 @@ import io.netty.handler.codec.memcache.MemcacheContent;
import org.junit.Before;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
@@ -40,7 +39,7 @@ public class BinaryMemcacheDecoderTest {
/**
* Represents a GET request header with a key size of three.
*/
- private static final byte[] GET_REQUEST = new byte[]{
+ private static final byte[] GET_REQUEST = {
(byte) 0x80, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03,
@@ -50,7 +49,7 @@ public class BinaryMemcacheDecoderTest {
0x66, 0x6f, 0x6f
};
- private static final byte[] SET_REQUEST_WITH_CONTENT = new byte[]{
+ private static final byte[] SET_REQUEST_WITH_CONTENT = {
(byte) 0x80, 0x01, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0B,
diff --git a/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheObjectAggregatorTest.java b/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheObjectAggregatorTest.java
index a98691cb73..2e9399d041 100644
--- a/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheObjectAggregatorTest.java
+++ b/codec-memcache/src/test/java/io/netty/handler/codec/memcache/binary/BinaryMemcacheObjectAggregatorTest.java
@@ -18,18 +18,10 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
-import io.netty.handler.codec.memcache.LastMemcacheContent;
-import io.netty.handler.codec.memcache.MemcacheContent;
-import io.netty.util.CharsetUtil;
-import org.hamcrest.CoreMatchers;
-import org.junit.Before;
import org.junit.Test;
-import java.nio.charset.Charset;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsNull.nullValue;
@@ -38,7 +30,7 @@ import static org.hamcrest.core.IsNull.nullValue;
*/
public class BinaryMemcacheObjectAggregatorTest {
- private static final byte[] SET_REQUEST_WITH_CONTENT = new byte[]{
+ private static final byte[] SET_REQUEST_WITH_CONTENT = {
(byte) 0x80, 0x01, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0B,