Issue #5499 - takeBuffer releases all the buffers in the list

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-11-13 09:22:57 +11:00
parent d75e6de1b2
commit e0031e0585
1 changed files with 11 additions and 6 deletions

View File

@ -79,23 +79,28 @@ public class ByteBufferAccumulator implements AutoCloseable
public ByteBuffer takeByteBuffer()
{
ByteBuffer combinedBuffer;
if (_buffers.size() == 1)
{
combinedBuffer = _buffers.get(0);
_buffers.clear();
return combinedBuffer;
}
int length = getLength();
ByteBuffer combinedBuffer = _bufferPool.acquire(length, false);
combinedBuffer = _bufferPool.acquire(length, false);
for (ByteBuffer buffer : _buffers)
{
combinedBuffer.put(buffer);
_bufferPool.release(buffer);
}
_buffers.clear();
return combinedBuffer;
}
public ByteBuffer toByteBuffer()
{
if (_buffers.size() == 1)
return _buffers.get(0);
ByteBuffer combinedBuffer = takeByteBuffer();
_buffers.forEach(_bufferPool::release);
_buffers.clear();
_buffers.add(combinedBuffer);
return combinedBuffer;
}