Class AbstractIoBuffer
- All Implemented Interfaces:
Comparable<IoBuffer>
- Direct Known Subclasses:
CachedBufferAllocator.CachedBuffer, SimpleBufferAllocator.SimpleBuffer
IoBuffer. This implementation assumes that
IoBuffer.buf() always returns a correct NIO ByteBuffer
instance. Most implementations could extend this class and implement their
own buffer management mechanism.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanA flag set to true if the buffer can extend automaticallyprivate booleanA flag set to true if the buffer can shrink automaticallyprivate static final longA mask for a byteprivate final booleanTells if a buffer has been created from an existing bufferprivate static final longA mask for an intprivate intWe don't have any access to Buffer.markValue(), so we need to track it down, which will cause small extra overhead.private intThe minimum number of bytes the IoBuffer can holdprivate booleanTells if a buffer can be expandedprivate static final longA mask for a short -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractIoBuffer(AbstractIoBuffer parent) Creates a new derived buffer.protectedAbstractIoBuffer(IoBufferAllocator allocator, int initialCapacity) Creates a new parent buffer. -
Method Summary
Modifier and TypeMethodDescriptionfinal CharBufferfinal DoubleBufferfinal FloatBufferfinal IntBufferfinal LongBufferfinal IoBufferprotected abstract IoBufferImplement this method to return the unexpandable read only version of this buffer.final ShortBufferprivate IoBufferautoExpand(int expectedRemaining) private IoBufferautoExpand(int pos, int expectedRemaining) protected abstract voidbuf(ByteBuffer newBuf) Sets the underlying NIO buffer instance.final intcapacity()final IoBuffercapacity(int newCapacity) Increases the capacity of this buffer.private static voidcheckFieldSize(int fieldSize) final IoBufferclear()final IoBuffercompact()intfinal IoBufferprotected abstract IoBufferImplement this method to return the unexpandable duplicate of this buffer.private StringenumConversionErrorMessage(Enum<?> e, String type) booleanfinal IoBufferexpand(int expectedRemaining) Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemainingroom from the current position.private IoBufferexpand(int expectedRemaining, boolean autoExpand) final IoBufferexpand(int pos, int expectedRemaining) Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemainingroom from the specifiedposition.private IoBufferexpand(int pos, int expectedRemaining, boolean autoExpand) fill(byte value, int size) Fills this buffer with the specified value.fill(int size) Fills this buffer withNUL (0x00).fillAndReset(byte value, int size) Fills this buffer with the specified value.fillAndReset(int size) Fills this buffer withNUL (0x00).final IoBufferflip()final byteget()get(byte[] dst) final IoBufferget(byte[] dst, int offset, int length) final byteget(int index) final chargetChar()final chargetChar(int index) final doublefinal doublegetDouble(int index) <E extends Enum<E>>
EReads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EReads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EgetEnumInt(int index, Class<E> enumClass) Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EgetEnumInt(Class<E> enumClass) Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.getEnumSet(int index, Class<E> enumClass) Reads a byte sized bit vector and converts it to anEnumSet.getEnumSet(Class<E> enumClass) Reads a byte sized bit vector and converts it to anEnumSet.getEnumSetInt(int index, Class<E> enumClass) Reads an int sized bit vector and converts it to anEnumSet.getEnumSetInt(Class<E> enumClass) Reads an int sized bit vector and converts it to anEnumSet.getEnumSetLong(int index, Class<E> enumClass) Reads a long sized bit vector and converts it to anEnumSet.getEnumSetLong(Class<E> enumClass) Reads a long sized bit vector and converts it to anEnumSet.getEnumSetShort(int index, Class<E> enumClass) Reads a short sized bit vector and converts it to anEnumSet.getEnumSetShort(Class<E> enumClass) Reads a short sized bit vector and converts it to anEnumSet.<E extends Enum<E>>
EgetEnumShort(int index, Class<E> enumClass) Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EgetEnumShort(Class<E> enumClass) Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.final floatgetFloat()final floatgetFloat(int index) final intgetInt()final intgetInt(int index) final longgetLong()final longgetLong(int index) intRelative get method for reading a medium int value.private intgetMediumInt(byte b1, byte b2, byte b3) intgetMediumInt(int index) Absolute get method for reading a medium int value.Reads a Java object from the buffer using the contextClassLoaderof the current thread.getObject(ClassLoader classLoader) Reads a Java object from the buffer using the specifiedclassLoader.getPrefixedString(int prefixLength, CharsetDecoder decoder) Reads a string which has a length field before the actual encoded string, using the specifieddecoderand returns it.getPrefixedString(CharsetDecoder decoder) Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoderand returns it.final shortgetShort()final shortgetShort(int index) final IoBuffergetSlice(int length) Get a new IoBuffer containing a slice of the current bufferfinal IoBuffergetSlice(int index, int length) Get a new IoBuffer containing a slice of the current buffergetString(int fieldSize, CharsetDecoder decoder) Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.getString(CharsetDecoder decoder) Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.final shortReads one unsigned byte as a short integer.final shortgetUnsigned(int index) Reads one byte as an unsigned short integer.longReads four bytes unsigned integer.longgetUnsignedInt(int index) Reads four bytes unsigned integer.intRelative get method for reading an unsigned medium int value.intgetUnsignedMediumInt(int index) Absolute get method for reading an unsigned medium int value.intReads two bytes unsigned integer.intgetUnsignedShort(int index) Reads two bytes unsigned integer.inthashCode()final booleanintindexOf(byte b) Returns the first occurrence position of the specified byte from the current position to the current limit.final booleanfinal booleanfinal booleanfinal booleanisDirect()final booleanfinal intlimit()final IoBufferlimit(int newLimit) final IoBuffermark()final intfinal intfinal IoBufferminimumCapacity(int minimumCapacity) Sets the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk byIoBuffer.compact()andIoBuffer.shrink()operation.final ByteOrderorder()final IoBufferfinal intposition()final IoBufferposition(int newPosition) booleanprefixedDataAvailable(int prefixLength) booleanprefixedDataAvailable(int prefixLength, int maxDataLength) final IoBufferput(byte b) put(byte[] src) final IoBufferput(byte[] src, int offset, int length) final IoBufferput(int index, byte b) final IoBufferput(ByteBuffer src) Writes the content of the specifiedsrcinto this buffer.Writes the content of the specifiedsrcinto this buffer.final IoBufferputChar(char value) final IoBufferputChar(int index, char value) final IoBufferputDouble(double value) final IoBufferputDouble(int index, double value) Writes an enum's ordinal value to the buffer as a byte.Writes an enum's ordinal value to the buffer as a byte.putEnumInt(int index, Enum<?> e) Writes an enum's ordinal value to the buffer as an integer.putEnumInt(Enum<?> e) Writes an enum's ordinal value to the buffer as an integer.putEnumSet(int index, Set<E> set) Writes the specifiedSetto the buffer as a byte sized bit vector.putEnumSet(Set<E> set) Writes the specifiedSetto the buffer as a byte sized bit vector.putEnumSetInt(int index, Set<E> set) Writes the specifiedSetto the buffer as an int sized bit vector.putEnumSetInt(Set<E> set) Writes the specifiedSetto the buffer as an int sized bit vector.putEnumSetLong(int index, Set<E> set) Writes the specifiedSetto the buffer as a long sized bit vector.putEnumSetLong(Set<E> set) Writes the specifiedSetto the buffer as a long sized bit vector.putEnumSetShort(int index, Set<E> set) Writes the specifiedSetto the buffer as a short sized bit vector.putEnumSetShort(Set<E> set) Writes the specifiedSetto the buffer as a short sized bit vector.putEnumShort(int index, Enum<?> e) Writes an enum's ordinal value to the buffer as a short.putEnumShort(Enum<?> e) Writes an enum's ordinal value to the buffer as a short.final IoBufferputFloat(float value) final IoBufferputFloat(int index, float value) final IoBufferputInt(int value) final IoBufferputInt(int index, int value) final IoBufferputLong(int index, long value) final IoBufferputLong(long value) putMediumInt(int value) Relative put method for writing a medium int value.putMediumInt(int index, int value) Absolute put method for writing a medium int value.Writes the specified Java object to the buffer.putPrefixedString(CharSequence val, int prefixLength, int padding, byte padValue, CharsetEncoder encoder) Writes the content ofvalinto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.putPrefixedString(CharSequence in, int prefixLength, int padding, CharsetEncoder encoder) Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.putPrefixedString(CharSequence in, int prefixLength, CharsetEncoder encoder) Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.putPrefixedString(CharSequence in, CharsetEncoder encoder) Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.final IoBufferputShort(int index, short value) final IoBufferputShort(short value) putString(CharSequence val, int fieldSize, CharsetEncoder encoder) Writes the content ofininto this buffer as aNUL-terminated string using the specifiedencoder.putString(CharSequence val, CharsetEncoder encoder) Writes the content ofininto this buffer using the specifiedencoder.putUnsigned(byte value) Writes an unsigned byte into the ByteBufferputUnsigned(int value) Writes an unsigned byte into the ByteBufferputUnsigned(int index, byte value) Writes an unsigned byte into the ByteBuffer at a specified positionputUnsigned(int index, int value) Writes an unsigned byte into the ByteBuffer at a specified positionputUnsigned(int index, long value) Writes an unsigned byte into the ByteBuffer at a specified positionputUnsigned(int index, short value) Writes an unsigned byte into the ByteBuffer at a specified positionputUnsigned(long value) Writes an unsigned byte into the ByteBufferputUnsigned(short value) Writes an unsigned byte into the ByteBufferfinal IoBufferputUnsignedInt(byte value) Writes an unsigned int into the ByteBufferfinal IoBufferputUnsignedInt(int value) Writes an unsigned int into the ByteBufferfinal IoBufferputUnsignedInt(int index, byte value) Writes an unsigned int into the ByteBuffer at a specified positionfinal IoBufferputUnsignedInt(int index, int value) Writes an unsigned int into the ByteBuffer at a specified positionfinal IoBufferputUnsignedInt(int index, long value) Writes an unsigned int into the ByteBuffer at a specified positionfinal IoBufferputUnsignedInt(int index, short value) Writes an unsigned int into the ByteBuffer at a specified positionfinal IoBufferputUnsignedInt(long value) Writes an unsigned int into the ByteBufferfinal IoBufferputUnsignedInt(short value) Writes an unsigned int into the ByteBufferfinal IoBufferputUnsignedShort(byte value) Writes an unsigned short into the ByteBufferfinal IoBufferputUnsignedShort(int value) Writes an unsigned Short into the ByteBufferfinal IoBufferputUnsignedShort(int index, byte value) Writes an unsigned Short into the ByteBuffer at a specified positionfinal IoBufferputUnsignedShort(int index, int value) Writes an unsigned Short into the ByteBuffer at a specified positionfinal IoBufferputUnsignedShort(int index, long value) Writes an unsigned Short into the ByteBuffer at a specified positionfinal IoBufferputUnsignedShort(int index, short value) Writes an unsigned Short into the ByteBuffer at a specified positionfinal IoBufferputUnsignedShort(long value) Writes an unsigned Short into the ByteBufferfinal IoBufferputUnsignedShort(short value) Writes an unsigned Short into the ByteBufferfinal intfinal IoBufferreset()final IoBufferrewind()final IoBuffersetAutoExpand(boolean autoExpand) Turns on or offautoExpand.final IoBuffersetAutoShrink(boolean autoShrink) Turns on or offautoShrink.final IoBuffershrink()Changes the capacity of this buffer so this buffer occupies as less memory as possible while retaining the position, limit and the buffer content between the position and limit.skip(int size) Forwards the position of this buffer as the specifiedsizebytes.final IoBufferslice()protected abstract IoBufferslice0()Implement this method to return the unexpandable slice of this buffer.final IoBuffersweep()Clears this buffer and fills its content withNUL.final IoBuffersweep(byte value) double Clears this buffer and fills its content withvalue.private <E> Eprivate <E extends Enum<E>>
longtoString()Methods inherited from class IoBuffer
allocate, allocate, array, arrayOffset, buf, free, getAllocator, getHexDump, getHexDump, getHexDump, getHexDump, hasArray, isUseDirectBuffer, normalizeCapacity, setAllocator, setUseDirectBuffer, wrap, wrap, wrap
-
Field Details
-
derived
private final boolean derivedTells if a buffer has been created from an existing buffer -
autoExpand
private boolean autoExpandA flag set to true if the buffer can extend automatically -
autoShrink
private boolean autoShrinkA flag set to true if the buffer can shrink automatically -
recapacityAllowed
private boolean recapacityAllowedTells if a buffer can be expanded -
minimumCapacity
private int minimumCapacityThe minimum number of bytes the IoBuffer can hold -
BYTE_MASK
private static final long BYTE_MASKA mask for a byte- See Also:
-
SHORT_MASK
private static final long SHORT_MASKA mask for a short- See Also:
-
INT_MASK
private static final long INT_MASKA mask for an int- See Also:
-
mark
private int markWe don't have any access to Buffer.markValue(), so we need to track it down, which will cause small extra overhead.
-
-
Constructor Details
-
AbstractIoBuffer
Creates a new parent buffer.- Parameters:
allocator- The allocator to use to create new buffersinitialCapacity- The initial buffer capacity when created
-
AbstractIoBuffer
Creates a new derived buffer. A derived buffer uses an existing buffer properties - the allocator and capacity -.- Parameters:
parent- The buffer we get the properties from
-
-
Method Details
-
isDirect
-
isReadOnly
public final boolean isReadOnly()- Specified by:
isReadOnlyin classIoBuffer- Returns:
trueif the buffer is readOnly- See Also:
-
buf
Sets the underlying NIO buffer instance.- Parameters:
newBuf- The buffer to store within this IoBuffer
-
minimumCapacity
public final int minimumCapacity()- Specified by:
minimumCapacityin classIoBuffer- Returns:
- the minimum capacity of this buffer which is used to determine the
new capacity of the buffer shrunk by the
IoBuffer.compact()andIoBuffer.shrink()operation. The default value is the initial capacity of the buffer.
-
minimumCapacity
Sets the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk byIoBuffer.compact()andIoBuffer.shrink()operation. The default value is the initial capacity of the buffer.- Specified by:
minimumCapacityin classIoBuffer- Parameters:
minimumCapacity- the wanted minimum capacity- Returns:
- the underlying NIO
ByteBufferinstance.
-
capacity
-
capacity
Increases the capacity of this buffer. If the new capacity is less than or equal to the current capacity, this method returns the original buffer. If the new capacity is greater than the current capacity, the buffer is reallocated while retaining the position, limit, mark and the content of the buffer.
Note that the IoBuffer is replaced, it's not copied.
Assuming a buffer contains N bytes, its position is 0 and its current capacity is C, here are the resulting buffer if we set the new capacity to a value V < C and V > C :Initial buffer : 0 L C +--------+----------+ |XXXXXXXX| | +--------+----------+ ^ ^ ^ | | | pos limit capacity V <= C : 0 L C +--------+----------+ |XXXXXXXX| | +--------+----------+ ^ ^ ^ | | | pos limit newCapacity V > C : 0 L C V +--------+-----------------------+ |XXXXXXXX| : | +--------+-----------------------+ ^ ^ ^ ^ | | | | pos limit oldCapacity newCapacity The buffer has been increased.
- Specified by:
capacityin classIoBuffer- Parameters:
newCapacity- the wanted capacity- Returns:
- the underlying NIO
ByteBufferinstance.
-
isAutoExpand
public final boolean isAutoExpand()- Specified by:
isAutoExpandin classIoBuffer- Returns:
trueif and only ifautoExpandis turned on.
-
isAutoShrink
public final boolean isAutoShrink()- Specified by:
isAutoShrinkin classIoBuffer- Returns:
trueif and only ifautoShrinkis turned on.
-
isDerived
public final boolean isDerived()- Specified by:
isDerivedin classIoBuffer- Returns:
trueif and only if this buffer is derived from another buffer via one of theIoBuffer.duplicate(),IoBuffer.slice()orIoBuffer.asReadOnlyBuffer()methods.
-
setAutoExpand
Turns on or offautoExpand.- Specified by:
setAutoExpandin classIoBuffer- Parameters:
autoExpand- The flag value to set- Returns:
- The modified IoBuffer instance
-
setAutoShrink
Turns on or offautoShrink.- Specified by:
setAutoShrinkin classIoBuffer- Parameters:
autoShrink- The flag value to set- Returns:
- The modified IoBuffer instance
-
expand
Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemainingroom from the current position. This method works even if you didn't setautoExpandtotrue.
Assuming a buffer contains N bytes, its position is P and its current capacity is C, here are the resulting buffer if we call the expand method with a expectedRemaining value V :Initial buffer : 0 L C +--------+----------+ |XXXXXXXX| | +--------+----------+ ^ ^ ^ | | | pos limit capacity ( pos + V ) <= L, no change : 0 L C +--------+----------+ |XXXXXXXX| | +--------+----------+ ^ ^ ^ | | | pos limit newCapacity You can still put ( L - pos ) bytes in the buffer ( pos + V ) > L & ( pos + V ) <= C : 0 L C +------------+------+ |XXXXXXXX:...| | +------------+------+ ^ ^ ^ | | | pos newlimit newCapacity You can now put ( L - pos + V ) bytes in the buffer. ( pos + V ) > C 0 L C +-------------------+----+ |XXXXXXXX:..........:....| +------------------------+ ^ ^ | | pos +-- newlimit | +-- newCapacity You can now put ( L - pos + V ) bytes in the buffer, which limit is now equals to the capacity.Note that the expecting remaining bytes starts at the current position. In all those examples, the position is 0. -
expand
-
expand
Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemainingroom from the specifiedposition. This method works even if you didn't setautoExpandtotrue. Assuming a buffer contains N bytes, its position is P and its current capacity is C, here are the resulting buffer if we call the expand method with a expectedRemaining value V :Initial buffer : P L C +--------+----------+ |XXXXXXXX| | +--------+----------+ ^ ^ ^ | | | pos limit capacity ( pos + V ) <= L, no change : P L C +--------+----------+ |XXXXXXXX| | +--------+----------+ ^ ^ ^ | | | pos limit newCapacity You can still put ( L - pos ) bytes in the buffer ( pos + V ) > L & ( pos + V ) <= C : P L C +------------+------+ |XXXXXXXX:...| | +------------+------+ ^ ^ ^ | | | pos newlimit newCapacity You can now put ( L - pos + V) bytes in the buffer. ( pos + V ) > C P L C +-------------------+----+ |XXXXXXXX:..........:....| +------------------------+ ^ ^ | | pos +-- newlimit | +-- newCapacity You can now put ( L - pos + V ) bytes in the buffer, which limit is now equals to the capacity.Note that the expecting remaining bytes starts at the current position. In all those examples, the position is P. -
expand
-
shrink
Changes the capacity of this buffer so this buffer occupies as less memory as possible while retaining the position, limit and the buffer content between the position and limit.
The capacity of the buffer never becomes less thanIoBuffer.minimumCapacity()
. The mark is discarded once the capacity changes.
Typically, a call to this method tries to remove as much unused bytes as possible, dividing by two the initial capacity until it can't without obtaining a new capacity lower than theIoBuffer.minimumCapacity(). For instance, if the limit is 7 and the capacity is 36, with a minimum capacity of 8, shrinking the buffer will left a capacity of 9 (we go down from 36 to 18, then from 18 to 9).Initial buffer : +--------+----------+ |XXXXXXXX| | +--------+----------+ ^ ^ ^ ^ | | | | pos | | capacity | | | +-- minimumCapacity | +-- limit Resulting buffer : +--------+--+-+ |XXXXXXXX| | | +--------+--+-+ ^ ^ ^ ^ | | | | | | | +-- new capacity | | | pos | +-- minimum capacity | +-- limit -
position
-
position
-
limit
-
limit
-
mark
-
markValue
-
reset
-
clear
-
sweep
-
sweep
double Clears this buffer and fills its content withvalue. The position is set to zero, the limit is set to the capacity, and the mark is discarded. -
flip
-
rewind
-
remaining
-
hasRemaining
public final boolean hasRemaining()- Specified by:
hasRemainingin classIoBuffer- Returns:
trueif there are some remaining bytes in the buffer- See Also:
-
get
-
getUnsigned
public final short getUnsigned()Reads one unsigned byte as a short integer.- Specified by:
getUnsignedin classIoBuffer- Returns:
- the unsigned short at the current position
-
put
-
putUnsigned
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsignedin classIoBuffer- Parameters:
value- the byte to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsignedin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the byte to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsignedin classIoBuffer- Parameters:
value- the short to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsignedin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the short to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsignedin classIoBuffer- Parameters:
value- the int to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsignedin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the int to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsignedin classIoBuffer- Parameters:
value- the long to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsignedin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the long to write- Returns:
- the modified IoBuffer
-
get
-
getUnsigned
public final short getUnsigned(int index) Reads one byte as an unsigned short integer.- Specified by:
getUnsignedin classIoBuffer- Parameters:
index- The position for which we want to read an unsigned byte- Returns:
- the unsigned byte at the given position
-
put
-
get
-
put
Writes the content of the specifiedsrcinto this buffer. -
put
-
compact
-
order
-
order
-
getChar
-
putChar
-
getChar
-
putChar
-
asCharBuffer
- Specified by:
asCharBufferin classIoBuffer- Returns:
- a new CharBuffer
- See Also:
-
getShort
-
putShort
-
getShort
-
putShort
-
asShortBuffer
- Specified by:
asShortBufferin classIoBuffer- Returns:
- A ShortBuffer from this IoBuffer
- See Also:
-
getInt
-
putInt
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
value- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
value- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
value- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
value- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedIntin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned short into the ByteBuffer- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
value- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
value- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
index- the position in the buffer to write the unsigned shortvalue- the unsigned short to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
value- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
index- the position in the buffer to write the valuevalue- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
value- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShortin classIoBuffer- Parameters:
index- the position in the buffer to write the shortvalue- the long to write- Returns:
- the modified IoBuffer
-
getInt
-
putInt
-
asIntBuffer
- Specified by:
asIntBufferin classIoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
getLong
-
putLong
-
getLong
-
putLong
-
asLongBuffer
- Specified by:
asLongBufferin classIoBuffer- Returns:
- a LongBuffer from this IoBffer
- See Also:
-
getFloat
-
putFloat
-
getFloat
-
putFloat
-
asFloatBuffer
- Specified by:
asFloatBufferin classIoBuffer- Returns:
- A FloatBuffer from this IoBuffer
- See Also:
-
getDouble
-
putDouble
-
getDouble
-
putDouble
-
asDoubleBuffer
- Specified by:
asDoubleBufferin classIoBuffer- Returns:
- A buffer containing Double
- See Also:
-
asReadOnlyBuffer
- Specified by:
asReadOnlyBufferin classIoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
asReadOnlyBuffer0
Implement this method to return the unexpandable read only version of this buffer.- Returns:
- the IoBoffer instance
-
duplicate
-
duplicate0
Implement this method to return the unexpandable duplicate of this buffer.- Returns:
- the IoBoffer instance
-
slice
-
getSlice
-
getSlice
-
slice0
Implement this method to return the unexpandable slice of this buffer.- Returns:
- the IoBoffer instance
-
hashCode
-
equals
-
compareTo
-
toString
-
get
-
put
-
put
-
getUnsignedShort
public int getUnsignedShort()Reads two bytes unsigned integer.- Specified by:
getUnsignedShortin classIoBuffer- Returns:
- The read unsigned short
-
getUnsignedShort
public int getUnsignedShort(int index) Reads two bytes unsigned integer.- Specified by:
getUnsignedShortin classIoBuffer- Parameters:
index- The index in the IoBuffer where we will read an unsigned short from- Returns:
- the unsigned short at the given position
-
getUnsignedInt
public long getUnsignedInt()Reads four bytes unsigned integer.- Specified by:
getUnsignedIntin classIoBuffer- Returns:
- The unsigned int read
-
getMediumInt
public int getMediumInt()Relative get method for reading a medium int value.Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order, and then increments the position by three.
- Specified by:
getMediumIntin classIoBuffer- Returns:
- The medium int value at the buffer's current position
-
getUnsignedMediumInt
public int getUnsignedMediumInt()Relative get method for reading an unsigned medium int value.Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order, and then increments the position by three.
- Specified by:
getUnsignedMediumIntin classIoBuffer- Returns:
- The unsigned medium int value at the buffer's current position
-
getMediumInt
public int getMediumInt(int index) Absolute get method for reading a medium int value.Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order.
- Specified by:
getMediumIntin classIoBuffer- Parameters:
index- The index from which the medium int will be read- Returns:
- The medium int value at the given index
-
getUnsignedMediumInt
public int getUnsignedMediumInt(int index) Absolute get method for reading an unsigned medium int value.Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order.
- Specified by:
getUnsignedMediumIntin classIoBuffer- Parameters:
index- The index from which the unsigned medium int will be read- Returns:
- The unsigned medium int value at the given index
-
getMediumInt
private int getMediumInt(byte b1, byte b2, byte b3) -
putMediumInt
Relative put method for writing a medium int value.Writes three bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by three.
- Specified by:
putMediumIntin classIoBuffer- Parameters:
value- The medium int value to be written- Returns:
- the modified IoBuffer
-
putMediumInt
Absolute put method for writing a medium int value.Writes three bytes containing the given int value, in the current byte order, into this buffer at the given index.
- Specified by:
putMediumIntin classIoBuffer- Parameters:
index- The index at which the bytes will be writtenvalue- The medium int value to be written- Returns:
- the modified IoBuffer
-
getUnsignedInt
public long getUnsignedInt(int index) Reads four bytes unsigned integer.- Specified by:
getUnsignedIntin classIoBuffer- Parameters:
index- The index in the IoBuffer where we will read an unsigned int from- Returns:
- The long at the given position
-
asInputStream
- Specified by:
asInputStreamin classIoBuffer- Returns:
- an
InputStreamthat reads the data from this buffer.InputStream.read()returns-1if the buffer position reaches to the limit.
-
asOutputStream
- Specified by:
asOutputStreamin classIoBuffer- Returns:
- an
OutputStreamthat appends the data into this buffer. Please note that theOutputStream.write(int)will throw aBufferOverflowExceptioninstead of anIOExceptionin case of buffer overflow. Please setautoExpandproperty by callingIoBuffer.setAutoExpand(boolean)to prevent the unexpected runtime exception.
-
getString
Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it. This method reads until the limit of this buffer if noNULis found.- Specified by:
getStringin classIoBuffer- Parameters:
decoder- TheCharsetDecoderto use- Returns:
- the read String
- Throws:
CharacterCodingException- Thrown when an error occurred while decoding the buffer
-
getString
Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.- Specified by:
getStringin classIoBuffer- Parameters:
fieldSize- the maximum number of bytes to readdecoder- TheCharsetDecoderto use- Returns:
- the read String
- Throws:
CharacterCodingException- Thrown when an error occurred while decoding the buffer
-
putString
Writes the content ofininto this buffer using the specifiedencoder. This method doesn't terminate string withNUL. You have to do it by yourself.- Specified by:
putStringin classIoBuffer- Parameters:
val- The CharSequence to put in the IoBufferencoder- The CharsetEncoder to use- Returns:
- The modified IoBuffer
- Throws:
CharacterCodingException- When we have an error while decoding the String
-
putString
public IoBuffer putString(CharSequence val, int fieldSize, CharsetEncoder encoder) throws CharacterCodingException Writes the content ofininto this buffer as aNUL-terminated string using the specifiedencoder.If the charset name of the encoder is UTF-16, you cannot specify odd
fieldSize, and this method will append twoNULs as a terminator.Please note that this method doesn't terminate with
NULif the input string is longer thanfieldSize.- Specified by:
putStringin classIoBuffer- Parameters:
val- The CharSequence to put in the IoBufferfieldSize- the maximum number of bytes to writeencoder- The CharsetEncoder to use- Returns:
- The modified IoBuffer
- Throws:
CharacterCodingException- When we have an error while decoding the String
-
getPrefixedString
Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoderand returns it. This method is a shortcut forgetPrefixedString(2, decoder).- Specified by:
getPrefixedStringin classIoBuffer- Parameters:
decoder- The CharsetDecoder to use- Returns:
- The read String
- Throws:
CharacterCodingException- When we have an error while decoding the String
-
getPrefixedString
public String getPrefixedString(int prefixLength, CharsetDecoder decoder) throws CharacterCodingException Reads a string which has a length field before the actual encoded string, using the specifieddecoderand returns it.- Specified by:
getPrefixedStringin classIoBuffer- Parameters:
prefixLength- the length of the length field (1, 2, or 4)decoder- the decoder to use for decoding the string- Returns:
- the prefixed string
- Throws:
CharacterCodingException- when decoding failsBufferUnderflowException- when there is not enough data available
-
putPrefixedString
public IoBuffer putPrefixedString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder. This method is a shortcut forputPrefixedString(in, 2, 0, encoder).- Specified by:
putPrefixedStringin classIoBuffer- Parameters:
in- The CharSequence to put in the IoBufferencoder- The CharsetEncoder to use- Returns:
- The modified IoBuffer
- Throws:
CharacterCodingException- When we have an error while decoding the CharSequence
-
putPrefixedString
public IoBuffer putPrefixedString(CharSequence in, int prefixLength, CharsetEncoder encoder) throws CharacterCodingException Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder. This method is a shortcut forputPrefixedString(in, prefixLength, 0, encoder).- Specified by:
putPrefixedStringin classIoBuffer- Parameters:
in- The CharSequence to put in the IoBufferprefixLength- the length of the length field (1, 2, or 4)encoder- The CharsetEncoder to use- Returns:
- The modified IoBuffer
- Throws:
CharacterCodingException- When we have an error while decoding the CharSequence
-
putPrefixedString
public IoBuffer putPrefixedString(CharSequence in, int prefixLength, int padding, CharsetEncoder encoder) throws CharacterCodingException Writes the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder. This method is a shortcut forputPrefixedString(in, prefixLength, padding, ( byte ) 0, encoder)- Specified by:
putPrefixedStringin classIoBuffer- Parameters:
in- The CharSequence to put in the IoBufferprefixLength- the length of the length field (1, 2, or 4)padding- the number of paddedNULs (1 (or 0), 2, or 4)encoder- The CharsetEncoder to use- Returns:
- The modified IoBuffer
- Throws:
CharacterCodingException- When we have an error while decoding the CharSequence
-
putPrefixedString
public IoBuffer putPrefixedString(CharSequence val, int prefixLength, int padding, byte padValue, CharsetEncoder encoder) throws CharacterCodingException Writes the content ofvalinto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.- Specified by:
putPrefixedStringin classIoBuffer- Parameters:
val- The CharSequence to put in teh IoBufferprefixLength- the length of the length field (1, 2, or 4)padding- the number of padded bytes (1 (or 0), 2, or 4)padValue- the value of padded bytesencoder- The CharsetEncoder to use- Returns:
- The modified IoBuffer
- Throws:
CharacterCodingException- When we have an error while decoding the CharSequence
-
getObject
Reads a Java object from the buffer using the contextClassLoaderof the current thread.- Specified by:
getObjectin classIoBuffer- Returns:
- The read Object
- Throws:
ClassNotFoundException- thrown when we can't find the Class to use
-
getObject
Reads a Java object from the buffer using the specifiedclassLoader.- Specified by:
getObjectin classIoBuffer- Parameters:
classLoader- The classLoader to use to read an Object from the IoBuffer- Returns:
- The read Object
- Throws:
ClassNotFoundException- thrown when we can't find the Class to use
-
putObject
-
prefixedDataAvailable
public boolean prefixedDataAvailable(int prefixLength) - Specified by:
prefixedDataAvailablein classIoBuffer- Parameters:
prefixLength- the length of the prefix field (1, 2, or 4)- Returns:
trueif this buffer contains a data which has a data length as a prefix and the buffer has remaining data as enough as specified in the data length field. This method is identical withprefixedDataAvailable( prefixLength, Integer.MAX_VALUE ). Please not that using this method can allow DoS (Denial of Service) attack in case the remote peer sends too big data length value. It is recommended to useIoBuffer.prefixedDataAvailable(int, int)instead.
-
prefixedDataAvailable
public boolean prefixedDataAvailable(int prefixLength, int maxDataLength) - Specified by:
prefixedDataAvailablein classIoBuffer- Parameters:
prefixLength- the length of the prefix field (1, 2, or 4)maxDataLength- the allowed maximum of the read data length- Returns:
trueif this buffer contains a data which has a data length as a prefix and the buffer has remaining data as enough as specified in the data length field.
-
indexOf
-
skip
-
fill
-
fillAndReset
Fills this buffer with the specified value. This method does not change buffer position.- Specified by:
fillAndResetin classIoBuffer- Parameters:
value- The value to fill the IoBuffer withsize- The added size- Returns:
- The modified IoBuffer
-
fill
-
fillAndReset
Fills this buffer withNUL (0x00). This method does not change buffer position.- Specified by:
fillAndResetin classIoBuffer- Parameters:
size- The added size- Returns:
- The modified IoBuffer
-
getEnum
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type. -
getEnum
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type. -
getEnumShort
Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumShortin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
enumClass- The enum's class object- Returns:
- The correlated enum constant
-
getEnumShort
Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumShortin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
index- the index from which the bytes will be readenumClass- The enum's class object- Returns:
- The correlated enum constant
-
getEnumInt
Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumIntin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
enumClass- The enum's class object- Returns:
- The correlated enum constant
-
getEnumInt
Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumIntin classIoBuffer- Type Parameters:
E- The enum type to return- Parameters:
index- the index from which the bytes will be readenumClass- The enum's class object- Returns:
- The correlated enum constant
-
putEnum
-
putEnum
-
putEnumShort
Writes an enum's ordinal value to the buffer as a short.- Specified by:
putEnumShortin classIoBuffer- Parameters:
e- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
putEnumShort
Writes an enum's ordinal value to the buffer as a short.- Specified by:
putEnumShortin classIoBuffer- Parameters:
index- The index at which the bytes will be writtene- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
putEnumInt
Writes an enum's ordinal value to the buffer as an integer.- Specified by:
putEnumIntin classIoBuffer- Parameters:
e- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
putEnumInt
Writes an enum's ordinal value to the buffer as an integer.- Specified by:
putEnumIntin classIoBuffer- Parameters:
index- The index at which the bytes will be writtene- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
toEnum
-
enumConversionErrorMessage
-
getEnumSet
Reads a byte sized bit vector and converts it to anEnumSet.Each bit is mapped to a value in the specified enum. The least significant bit maps to the first entry in the specified enum and each subsequent bit maps to each subsequent bit as mapped to the subsequent enum value.
- Specified by:
getEnumSetin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
-
getEnumSet
Reads a byte sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the byte will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
-
getEnumSetShort
Reads a short sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
-
getEnumSetShort
Reads a short sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the bytes will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
-
getEnumSetInt
Reads an int sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
-
getEnumSetInt
Reads an int sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the bytes will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
-
getEnumSetLong
Reads a long sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
enumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
-
getEnumSetLong
Reads a long sized bit vector and converts it to anEnumSet.- Specified by:
getEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type- Parameters:
index- the index from which the bytes will be readenumClass- the enum class used to create the EnumSet- Returns:
- the EnumSet representation of the bit vector
- See Also:
-
toEnumSet
-
putEnumSet
-
putEnumSet
Writes the specifiedSetto the buffer as a byte sized bit vector.- Specified by:
putEnumSetin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the byte will be writtenset- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
putEnumSetShort
Writes the specifiedSetto the buffer as a short sized bit vector.- Specified by:
putEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
set- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
putEnumSetShort
Writes the specifiedSetto the buffer as a short sized bit vector.- Specified by:
putEnumSetShortin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the bytes will be writtenset- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
putEnumSetInt
Writes the specifiedSetto the buffer as an int sized bit vector.- Specified by:
putEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
set- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
putEnumSetInt
Writes the specifiedSetto the buffer as an int sized bit vector.- Specified by:
putEnumSetIntin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the bytes will be writtenset- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
putEnumSetLong
Writes the specifiedSetto the buffer as a long sized bit vector.- Specified by:
putEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
set- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
putEnumSetLong
Writes the specifiedSetto the buffer as a long sized bit vector.- Specified by:
putEnumSetLongin classIoBuffer- Type Parameters:
E- the enum type of the Set- Parameters:
index- the index at which the bytes will be writtenset- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
toLong
-
autoExpand
-
autoExpand
-
checkFieldSize
private static void checkFieldSize(int fieldSize)
-