Use the ByteBufAllocator when possible

This commit is contained in:
Norman Maurer 2013-07-14 23:34:36 +02:00
parent 0393ffbfb2
commit 3140282ae3
4 changed files with 6 additions and 7 deletions

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.serialization.ObjectDecoder;
@ -423,7 +422,7 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder {
// extract frame
int readerIndex = in.readerIndex();
int actualFrameLength = frameLengthInt - initialBytesToStrip;
ByteBuf frame = extractFrame(in, readerIndex, actualFrameLength);
ByteBuf frame = extractFrame(ctx, in, readerIndex, actualFrameLength);
in.readerIndex(readerIndex + actualFrameLength);
return frame;
}
@ -483,8 +482,8 @@ public class LengthFieldBasedFrameDecoder extends ByteToMessageDecoder {
* Refer to the source code of {@link ObjectDecoder} to see how this method
* is overridden to avoid memory copy.
*/
protected ByteBuf extractFrame(ByteBuf buffer, int index, int length) {
ByteBuf frame = Unpooled.buffer(length);
protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
ByteBuf frame = ctx.alloc().buffer(length);
frame.writeBytes(buffer, index, length);
return frame;
}

View File

@ -233,7 +233,7 @@ public class JdkZlibEncoder extends ZlibEncoder {
return promise;
}
ByteBuf footer = Unpooled.buffer();
ByteBuf footer = ctx.alloc().buffer();
synchronized (deflater) {
deflater.finish();
while (!deflater.finished()) {

View File

@ -81,7 +81,7 @@ public class MarshallingDecoder extends LengthFieldBasedFrameDecoder {
}
@Override
protected ByteBuf extractFrame(ByteBuf buffer, int index, int length) {
protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
return buffer.slice(index, length);
}
}

View File

@ -75,7 +75,7 @@ public class ObjectDecoder extends LengthFieldBasedFrameDecoder {
}
@Override
protected ByteBuf extractFrame(ByteBuf buffer, int index, int length) {
protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length) {
return buffer.slice(index, length);
}
}