Class IoBuffer
- All Implemented Interfaces:
Comparable<IoBuffer>
- Direct Known Subclasses:
AbstractIoBuffer, IoBufferWrapper
This is a replacement for ByteBuffer. Please refer to
ByteBuffer documentation for preliminary usage. MINA does not use NIO
ByteBuffer directly for two reasons:
- It doesn't provide useful getters and putters such as
fill,get/putString, andget/putAsciiInt()enough. - It is difficult to write variable-length data due to its fixed capacity
Allocation
You can allocate a new heap buffer.
IoBuffer buf = IoBuffer.allocate(1024, false);You can also allocate a new direct buffer:
IoBuffer buf = IoBuffer.allocate(1024, true);or you can set the default buffer type.
// Allocate heap buffer by default. IoBuffer.setUseDirectBuffer(false); // A new heap buffer is returned. IoBuffer buf = IoBuffer.allocate(1024);
Wrapping existing NIO buffers and arrays
This class provides a few wrap(...) methods that wraps any NIO
buffers and byte arrays.
AutoExpand
Writing variable-length data using NIO ByteBuffers is not really
easy, and it is because its size is fixed at allocation. IoBuffer
introduces the autoExpand property. If autoExpand property
is set to true, you never get a BufferOverflowException or an
IndexOutOfBoundsException (except when index is negative). It
automatically expands its capacity. For instance:
String greeting = messageBundle.getMessage("hello");
IoBuffer buf = IoBuffer.allocate(16);
// Turn on autoExpand (it is off by default)
buf.setAutoExpand(true);
buf.putString(greeting, utf8encoder);
The underlying ByteBuffer is reallocated by IoBuffer behind
the scene if the encoded data is larger than 16 bytes in the example above.
Its capacity will double, and its limit will increase to the last position
the string is written.
AutoShrink
You might also want to decrease the capacity of the buffer when most of the
allocated memory area is not being used. IoBuffer provides
autoShrink property to take care of this issue. If
autoShrink is turned on, IoBuffer halves the capacity of the
buffer when compact() is invoked and only 1/4 or less of the current
capacity is being used.
You can also call the shrink() method manually to shrink the
capacity of the buffer.
The underlying ByteBuffer is reallocated by the IoBuffer
behind the scene, and therefore buf() will return a different
ByteBuffer instance once capacity changes. Please also note that the
compact() method or the shrink() method will not decrease
the capacity if the new capacity is less than the minimumCapacity()
of the buffer.
Derived Buffers
Derived buffers are the buffers which were created by the
duplicate(), slice(), or asReadOnlyBuffer()
methods. They are useful especially when you broadcast the same messages to
multiple IoSessions. Please note that the buffer derived from and its
derived buffers are not auto-expandable nor auto-shrinkable. Trying to call
setAutoExpand(boolean) or setAutoShrink(boolean) with
true parameter will raise an IllegalStateException.
Changing Buffer Allocation Policy
The IoBufferAllocator interface lets you override the default buffer
management behavior. There are two allocators provided out-of-the-box:
SimpleBufferAllocator(default)CachedBufferAllocator
setAllocator(IoBufferAllocator).-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static IoBufferAllocatorThe allocator used to create new buffersprivate static booleanA flag indicating which type of buffer we are using : heap or direct -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic IoBufferallocate(int capacity) Returns the direct or heap buffer which is capable to store the specified amount of bytes.static IoBufferallocate(int capacity, boolean useDirectBuffer) Returns a direct or heap IoBuffer which can contain the specified number of bytes.abstract byte[]array()abstract intabstract CharBufferabstract DoubleBufferabstract FloatBufferabstract InputStreamabstract IntBufferabstract LongBufferabstract OutputStreamabstract IoBufferabstract ShortBufferabstract ByteBufferbuf()abstract intcapacity()abstract IoBuffercapacity(int newCapacity) Increases the capacity of this buffer.abstract IoBufferclear()abstract IoBuffercompact()abstract IoBufferabstract IoBufferexpand(int expectedRemaining) Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemainingroom from the current position.abstract IoBufferexpand(int position, int expectedRemaining) Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemainingroom from the specifiedposition.abstract IoBufferfill(byte value, int size) Fills this buffer with the specified value.abstract IoBufferfill(int size) Fills this buffer withNUL (0x00).abstract IoBufferfillAndReset(byte value, int size) Fills this buffer with the specified value.abstract IoBufferfillAndReset(int size) Fills this buffer withNUL (0x00).abstract IoBufferflip()abstract voidfree()Declares this buffer and all its derived buffers are not used anymore so that it can be reused by someIoBufferAllocatorimplementations.abstract byteget()abstract IoBufferget(byte[] dst) abstract IoBufferget(byte[] dst, int offset, int length) abstract byteget(int index) static IoBufferAllocatorabstract chargetChar()abstract chargetChar(int index) abstract doubleabstract doublegetDouble(int index) abstract <E extends Enum<E>>
EReads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.abstract <E extends Enum<E>>
EReads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.abstract <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.abstract <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.abstract <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.abstract <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.abstract floatgetFloat()abstract floatgetFloat(int index) Returns hexdump of this buffer.getHexDump(boolean pretty) Returns hexdump of this buffer.getHexDump(int length) Return hexdump of this buffer with limited length.getHexDump(int length, boolean pretty) Return hexdump of this buffer with limited length.abstract intgetInt()abstract intgetInt(int index) abstract longgetLong()abstract longgetLong(int index) abstract intRelative get method for reading a medium int value.abstract intgetMediumInt(int index) Absolute get method for reading a medium int value.abstract ObjectReads a Java object from the buffer using the contextClassLoaderof the current thread.abstract ObjectgetObject(ClassLoader classLoader) Reads a Java object from the buffer using the specifiedclassLoader.abstract StringgetPrefixedString(int prefixLength, CharsetDecoder decoder) Reads a string which has a length field before the actual encoded string, using the specifieddecoderand returns it.abstract StringgetPrefixedString(CharsetDecoder decoder) Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoderand returns it.abstract shortgetShort()abstract shortgetShort(int index) abstract IoBuffergetSlice(int length) Get a new IoBuffer containing a slice of the current bufferabstract IoBuffergetSlice(int index, int length) Get a new IoBuffer containing a slice of the current bufferabstract StringgetString(int fieldSize, CharsetDecoder decoder) Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.abstract StringgetString(CharsetDecoder decoder) Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.abstract shortReads one unsigned byte as a short integer.abstract shortgetUnsigned(int index) Reads one byte as an unsigned short integer.abstract longReads four bytes unsigned integer.abstract longgetUnsignedInt(int index) Reads four bytes unsigned integer.abstract intRelative get method for reading an unsigned medium int value.abstract intgetUnsignedMediumInt(int index) Absolute get method for reading an unsigned medium int value.abstract intReads two bytes unsigned integer.abstract intgetUnsignedShort(int index) Reads two bytes unsigned integer.abstract booleanhasArray()abstract booleanabstract intindexOf(byte b) Returns the first occurrence position of the specified byte from the current position to the current limit.abstract booleanabstract booleanabstract booleanabstract booleanisDirect()abstract booleanstatic booleanabstract intlimit()abstract IoBufferlimit(int newLimit) abstract IoBuffermark()abstract intabstract intabstract IoBufferminimumCapacity(int minimumCapacity) protected static intnormalizeCapacity(int requestedCapacity) Normalizes the specified capacity of the buffer to power of 2, which is often helpful for optimal memory usage and performance.abstract ByteOrderorder()abstract IoBufferabstract intposition()abstract IoBufferposition(int newPosition) abstract booleanprefixedDataAvailable(int prefixLength) abstract booleanprefixedDataAvailable(int prefixLength, int maxDataLength) abstract IoBufferput(byte b) abstract IoBufferput(byte[] src) abstract IoBufferput(byte[] src, int offset, int length) abstract IoBufferput(int index, byte b) abstract IoBufferput(ByteBuffer src) Writes the content of the specifiedsrcinto this buffer.abstract IoBufferWrites the content of the specifiedsrcinto this buffer.abstract IoBufferputChar(char value) abstract IoBufferputChar(int index, char value) abstract IoBufferputDouble(double value) abstract IoBufferputDouble(int index, double value) abstract IoBufferWrites an enum's ordinal value to the buffer as a byte.abstract IoBufferWrites an enum's ordinal value to the buffer as a byte.abstract IoBufferputEnumInt(int index, Enum<?> e) Writes an enum's ordinal value to the buffer as an integer.abstract IoBufferputEnumInt(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.abstract IoBufferputEnumShort(int index, Enum<?> e) Writes an enum's ordinal value to the buffer as a short.abstract IoBufferputEnumShort(Enum<?> e) Writes an enum's ordinal value to the buffer as a short.abstract IoBufferputFloat(float value) abstract IoBufferputFloat(int index, float value) abstract IoBufferputInt(int value) abstract IoBufferputInt(int index, int value) abstract IoBufferputLong(int index, long value) abstract IoBufferputLong(long value) abstract IoBufferputMediumInt(int value) Relative put method for writing a medium int value.abstract IoBufferputMediumInt(int index, int value) Absolute put method for writing a medium int value.abstract IoBufferWrites the specified Java object to the buffer.abstract IoBufferputPrefixedString(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.abstract IoBufferputPrefixedString(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.abstract IoBufferputPrefixedString(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.abstract IoBufferputPrefixedString(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.abstract IoBufferputShort(int index, short value) abstract IoBufferputShort(short value) abstract IoBufferputString(CharSequence val, int fieldSize, CharsetEncoder encoder) Writes the content ofininto this buffer as aNUL-terminated string using the specifiedencoder.abstract IoBufferputString(CharSequence val, CharsetEncoder encoder) Writes the content ofininto this buffer using the specifiedencoder.abstract IoBufferputUnsigned(byte value) Writes an unsigned byte into the ByteBufferabstract IoBufferputUnsigned(int value) Writes an unsigned byte into the ByteBufferabstract IoBufferputUnsigned(int index, byte value) Writes an unsigned byte into the ByteBuffer at a specified positionabstract IoBufferputUnsigned(int index, int value) Writes an unsigned byte into the ByteBuffer at a specified positionabstract IoBufferputUnsigned(int index, long value) Writes an unsigned byte into the ByteBuffer at a specified positionabstract IoBufferputUnsigned(int index, short value) Writes an unsigned byte into the ByteBuffer at a specified positionabstract IoBufferputUnsigned(long value) Writes an unsigned byte into the ByteBufferabstract IoBufferputUnsigned(short value) Writes an unsigned byte into the ByteBufferabstract IoBufferputUnsignedInt(byte value) Writes an unsigned int into the ByteBufferabstract IoBufferputUnsignedInt(int value) Writes an unsigned int into the ByteBufferabstract IoBufferputUnsignedInt(int index, byte value) Writes an unsigned int into the ByteBuffer at a specified positionabstract IoBufferputUnsignedInt(int index, int value) Writes an unsigned int into the ByteBuffer at a specified positionabstract IoBufferputUnsignedInt(int index, long value) Writes an unsigned int into the ByteBuffer at a specified positionabstract IoBufferputUnsignedInt(int index, short value) Writes an unsigned int into the ByteBuffer at a specified positionabstract IoBufferputUnsignedInt(long value) Writes an unsigned int into the ByteBufferabstract IoBufferputUnsignedInt(short value) Writes an unsigned int into the ByteBufferabstract IoBufferputUnsignedShort(byte value) Writes an unsigned short into the ByteBufferabstract IoBufferputUnsignedShort(int value) Writes an unsigned Short into the ByteBufferabstract IoBufferputUnsignedShort(int index, byte value) Writes an unsigned Short into the ByteBuffer at a specified positionabstract IoBufferputUnsignedShort(int index, int value) Writes an unsigned Short into the ByteBuffer at a specified positionabstract IoBufferputUnsignedShort(int index, long value) Writes an unsigned Short into the ByteBuffer at a specified positionabstract IoBufferputUnsignedShort(int index, short value) Writes an unsigned Short into the ByteBuffer at a specified positionabstract IoBufferputUnsignedShort(long value) Writes an unsigned Short into the ByteBufferabstract IoBufferputUnsignedShort(short value) Writes an unsigned Short into the ByteBufferabstract intabstract IoBufferreset()abstract IoBufferrewind()static voidsetAllocator(IoBufferAllocator newAllocator) Sets the allocator used by existing and new buffersabstract IoBuffersetAutoExpand(boolean autoExpand) Turns on or offautoExpand.abstract IoBuffersetAutoShrink(boolean autoShrink) Turns on or offautoShrink.static voidsetUseDirectBuffer(boolean useDirectBuffer) Sets if a direct buffer should be allocated by default when the type of the new buffer is not specified.abstract 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.abstract IoBufferskip(int size) Forwards the position of this buffer as the specifiedsizebytes.abstract IoBufferslice()abstract IoBuffersweep()Clears this buffer and fills its content withNUL.abstract IoBuffersweep(byte value) double Clears this buffer and fills its content withvalue.static IoBufferwrap(byte[] byteArray) Wraps the specified byte array into a MINA heap buffer.static IoBufferwrap(byte[] byteArray, int offset, int length) Wraps the specified byte array into MINA heap buffer.static IoBufferwrap(ByteBuffer nioBuffer) Wraps the specified NIOByteBufferinto a MINA buffer (either direct or heap).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Comparable
compareTo
-
Field Details
-
allocator
The allocator used to create new buffers -
useDirectBuffer
private static boolean useDirectBufferA flag indicating which type of buffer we are using : heap or direct
-
-
Constructor Details
-
IoBuffer
protected IoBuffer()Creates a new instance. This is an empty constructor. It's protected, to forbid its usage by the users.
-
-
Method Details
-
getAllocator
- Returns:
- the allocator used by existing and new buffers
-
setAllocator
Sets the allocator used by existing and new buffers- Parameters:
newAllocator- the new allocator to use
-
isUseDirectBuffer
public static boolean isUseDirectBuffer()- Returns:
trueif and only if a direct buffer is allocated by default when the type of the new buffer is not specified. The default value isfalse.
-
setUseDirectBuffer
public static void setUseDirectBuffer(boolean useDirectBuffer) Sets if a direct buffer should be allocated by default when the type of the new buffer is not specified. The default value isfalse.- Parameters:
useDirectBuffer- Tells if direct buffers should be allocated
-
allocate
Returns the direct or heap buffer which is capable to store the specified amount of bytes.- Parameters:
capacity- the capacity of the buffer- Returns:
- a IoBuffer which can hold up to capacity bytes
- See Also:
-
allocate
Returns a direct or heap IoBuffer which can contain the specified number of bytes.- Parameters:
capacity- the capacity of the bufferuseDirectBuffer-trueto get a direct buffer,falseto get a heap buffer.- Returns:
- a direct or heap IoBuffer which can hold up to capacity bytes
-
wrap
Wraps the specified NIOByteBufferinto a MINA buffer (either direct or heap).- Parameters:
nioBuffer- TheByteBufferto wrap- Returns:
- a IoBuffer containing the bytes stored in the
ByteBuffer
-
wrap
Wraps the specified byte array into a MINA heap buffer. Note that the byte array is not copied, so any modification done on it will be visible by both sides.- Parameters:
byteArray- The byte array to wrap- Returns:
- a heap IoBuffer containing the byte array
-
wrap
Wraps the specified byte array into MINA heap buffer. We just wrap the bytes starting from offset up to offset + length. Note that the byte array is not copied, so any modification done on it will be visible by both sides.- Parameters:
byteArray- The byte array to wrapoffset- The starting point in the byte arraylength- The number of bytes to store- Returns:
- a heap IoBuffer containing the selected part of the byte array
-
normalizeCapacity
protected static int normalizeCapacity(int requestedCapacity) Normalizes the specified capacity of the buffer to power of 2, which is often helpful for optimal memory usage and performance. If it is greater than or equal toInteger.MAX_VALUE, it returnsInteger.MAX_VALUE. If it is zero, it returns zero.- Parameters:
requestedCapacity- The IoBuffer capacity we want to be able to store- Returns:
- The power of 2 strictly superior to the requested capacity
-
free
public abstract void free()Declares this buffer and all its derived buffers are not used anymore so that it can be reused by someIoBufferAllocatorimplementations. It is not mandatory to call this method, but you might want to invoke this method for maximum performance. -
buf
- Returns:
- the underlying NIO
ByteBufferinstance.
-
isDirect
public abstract boolean isDirect()- Returns:
Trueif this is a direct buffer- See Also:
-
isDerived
public abstract boolean isDerived()- Returns:
trueif and only if this buffer is derived from another buffer via one of theduplicate(),slice()orasReadOnlyBuffer()methods.
-
isReadOnly
public abstract boolean isReadOnly()- Returns:
trueif the buffer is readOnly- See Also:
-
minimumCapacity
-
minimumCapacity
Sets the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk bycompact()andshrink()operation. The default value is the initial capacity of the buffer.- Parameters:
minimumCapacity- the wanted minimum capacity- Returns:
- the underlying NIO
ByteBufferinstance.
-
capacity
public abstract int capacity()- Returns:
- the buffer capacity
- See Also:
-
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.
- Parameters:
newCapacity- the wanted capacity- Returns:
- the underlying NIO
ByteBufferinstance.
-
isAutoExpand
public abstract boolean isAutoExpand()- Returns:
trueif and only ifautoExpandis turned on.
-
setAutoExpand
Turns on or offautoExpand.- Parameters:
autoExpand- The flag value to set- Returns:
- The modified IoBuffer instance
-
isAutoShrink
public abstract boolean isAutoShrink()- Returns:
trueif and only ifautoShrinkis turned on.
-
setAutoShrink
Turns on or offautoShrink.- 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.- Parameters:
expectedRemaining- The expected remaining bytes in the buffer- Returns:
- The modified IoBuffer instance
-
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.- Parameters:
position- The starting position from which we want to define a remaining number of bytesexpectedRemaining- The expected remaining bytes in the buffer- Returns:
- The modified IoBuffer instance
-
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 thanminimumCapacity()
. 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 theminimumCapacity(). 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- Returns:
- The modified IoBuffer instance
-
position
public abstract int position()- Returns:
- The current position in the buffer
- See Also:
-
position
- Parameters:
newPosition- Sets the new position in the buffer- Returns:
- the modified IoBuffer
- See Also:
-
limit
public abstract int limit()- Returns:
- the modified IoBuffer 's limit
- See Also:
-
limit
- Parameters:
newLimit- The new buffer's limit- Returns:
- the modified IoBuffer
- See Also:
-
mark
- Returns:
- the modified IoBuffer
- See Also:
-
markValue
public abstract int markValue()- Returns:
- the position of the current mark. This method returns
-1if no mark is set.
-
reset
- Returns:
- the modified IoBuffer
- See Also:
-
clear
- Returns:
- the modified IoBuffer
- See Also:
-
sweep
Clears this buffer and fills its content withNUL. The position is set to zero, the limit is set to the capacity, and the mark is discarded.- Returns:
- the modified IoBuffer
-
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.- Parameters:
value- The value to put in the buffer- Returns:
- the modified IoBuffer
-
flip
- Returns:
- the modified IoBuffer
- See Also:
-
rewind
- Returns:
- the modified IoBuffer
- See Also:
-
remaining
public abstract int remaining()- Returns:
- The remaining bytes in the buffer
- See Also:
-
hasRemaining
public abstract boolean hasRemaining()- Returns:
trueif there are some remaining bytes in the buffer- See Also:
-
duplicate
- Returns:
- the modified IoBuffer
- See Also:
-
slice
- Returns:
- the modified IoBuffer
- See Also:
-
asReadOnlyBuffer
- Returns:
- the modified IoBuffer
- See Also:
-
hasArray
public abstract boolean hasArray()- Returns:
trueif thearray()method will return a byte[]- See Also:
-
array
public abstract byte[] array()- Returns:
- A byte[] if this IoBuffer supports it
- See Also:
-
arrayOffset
public abstract int arrayOffset()- Returns:
- The offset in the returned byte[] when the
array()method is called - See Also:
-
get
public abstract byte get()- Returns:
- The byte at the current position
- See Also:
-
getUnsigned
public abstract short getUnsigned()Reads one unsigned byte as a short integer.- Returns:
- the unsigned short at the current position
-
put
- Parameters:
b- The byte to put in the buffer- Returns:
- the modified IoBuffer
- See Also:
-
get
public abstract byte get(int index) - Parameters:
index- The position for which we want to read a byte- Returns:
- the byte at the given position
- See Also:
-
getUnsigned
public abstract short getUnsigned(int index) Reads one byte as an unsigned short integer.- Parameters:
index- The position for which we want to read an unsigned byte- Returns:
- the unsigned byte at the given position
-
put
- Parameters:
index- The position where the byte will be putb- The byte to put- Returns:
- the modified IoBuffer
- See Also:
-
get
- Parameters:
dst- The destination bufferoffset- The position in the original bufferlength- The number of bytes to copy- Returns:
- the modified IoBuffer
- See Also:
-
get
- Parameters:
dst- The byte[] that will contain the read bytes- Returns:
- the IoBuffer
- See Also:
-
getSlice
Get a new IoBuffer containing a slice of the current buffer- Parameters:
index- The position in the bufferlength- The number of bytes to copy- Returns:
- the new IoBuffer
-
getSlice
Get a new IoBuffer containing a slice of the current buffer- Parameters:
length- The number of bytes to copy- Returns:
- the new IoBuffer
-
put
Writes the content of the specifiedsrcinto this buffer.- Parameters:
src- The source ByteBuffer- Returns:
- the modified IoBuffer
-
put
-
put
- Parameters:
src- The byte[] to putoffset- The position in the sourcelength- The number of bytes to copy- Returns:
- the modified IoBuffer
- See Also:
-
put
- Parameters:
src- The byte[] to put- Returns:
- the modified IoBuffer
- See Also:
-
compact
- Returns:
- the modified IoBuffer
- See Also:
-
order
- Returns:
- the IoBuffer ByteOrder
- See Also:
-
order
-
getChar
public abstract char getChar()- Returns:
- The char at the current position
- See Also:
-
putChar
- Parameters:
value- The char to put at the current position- Returns:
- the modified IoBuffer
- See Also:
-
getChar
public abstract char getChar(int index) - Parameters:
index- The index in the IoBuffer where we will read a char from- Returns:
- the char at 'index' position
- See Also:
-
putChar
- Parameters:
index- The index in the IoBuffer where we will put a char invalue- The char to put at the current position- Returns:
- the modified IoBuffer
- See Also:
-
asCharBuffer
- Returns:
- a new CharBuffer
- See Also:
-
getShort
public abstract short getShort()- Returns:
- The read short
- See Also:
-
getUnsignedShort
public abstract int getUnsignedShort()Reads two bytes unsigned integer.- Returns:
- The read unsigned short
-
putShort
- Parameters:
value- The short to put at the current position- Returns:
- the modified IoBuffer
- See Also:
-
getShort
public abstract short getShort(int index) - Parameters:
index- The index in the IoBuffer where we will read a short from- Returns:
- The read short
- See Also:
-
getUnsignedShort
public abstract int getUnsignedShort(int index) Reads two bytes unsigned integer.- Parameters:
index- The index in the IoBuffer where we will read an unsigned short from- Returns:
- the unsigned short at the given position
-
putShort
- Parameters:
index- The position at which the short should be writtenvalue- The short to put at the current position- Returns:
- the modified IoBuffer
- See Also:
-
asShortBuffer
- Returns:
- A ShortBuffer from this IoBuffer
- See Also:
-
getInt
public abstract int getInt()- Returns:
- The int read
- See Also:
-
getUnsignedInt
public abstract long getUnsignedInt()Reads four bytes unsigned integer.- Returns:
- The unsigned int read
-
getMediumInt
public abstract 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.
- Returns:
- The medium int value at the buffer's current position
-
getUnsignedMediumInt
public abstract 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.
- Returns:
- The unsigned medium int value at the buffer's current position
-
getMediumInt
public abstract 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.
- Parameters:
index- The index from which the medium int will be read- Returns:
- The medium int value at the given index
- Throws:
IndexOutOfBoundsException- Ifindexis negative or not smaller than the buffer's limit
-
getUnsignedMediumInt
public abstract 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.
- Parameters:
index- The index from which the unsigned medium int will be read- Returns:
- The unsigned medium int value at the given index
- Throws:
IndexOutOfBoundsException- Ifindexis negative or not smaller than the buffer's limit
-
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.
- 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.
- Parameters:
index- The index at which the bytes will be writtenvalue- The medium int value to be written- Returns:
- the modified IoBuffer
- Throws:
IndexOutOfBoundsException- Ifindexis negative or not smaller than the buffer's limit, minus three
-
putInt
- Parameters:
value- The int to put at the current position- Returns:
- the modified IoBuffer
- See Also:
-
putUnsigned
Writes an unsigned byte into the ByteBuffer- Parameters:
value- the byte to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- 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- Parameters:
value- the short to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- 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- Parameters:
value- the int to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- 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- Parameters:
value- the long to write- Returns:
- the modified IoBuffer
-
putUnsigned
Writes an unsigned byte into the ByteBuffer at a specified position- Parameters:
index- the position in the buffer to write the valuevalue- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer- Parameters:
value- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- 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- Parameters:
value- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- 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- Parameters:
value- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- 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- Parameters:
value- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
Writes an unsigned int into the ByteBuffer at a specified position- 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- Parameters:
value- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- 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- Parameters:
value- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- 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- Parameters:
value- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- 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- Parameters:
value- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
Writes an unsigned Short into the ByteBuffer at a specified position- Parameters:
index- the position in the buffer to write the shortvalue- the long to write- Returns:
- the modified IoBuffer
-
getInt
public abstract int getInt(int index) - Parameters:
index- The index in the IoBuffer where we will read an int from- Returns:
- the int at the given position
- See Also:
-
getUnsignedInt
public abstract long getUnsignedInt(int index) Reads four bytes unsigned integer.- Parameters:
index- The index in the IoBuffer where we will read an unsigned int from- Returns:
- The long at the given position
-
putInt
- Parameters:
index- The position where to put the intvalue- The int to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
asIntBuffer
- Returns:
- the modified IoBuffer
- See Also:
-
getLong
public abstract long getLong()- Returns:
- The long at the current position
- See Also:
-
putLong
- Parameters:
value- The log to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
getLong
public abstract long getLong(int index) - Parameters:
index- The index in the IoBuffer where we will read a long from- Returns:
- the long at the given position
- See Also:
-
putLong
- Parameters:
index- The position where to put the longvalue- The long to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
asLongBuffer
- Returns:
- a LongBuffer from this IoBffer
- See Also:
-
getFloat
public abstract float getFloat()- Returns:
- the float at the current position
- See Also:
-
putFloat
- Parameters:
value- The float to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
getFloat
public abstract float getFloat(int index) - Parameters:
index- The index in the IoBuffer where we will read a float from- Returns:
- The float at the given position
- See Also:
-
putFloat
- Parameters:
index- The position where to put the floatvalue- The float to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
asFloatBuffer
- Returns:
- A FloatBuffer from this IoBuffer
- See Also:
-
getDouble
public abstract double getDouble()- Returns:
- the double at the current position
- See Also:
-
putDouble
- Parameters:
value- The double to put at the IoBuffer current position- Returns:
- the modified IoBuffer
- See Also:
-
getDouble
public abstract double getDouble(int index) - Parameters:
index- The position where to get the double from- Returns:
- The double at the given position
- See Also:
-
putDouble
- Parameters:
index- The position where to put the doublevalue- The double to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
-
asDoubleBuffer
- Returns:
- A buffer containing Double
- See Also:
-
asInputStream
- Returns:
- an
InputStreamthat reads the data from this buffer.InputStream.read()returns-1if the buffer position reaches to the limit.
-
asOutputStream
- 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 callingsetAutoExpand(boolean)to prevent the unexpected runtime exception.
-
getHexDump
Returns hexdump of this buffer. The data and pointer are not changed as a result of this method call.- Returns:
- hexadecimal representation of this buffer
-
getHexDump
Returns hexdump of this buffer. The data and pointer are not changed as a result of this method call.- Parameters:
pretty- If we should do a pretty dump- Returns:
- hexadecimal representation of this buffer
-
getHexDump
Return hexdump of this buffer with limited length.- Parameters:
length- The maximum number of bytes to dump from the current buffer position.- Returns:
- hexadecimal representation of this buffer
-
getHexDump
Return hexdump of this buffer with limited length.- Parameters:
length- The maximum number of bytes to dump from the current buffer position.pretty- If we should do a pretty dump- Returns:
- hexadecimal representation of this buffer
-
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.- Parameters:
decoder- TheCharsetDecoderto use- Returns:
- the read String
- Throws:
CharacterCodingException- Thrown when an error occurred while decoding the buffer
-
getString
public abstract String getString(int fieldSize, CharsetDecoder decoder) throws CharacterCodingException Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.- 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
public abstract IoBuffer putString(CharSequence val, CharsetEncoder encoder) throws CharacterCodingException Writes the content ofininto this buffer using the specifiedencoder. This method doesn't terminate string withNUL. You have to do it by yourself.- 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 abstract 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.- 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).- Parameters:
decoder- The CharsetDecoder to use- Returns:
- The read String
- Throws:
CharacterCodingException- When we have an error while decoding the String
-
getPrefixedString
public abstract 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.- Parameters:
prefixLength- the length of the length field (1, 2, or 4)decoder- The CharsetDecoder to use- Returns:
- The read String
- Throws:
CharacterCodingException- When we have an error while decoding the String
-
putPrefixedString
public abstract 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).- 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 abstract 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).- 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 abstract 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)- 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 abstract 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.- 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.- 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.- 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 abstract boolean prefixedDataAvailable(int prefixLength) - 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 useprefixedDataAvailable(int, int)instead.- Throws:
IllegalArgumentException- if prefixLength is wrongBufferDataException- if data length is negative
-
prefixedDataAvailable
public abstract boolean prefixedDataAvailable(int prefixLength, int maxDataLength) - 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.- Throws:
IllegalArgumentException- if prefixLength is wrongBufferDataException- if data length is negative or greater thenmaxDataLength
-
indexOf
public abstract int indexOf(byte b) Returns the first occurrence position of the specified byte from the current position to the current limit.- Parameters:
b- The byte we are looking for- Returns:
-1if the specified byte is not found
-
skip
Forwards the position of this buffer as the specifiedsizebytes.- Parameters:
size- The added size- Returns:
- The modified IoBuffer
-
fill
Fills this buffer with the specified value. This method moves buffer position forward.- Parameters:
value- The value to fill the IoBuffer withsize- The added size- Returns:
- The modified IoBuffer
-
fillAndReset
Fills this buffer with the specified value. This method does not change buffer position.- Parameters:
value- The value to fill the IoBuffer withsize- The added size- Returns:
- The modified IoBuffer
-
fill
Fills this buffer withNUL (0x00). This method moves buffer position forward.- Parameters:
size- The added size- Returns:
- The modified IoBuffer
-
fillAndReset
Fills this buffer withNUL (0x00). This method does not change buffer position.- 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.- Type Parameters:
E- The enum type to return- Parameters:
enumClass- The enum's class object- Returns:
- The correlated enum constant
-
getEnum
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.- Type Parameters:
E- The enum type to return- Parameters:
index- the index from which the byte will be readenumClass- 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.- 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.- 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.- 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.- 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
-
putEnumShort
-
putEnumInt
-
putEnumInt
-
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.
- 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.- 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.- 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.- 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.- 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.- 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.- 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.- 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:
-
putEnumSet
-
putEnumSet
Writes the specifiedSetto the buffer as a byte sized bit vector.- 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
-
putEnumSetShort
Writes the specifiedSetto the buffer as a short sized bit vector.- 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
-
putEnumSetInt
Writes the specifiedSetto the buffer as an int sized bit vector.- 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
-
putEnumSetLong
Writes the specifiedSetto the buffer as a long sized bit vector.- 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
-