cache: release the ByteBuf allocated when calling ByteBuf#readBytes(int)

This commit is contained in:
Joshua Filby
2018-02-19 10:16:18 -06:00
committed by Adam
parent 55a5eaa43d
commit ee35d32312

View File

@@ -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();
}
}
}