public class ExpandableBuffer extends Object implements BufferInfo, BufferInfo
ByteBufferAllocator
interface. Internally, this class is backed by an instance of
ByteBuffer
.
This class is not thread safe.
Modifier and Type | Field and Description |
---|---|
private ByteBufferAllocator |
allocator |
protected ByteBuffer |
buffer |
static int |
INPUT_MODE |
private int |
mode |
static int |
OUTPUT_MODE |
Constructor and Description |
---|
ExpandableBuffer(int buffersize,
ByteBufferAllocator allocator)
Allocates buffer of the given size using the given allocator.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns available capacity of this buffer.
|
int |
capacity()
Returns the total capacity of this buffer.
|
protected void |
clear()
Clears buffer.
|
protected void |
ensureCapacity(int requiredCapacity)
Ensures the buffer can accommodate the required capacity.
|
protected void |
expand()
Expands buffer's capacity.
|
private void |
expandCapacity(int capacity) |
protected int |
getMode()
Returns the current mode:
INPUT_MODE : the buffer is in the input mode. |
boolean |
hasData()
Determines if the buffer contains data.
|
int |
length()
Returns the length of this buffer.
|
protected void |
setInputMode()
Sets input mode.
|
protected void |
setOutputMode()
Sets output mode.
|
String |
toString() |
public static final int INPUT_MODE
public static final int OUTPUT_MODE
private final ByteBufferAllocator allocator
private int mode
protected ByteBuffer buffer
public ExpandableBuffer(int buffersize, ByteBufferAllocator allocator)
buffersize
- the buffer size.allocator
- allocator to be used to allocate ByteBuffer
s.protected int getMode()
INPUT_MODE
: the buffer is in the input mode.
OUTPUT_MODE
: the buffer is in the output mode.
protected void setOutputMode()
protected void setInputMode()
private void expandCapacity(int capacity)
protected void expand()
protected void ensureCapacity(int requiredCapacity)
public int capacity()
capacity
in interface BufferInfo
public boolean hasData()
true
if there is data in the buffer,
false
otherwise.public int length()
length
in interface BufferInfo
public int available()
available
in interface BufferInfo
protected void clear()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses