Package org.apache.http.nio.util
Class ExpandableBuffer
java.lang.Object
org.apache.http.nio.util.ExpandableBuffer
- All Implemented Interfaces:
BufferInfo
,BufferInfo
- Direct Known Subclasses:
SessionInputBufferImpl
,SessionOutputBufferImpl
,SharedInputBuffer
,SharedOutputBuffer
,SimpleInputBuffer
,SimpleOutputBuffer
A buffer that expand its capacity on demand using
ByteBufferAllocator
interface. Internally, this class is backed by an instance of
ByteBuffer
.
This class is not thread safe.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBufferAllocator
protected ByteBuffer
static final int
private int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionExpandableBuffer
(int bufferSize, ByteBufferAllocator allocator) Allocates buffer of the given size using the given allocator. -
Method Summary
Modifier and TypeMethodDescriptionint
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:boolean
hasData()
Determines if the buffer contains data.int
length()
Returns the length of this buffer.protected void
Sets input mode.protected void
Sets output mode.toString()
-
Field Details
-
INPUT_MODE
public static final int INPUT_MODE- See Also:
-
OUTPUT_MODE
public static final int OUTPUT_MODE- See Also:
-
allocator
-
mode
private int mode -
buffer
-
-
Constructor Details
-
ExpandableBuffer
Allocates buffer of the given size using the given allocator.- Parameters:
bufferSize
- the buffer size.allocator
- allocator to be used to allocateByteBuffer
s.
-
-
Method Details
-
getMode
protected int getMode()Returns the current mode:INPUT_MODE
: the buffer is in the input mode.OUTPUT_MODE
: the buffer is in the output mode.- Returns:
- current input/output mode.
-
setOutputMode
protected void setOutputMode()Sets output mode. The buffer can now be read from. -
setInputMode
protected void setInputMode()Sets input mode. The buffer can now be written into. -
expandCapacity
private void expandCapacity(int capacity) -
expand
Expands buffer's capacity.- Throws:
BufferOverflowException
- in case we get over the maximum allowed value
-
ensureCapacity
protected void ensureCapacity(int requiredCapacity) Ensures the buffer can accommodate the required capacity. -
capacity
public int capacity()Returns the total capacity of this buffer.- Specified by:
capacity
in interfaceBufferInfo
- Specified by:
capacity
in interfaceBufferInfo
- Returns:
- total capacity.
-
hasData
public boolean hasData()Determines if the buffer contains data.- Returns:
true
if there is data in the buffer,false
otherwise.
-
length
public int length()Returns the length of this buffer.- Specified by:
length
in interfaceBufferInfo
- Specified by:
length
in interfaceBufferInfo
- Returns:
- buffer length.
-
available
public int available()Returns available capacity of this buffer.- Specified by:
available
in interfaceBufferInfo
- Specified by:
available
in interfaceBufferInfo
- Returns:
- buffer length.
-
clear
protected void clear()Clears buffer. -
toString
-