public class ByteBufferAccumulator
extends java.lang.Object
implements java.lang.AutoCloseable
ByteBufferPool
or freshly allocated if one is not supplied.
The method ensureBuffer(int, int)
is used to write directly to the last buffer stored in the buffer list,
if there is less than a certain amount of space available in that buffer then a new one will be allocated and returned instead.ensureBuffer(int, int)
Constructor and Description |
---|
ByteBufferAccumulator() |
ByteBufferAccumulator(ByteBufferPool bufferPool,
boolean direct) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
copyBuffer(java.nio.ByteBuffer buffer) |
void |
copyBytes(byte[] buf,
int offset,
int length) |
java.nio.ByteBuffer |
ensureBuffer(int minAllocationSize)
Get the last buffer of the accumulator, this can be written to directly to avoid copying into the accumulator.
|
java.nio.ByteBuffer |
ensureBuffer(int minSize,
int minAllocationSize)
Get the last buffer of the accumulator, this can be written to directly to avoid copying into the accumulator.
|
ByteBufferPool |
getByteBufferPool() |
int |
getLength()
Get the amount of bytes which have been accumulated.
|
java.nio.ByteBuffer |
takeByteBuffer()
Take the combined buffer containing all content written to the accumulator.
|
byte[] |
toByteArray() |
java.nio.ByteBuffer |
toByteBuffer()
Take the combined buffer containing all content written to the accumulator.
|
void |
writeTo(java.nio.ByteBuffer buffer) |
void |
writeTo(java.io.OutputStream out) |
public ByteBufferAccumulator()
public ByteBufferAccumulator(ByteBufferPool bufferPool, boolean direct)
public int getLength()
public ByteBufferPool getByteBufferPool()
public java.nio.ByteBuffer ensureBuffer(int minAllocationSize)
minAllocationSize
- new buffers will be allocated to have at least this size.minSize
space to write into.public java.nio.ByteBuffer ensureBuffer(int minSize, int minAllocationSize)
minSize
- the smallest amount of remaining space before a new buffer is allocated.minAllocationSize
- new buffers will be allocated to have at least this size.minSize
space to write into.public void copyBytes(byte[] buf, int offset, int length)
public void copyBuffer(java.nio.ByteBuffer buffer)
public java.nio.ByteBuffer takeByteBuffer()
ByteBuffer
back into the ByteBufferPool
.toByteBuffer()
public java.nio.ByteBuffer toByteBuffer()
ByteBufferPool
when the accumulator is closed.takeByteBuffer()
,
close()
public byte[] toByteArray()
public void writeTo(java.nio.ByteBuffer buffer)
public void writeTo(java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public void close()
close
in interface java.lang.AutoCloseable
Copyright © 1995–2021 Webtide. All rights reserved.