Make ByteBufferAccumulator direct configurable
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
602cd7e5c0
commit
6dce1cbffd
|
@ -39,15 +39,17 @@ public class ByteBufferAccumulator implements AutoCloseable
|
||||||
{
|
{
|
||||||
private final List<ByteBuffer> _buffers = new ArrayList<>();
|
private final List<ByteBuffer> _buffers = new ArrayList<>();
|
||||||
private final ByteBufferPool _bufferPool;
|
private final ByteBufferPool _bufferPool;
|
||||||
|
private final boolean _direct;
|
||||||
|
|
||||||
public ByteBufferAccumulator()
|
public ByteBufferAccumulator()
|
||||||
{
|
{
|
||||||
this(null);
|
this(null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBufferAccumulator(ByteBufferPool bufferPool)
|
public ByteBufferAccumulator(ByteBufferPool bufferPool, boolean direct)
|
||||||
{
|
{
|
||||||
_bufferPool = (bufferPool == null) ? new NullByteBufferPool() : bufferPool;
|
_bufferPool = (bufferPool == null) ? new NullByteBufferPool() : bufferPool;
|
||||||
|
_direct = direct;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,7 +131,7 @@ public class ByteBufferAccumulator implements AutoCloseable
|
||||||
}
|
}
|
||||||
|
|
||||||
int length = getLength();
|
int length = getLength();
|
||||||
combinedBuffer = _bufferPool.acquire(length, false);
|
combinedBuffer = _bufferPool.acquire(length, _direct);
|
||||||
BufferUtil.clearToFill(combinedBuffer);
|
BufferUtil.clearToFill(combinedBuffer);
|
||||||
for (ByteBuffer buffer : _buffers)
|
for (ByteBuffer buffer : _buffers)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,12 +36,12 @@ public class ByteBufferOutputStream2 extends OutputStream
|
||||||
|
|
||||||
public ByteBufferOutputStream2()
|
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()
|
public ByteBufferPool getByteBufferPool()
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class ByteBufferAccumulatorTest
|
||||||
public void before()
|
public void before()
|
||||||
{
|
{
|
||||||
byteBufferPool = new CountingBufferPool();
|
byteBufferPool = new CountingBufferPool();
|
||||||
accumulator = new ByteBufferAccumulator(byteBufferPool);
|
accumulator = new ByteBufferAccumulator(byteBufferPool, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ByteAccumulator implements AutoCloseable
|
||||||
public ByteAccumulator(int maxOverallBufferSize, ByteBufferPool byteBufferPool)
|
public ByteAccumulator(int maxOverallBufferSize, ByteBufferPool byteBufferPool)
|
||||||
{
|
{
|
||||||
this.maxSize = maxOverallBufferSize;
|
this.maxSize = maxOverallBufferSize;
|
||||||
this.accumulator = new ByteBufferAccumulator(byteBufferPool);
|
this.accumulator = new ByteBufferAccumulator(byteBufferPool, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLength()
|
public int getLength()
|
||||||
|
|
|
@ -492,7 +492,7 @@ public abstract class CompressExtension extends AbstractExtension
|
||||||
if (!deflater.needsInput() || supplyInput(deflater, data))
|
if (!deflater.needsInput() || supplyInput(deflater, data))
|
||||||
{
|
{
|
||||||
ByteBufferPool bufferPool = getBufferPool();
|
ByteBufferPool bufferPool = getBufferPool();
|
||||||
try (ByteBufferAccumulator accumulator = new ByteBufferAccumulator(bufferPool))
|
try (ByteBufferAccumulator accumulator = new ByteBufferAccumulator(bufferPool, false))
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue