cache: release the ByteBuf allocated when calling ByteBuf#readBytes(int)
This commit is contained in:
@@ -55,14 +55,14 @@ public class ArchiveResponseEncoder extends MessageToByteEncoder<ArchiveResponse
|
||||
// - 3 for the header
|
||||
int chunkSize = Math.min(file.readableBytes(), CHUNK_SIZE - 3);
|
||||
|
||||
out.writeBytes(file.readBytes(chunkSize));
|
||||
writeChunk(file.readBytes(chunkSize), out);
|
||||
|
||||
while (file.isReadable())
|
||||
{
|
||||
out.writeByte(0xff);
|
||||
|
||||
chunkSize = Math.min(file.readableBytes(), CHUNK_SIZE - 1);
|
||||
out.writeBytes(file.readBytes(chunkSize));
|
||||
writeChunk(file.readBytes(chunkSize), out);
|
||||
}
|
||||
|
||||
int size = out.readableBytes() - pos;
|
||||
@@ -71,4 +71,16 @@ public class ArchiveResponseEncoder extends MessageToByteEncoder<ArchiveResponse
|
||||
archiveResponse.getData().length, size);
|
||||
}
|
||||
|
||||
private void writeChunk(ByteBuf chunk, ByteBuf out)
|
||||
{
|
||||
try
|
||||
{
|
||||
out.writeBytes(chunk);
|
||||
}
|
||||
finally
|
||||
{
|
||||
chunk.release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user