Class ExpandableBuffer
- java.lang.Object
-
- org.apache.hc.core5.http.impl.nio.ExpandableBuffer
-
- Direct Known Subclasses:
AbstractSharedBuffer,BufferedData,SessionInputBufferImpl,SessionOutputBufferImpl
@Internal public class ExpandableBuffer extends java.lang.Object
A buffer that expand its capacity on demand. Internally, this class is backed by an instance ofByteBuffer.This class is not thread safe.
- Since:
- 4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExpandableBuffer.ModeA buffer's mode.
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBufferbufferprivate ExpandableBuffer.Modemode
-
Constructor Summary
Constructors Modifier Constructor Description protectedExpandableBuffer(int bufferSize)Allocates buffer of the given size using the given allocator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.nio.ByteBufferbuffer()protected intcapacity()Returns available capacity of this buffer.protected voidclear()Clears buffer.protected voidensureAdjustedCapacity(int requiredCapacity)Ensures the buffer can accommodate at least the required capacity adjusted to multiples of 1024.protected voidensureCapacity(int requiredCapacity)Ensures the buffer can accommodate the exact required capacity.protected voidexpand()Expands buffer's capacity.private voidexpandCapacity(int capacity)protected booleanhasData()Determines if the buffer contains data.protected intlength()Returns the length of this buffer.protected ExpandableBuffer.Modemode()protected voidsetInputMode()Sets the mode toINPUT.protected voidsetOutputMode()Sets the mode toOUTPUT.java.lang.StringtoString()
-
-
-
Field Detail
-
mode
private ExpandableBuffer.Mode mode
-
buffer
private java.nio.ByteBuffer buffer
-
-
Constructor Detail
-
ExpandableBuffer
protected ExpandableBuffer(int bufferSize)
Allocates buffer of the given size using the given allocator.Sets the mode to
INPUT.- Parameters:
bufferSize- the buffer size.
-
-
Method Detail
-
mode
protected ExpandableBuffer.Mode mode()
Returns the current mode:- Returns:
- current input/output mode, never null.
-
buffer
protected java.nio.ByteBuffer buffer()
-
setOutputMode
protected void setOutputMode()
Sets the mode toOUTPUT. The buffer can now be read from.
-
setInputMode
protected void setInputMode()
Sets the mode toINPUT. The buffer can now be written into.
-
expandCapacity
private void expandCapacity(int capacity)
-
expand
protected void expand() throws java.nio.BufferOverflowExceptionExpands buffer's capacity.- Throws:
java.nio.BufferOverflowException- in case we get over the maximum allowed value
-
ensureCapacity
protected void ensureCapacity(int requiredCapacity)
Ensures the buffer can accommodate the exact required capacity.- Parameters:
requiredCapacity- the required capacity.
-
ensureAdjustedCapacity
protected void ensureAdjustedCapacity(int requiredCapacity)
Ensures the buffer can accommodate at least the required capacity adjusted to multiples of 1024.- Parameters:
requiredCapacity- the required capacity.
-
hasData
protected boolean hasData()
Determines if the buffer contains data.Sets the mode to output.
- Returns:
trueif there is data in the buffer,falseotherwise.
-
length
protected int length()
Returns the length of this buffer.Sets the mode to output.
- Returns:
- buffer length.
-
capacity
protected int capacity()
Returns available capacity of this buffer.- Returns:
- buffer length.
-
clear
protected void clear()
Clears buffer.Sets the mode to
INPUT.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-