Make ByteBufferAccumulator direct configurable

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-12-01 10:01:31 +11:00
parent 602cd7e5c0
commit 6dce1cbffd
5 changed files with 11 additions and 9 deletions

View File

@ -39,15 +39,17 @@ public class ByteBufferAccumulator implements AutoCloseable
{
private final List<ByteBuffer> _buffers = new ArrayList<>();
private final ByteBufferPool _bufferPool;
private final boolean _direct;
public ByteBufferAccumulator()
{
this(null);
this(null, false);
}
public ByteBufferAccumulator(ByteBufferPool bufferPool)
public ByteBufferAccumulator(ByteBufferPool bufferPool, boolean direct)
{
_bufferPool = (bufferPool == null) ? new NullByteBufferPool() : bufferPool;
_direct = direct;
}
/**
@ -129,7 +131,7 @@ public class ByteBufferAccumulator implements AutoCloseable
}
int length = getLength();
combinedBuffer = _bufferPool.acquire(length, false);
combinedBuffer = _bufferPool.acquire(length, _direct);
BufferUtil.clearToFill(combinedBuffer);
for (ByteBuffer buffer : _buffers)
{

View File

@ -36,12 +36,12 @@ public class ByteBufferOutputStream2 extends OutputStream
public ByteBufferOutputStream2()
{
this(null);
this(null, false);
}
public ByteBufferOutputStream2(ByteBufferPool bufferPool)
public ByteBufferOutputStream2(ByteBufferPool bufferPool, boolean direct)
{
_accumulator = new ByteBufferAccumulator((bufferPool == null) ? new NullByteBufferPool() : bufferPool);
_accumulator = new ByteBufferAccumulator((bufferPool == null) ? new NullByteBufferPool() : bufferPool, direct);
}
public ByteBufferPool getByteBufferPool()

View File

@ -42,7 +42,7 @@ public class ByteBufferAccumulatorTest
public void before()
{
byteBufferPool = new CountingBufferPool();
accumulator = new ByteBufferAccumulator(byteBufferPool);
accumulator = new ByteBufferAccumulator(byteBufferPool, false);
}
@Test

View File

@ -45,7 +45,7 @@ public class ByteAccumulator implements AutoCloseable
public ByteAccumulator(int maxOverallBufferSize, ByteBufferPool byteBufferPool)
{
this.maxSize = maxOverallBufferSize;
this.accumulator = new ByteBufferAccumulator(byteBufferPool);
this.accumulator = new ByteBufferAccumulator(byteBufferPool, false);
}
public int getLength()

View File

@ -492,7 +492,7 @@ public abstract class CompressExtension extends AbstractExtension
if (!deflater.needsInput() || supplyInput(deflater, data))
{
ByteBufferPool bufferPool = getBufferPool();
try (ByteBufferAccumulator accumulator = new ByteBufferAccumulator(bufferPool))
try (ByteBufferAccumulator accumulator = new ByteBufferAccumulator(bufferPool, false))
{
while (true)
{