Use the source frame's allocator instead of the unpooled allocator

This commit is contained in:
Trustin Lee 2014-01-14 14:22:06 +09:00
parent ae6aea794c
commit 2f9ad15d3f

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.ByteBufAllocator;
import java.util.zip.DataFormatException; import java.util.zip.DataFormatException;
import java.util.zip.Inflater; import java.util.zip.Inflater;
@ -41,7 +41,7 @@ final class SpdyHeaderBlockZlibDecoder extends SpdyHeaderBlockRawDecoder {
int numBytes; int numBytes;
do { do {
numBytes = decompress(frame); numBytes = decompress(encoded.alloc(), frame);
} while (numBytes > 0); } while (numBytes > 0);
if (decompressor.getRemaining() != 0) { if (decompressor.getRemaining() != 0) {
@ -65,8 +65,8 @@ final class SpdyHeaderBlockZlibDecoder extends SpdyHeaderBlockRawDecoder {
return len; return len;
} }
private int decompress(SpdyHeadersFrame frame) throws Exception { private int decompress(ByteBufAllocator alloc, SpdyHeadersFrame frame) throws Exception {
ensureBuffer(); ensureBuffer(alloc);
byte[] out = decompressed.array(); byte[] out = decompressed.array();
int off = decompressed.arrayOffset() + decompressed.writerIndex(); int off = decompressed.arrayOffset() + decompressed.writerIndex();
try { try {
@ -87,23 +87,30 @@ final class SpdyHeaderBlockZlibDecoder extends SpdyHeaderBlockRawDecoder {
} }
} }
private void ensureBuffer() { private void ensureBuffer(ByteBufAllocator alloc) {
if (decompressed == null) { if (decompressed == null) {
decompressed = Unpooled.buffer(DEFAULT_BUFFER_CAPACITY); decompressed = alloc.heapBuffer(DEFAULT_BUFFER_CAPACITY);
} }
decompressed.ensureWritable(1); decompressed.ensureWritable(1);
} }
@Override @Override
void reset() { void reset() {
decompressed = null; releaseBuffer();
super.reset(); super.reset();
} }
@Override @Override
public void end() { public void end() {
decompressed = null; releaseBuffer();
decompressor.end(); decompressor.end();
super.end(); super.end();
} }
private void releaseBuffer() {
if (decompressed != null) {
decompressed.release();
decompressed = null;
}
}
} }