Class IoBufferWrapper
- java.lang.Object
-
- org.apache.mina.core.buffer.IoBuffer
-
- org.apache.mina.core.buffer.IoBufferWrapper
-
- All Implemented Interfaces:
Comparable<IoBuffer>
- Direct Known Subclasses:
ProxyHandshakeIoBuffer
public class IoBufferWrapper extends IoBuffer
AIoBuffer
that wraps a buffer and proxies any operations to it.You can think this class like a
FileOutputStream
. All operations are proxied by default so that you can extend this class and override existing operations selectively. You can introduce new operations, too.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
IoBufferWrapper(IoBuffer buf)
Create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
array()
int
arrayOffset()
CharBuffer
asCharBuffer()
DoubleBuffer
asDoubleBuffer()
FloatBuffer
asFloatBuffer()
InputStream
asInputStream()
IntBuffer
asIntBuffer()
LongBuffer
asLongBuffer()
OutputStream
asOutputStream()
IoBuffer
asReadOnlyBuffer()
ShortBuffer
asShortBuffer()
ByteBuffer
buf()
int
capacity()
IoBuffer
capacity(int newCapacity)
Increases the capacity of this buffer.IoBuffer
clear()
IoBuffer
compact()
int
compareTo(IoBuffer that)
IoBuffer
duplicate()
boolean
equals(Object ob)
IoBuffer
expand(int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemaining
room from the current position.IoBuffer
expand(int pos, int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemaining
room from the specifiedposition
.IoBuffer
fill(byte value, int size)
Fills this buffer with the specified value.IoBuffer
fill(int size)
Fills this buffer withNUL (0x00)
.IoBuffer
fillAndReset(byte value, int size)
Fills this buffer with the specified value.IoBuffer
fillAndReset(int size)
Fills this buffer withNUL (0x00)
.IoBuffer
flip()
void
free()
Declares this buffer and all its derived buffers are not used anymore so that it can be reused by someIoBufferAllocator
implementations.byte
get()
IoBuffer
get(byte[] dst)
IoBuffer
get(byte[] dst, int offset, int length)
byte
get(int index)
char
getChar()
char
getChar(int index)
double
getDouble()
double
getDouble(int index)
<E extends Enum<E>>
EgetEnum(int index, Class<E> enumClass)
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EgetEnum(Class<E> enumClass)
Reads 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.<E extends Enum<E>>
Set<E>getEnumSet(int index, Class<E> enumClass)
Reads a byte sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
Set<E>getEnumSet(Class<E> enumClass)
Reads a byte sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
Set<E>getEnumSetInt(int index, Class<E> enumClass)
Reads an int sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
Set<E>getEnumSetInt(Class<E> enumClass)
Reads an int sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
Set<E>getEnumSetLong(int index, Class<E> enumClass)
Reads a long sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
Set<E>getEnumSetLong(Class<E> enumClass)
Reads a long sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
Set<E>getEnumSetShort(int index, Class<E> enumClass)
Reads a short sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
Set<E>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.float
getFloat()
float
getFloat(int index)
int
getInt()
int
getInt(int index)
long
getLong()
long
getLong(int index)
int
getMediumInt()
Relative get method for reading a medium int value.int
getMediumInt(int index)
Absolute get method for reading a medium int value.Object
getObject()
Reads a Java object from the buffer using the contextClassLoader
of the current thread.Object
getObject(ClassLoader classLoader)
Reads a Java object from the buffer using the specifiedclassLoader
.IoBuffer
getParentBuffer()
String
getPrefixedString(int prefixLength, CharsetDecoder decoder)
Reads a string which has a length field before the actual encoded string, using the specifieddecoder
and returns it.String
getPrefixedString(CharsetDecoder decoder)
Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoder
and returns it.short
getShort()
short
getShort(int index)
IoBuffer
getSlice(int length)
Get a new IoBuffer containing a slice of the current bufferIoBuffer
getSlice(int index, int length)
Get a new IoBuffer containing a slice of the current bufferString
getString(int fieldSize, CharsetDecoder decoder)
Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it.String
getString(CharsetDecoder decoder)
Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it.short
getUnsigned()
Reads one unsigned byte as a short integer.short
getUnsigned(int index)
Reads one byte as an unsigned short integer.long
getUnsignedInt()
Reads four bytes unsigned integer.long
getUnsignedInt(int index)
Reads four bytes unsigned integer.int
getUnsignedMediumInt()
Relative get method for reading an unsigned medium int value.int
getUnsignedMediumInt(int index)
Absolute get method for reading an unsigned medium int value.int
getUnsignedShort()
Reads two bytes unsigned integer.int
getUnsignedShort(int index)
Reads two bytes unsigned integer.boolean
hasArray()
int
hashCode()
boolean
hasRemaining()
int
indexOf(byte b)
Returns the first occurrence position of the specified byte from the current position to the current limit.boolean
isAutoExpand()
boolean
isAutoShrink()
boolean
isDerived()
boolean
isDirect()
boolean
isReadOnly()
int
limit()
IoBuffer
limit(int newLimit)
IoBuffer
mark()
int
markValue()
int
minimumCapacity()
IoBuffer
minimumCapacity(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.ByteOrder
order()
IoBuffer
order(ByteOrder bo)
int
position()
IoBuffer
position(int newPosition)
boolean
prefixedDataAvailable(int prefixLength)
boolean
prefixedDataAvailable(int prefixLength, int maxDataLength)
IoBuffer
put(byte b)
IoBuffer
put(byte[] src)
IoBuffer
put(byte[] src, int offset, int length)
IoBuffer
put(int index, byte b)
IoBuffer
put(ByteBuffer src)
Writes the content of the specifiedsrc
into this buffer.IoBuffer
put(IoBuffer src)
Writes the content of the specifiedsrc
into this buffer.IoBuffer
putChar(char value)
IoBuffer
putChar(int index, char value)
IoBuffer
putDouble(double value)
IoBuffer
putDouble(int index, double value)
IoBuffer
putEnum(int index, Enum<?> e)
Writes an enum's ordinal value to the buffer as a byte.IoBuffer
putEnum(Enum<?> e)
Writes an enum's ordinal value to the buffer as a byte.IoBuffer
putEnumInt(int index, Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.IoBuffer
putEnumInt(Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.<E extends Enum<E>>
IoBufferputEnumSet(int index, Set<E> set)
Writes the specifiedSet
to the buffer as a byte sized bit vector.<E extends Enum<E>>
IoBufferputEnumSet(Set<E> set)
Writes the specifiedSet
to the buffer as a byte sized bit vector.<E extends Enum<E>>
IoBufferputEnumSetInt(int index, Set<E> set)
Writes the specifiedSet
to the buffer as an int sized bit vector.<E extends Enum<E>>
IoBufferputEnumSetInt(Set<E> set)
Writes the specifiedSet
to the buffer as an int sized bit vector.<E extends Enum<E>>
IoBufferputEnumSetLong(int index, Set<E> set)
Writes the specifiedSet
to the buffer as a long sized bit vector.<E extends Enum<E>>
IoBufferputEnumSetLong(Set<E> set)
Writes the specifiedSet
to the buffer as a long sized bit vector.<E extends Enum<E>>
IoBufferputEnumSetShort(int index, Set<E> set)
Writes the specifiedSet
to the buffer as a short sized bit vector.<E extends Enum<E>>
IoBufferputEnumSetShort(Set<E> set)
Writes the specifiedSet
to the buffer as a short sized bit vector.IoBuffer
putEnumShort(int index, Enum<?> e)
Writes an enum's ordinal value to the buffer as a short.IoBuffer
putEnumShort(Enum<?> e)
Writes an enum's ordinal value to the buffer as a short.IoBuffer
putFloat(float value)
IoBuffer
putFloat(int index, float value)
IoBuffer
putInt(int value)
IoBuffer
putInt(int index, int value)
IoBuffer
putLong(int index, long value)
IoBuffer
putLong(long value)
IoBuffer
putMediumInt(int value)
Relative put method for writing a medium int value.IoBuffer
putMediumInt(int index, int value)
Absolute put method for writing a medium int value.IoBuffer
putObject(Object o)
Writes the specified Java object to the buffer.IoBuffer
putPrefixedString(CharSequence in, int prefixLength, int padding, byte padValue, CharsetEncoder encoder)
Writes the content ofval
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.IoBuffer
putPrefixedString(CharSequence in, int prefixLength, int padding, CharsetEncoder encoder)
Writes the content ofin
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.IoBuffer
putPrefixedString(CharSequence in, int prefixLength, CharsetEncoder encoder)
Writes the content ofin
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.IoBuffer
putPrefixedString(CharSequence in, CharsetEncoder encoder)
Writes the content ofin
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.IoBuffer
putShort(int index, short value)
IoBuffer
putShort(short value)
IoBuffer
putString(CharSequence in, int fieldSize, CharsetEncoder encoder)
Writes the content ofin
into this buffer as aNUL
-terminated string using the specifiedencoder
.IoBuffer
putString(CharSequence in, CharsetEncoder encoder)
Writes the content ofin
into this buffer using the specifiedencoder
.IoBuffer
putUnsigned(byte value)
Writes an unsigned byte into the ByteBufferIoBuffer
putUnsigned(int value)
Writes an unsigned byte into the ByteBufferIoBuffer
putUnsigned(int index, byte value)
Writes an unsigned byte into the ByteBuffer at a specified positionIoBuffer
putUnsigned(int index, int value)
Writes an unsigned byte into the ByteBuffer at a specified positionIoBuffer
putUnsigned(int index, long value)
Writes an unsigned byte into the ByteBuffer at a specified positionIoBuffer
putUnsigned(int index, short value)
Writes an unsigned byte into the ByteBuffer at a specified positionIoBuffer
putUnsigned(long value)
Writes an unsigned byte into the ByteBufferIoBuffer
putUnsigned(short value)
Writes an unsigned byte into the ByteBufferIoBuffer
putUnsignedInt(byte value)
Writes an unsigned int into the ByteBufferIoBuffer
putUnsignedInt(int value)
Writes an unsigned int into the ByteBufferIoBuffer
putUnsignedInt(int index, byte value)
Writes an unsigned int into the ByteBuffer at a specified positionIoBuffer
putUnsignedInt(int index, int value)
Writes an unsigned int into the ByteBuffer at a specified positionIoBuffer
putUnsignedInt(int index, long value)
Writes an unsigned int into the ByteBuffer at a specified positionIoBuffer
putUnsignedInt(int index, short value)
Writes an unsigned int into the ByteBuffer at a specified positionIoBuffer
putUnsignedInt(long value)
Writes an unsigned int into the ByteBufferIoBuffer
putUnsignedInt(short value)
Writes an unsigned int into the ByteBufferIoBuffer
putUnsignedShort(byte value)
Writes an unsigned short into the ByteBufferIoBuffer
putUnsignedShort(int value)
Writes an unsigned Short into the ByteBufferIoBuffer
putUnsignedShort(int index, byte value)
Writes an unsigned Short into the ByteBuffer at a specified positionIoBuffer
putUnsignedShort(int index, int value)
Writes an unsigned Short into the ByteBuffer at a specified positionIoBuffer
putUnsignedShort(int index, long value)
Writes an unsigned Short into the ByteBuffer at a specified positionIoBuffer
putUnsignedShort(int index, short value)
Writes an unsigned Short into the ByteBuffer at a specified positionIoBuffer
putUnsignedShort(long value)
Writes an unsigned Short into the ByteBufferIoBuffer
putUnsignedShort(short value)
Writes an unsigned Short into the ByteBufferint
remaining()
IoBuffer
reset()
IoBuffer
rewind()
IoBuffer
setAutoExpand(boolean autoExpand)
Turns on or offautoExpand
.IoBuffer
setAutoShrink(boolean autoShrink)
Turns on or offautoShrink
.IoBuffer
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.IoBuffer
skip(int size)
Forwards the position of this buffer as the specifiedsize
bytes.IoBuffer
slice()
IoBuffer
sweep()
Clears this buffer and fills its content withNUL
.IoBuffer
sweep(byte value)
double Clears this buffer and fills its content withvalue
.String
toString()
-
Methods inherited from class org.apache.mina.core.buffer.IoBuffer
allocate, allocate, getAllocator, getHexDump, getHexDump, getHexDump, getHexDump, isUseDirectBuffer, normalizeCapacity, setAllocator, setUseDirectBuffer, wrap, wrap, wrap
-
-
-
-
Constructor Detail
-
IoBufferWrapper
protected IoBufferWrapper(IoBuffer buf)
Create a new instance.- Parameters:
buf
- the buffer to be proxied
-
-
Method Detail
-
getParentBuffer
public IoBuffer getParentBuffer()
- Returns:
- the parent buffer that this buffer wrapped.
-
isDirect
public boolean isDirect()
- Specified by:
isDirect
in classIoBuffer
- Returns:
True
if this is a direct buffer- See Also:
ByteBuffer.isDirect()
-
buf
public ByteBuffer buf()
- Specified by:
buf
in classIoBuffer
- Returns:
- the underlying NIO
ByteBuffer
instance.
-
capacity
public int capacity()
- Specified by:
capacity
in classIoBuffer
- Returns:
- the buffer capacity
- See Also:
Buffer.capacity()
-
position
public int position()
- Specified by:
position
in classIoBuffer
- Returns:
- The current position in the buffer
- See Also:
Buffer.position()
-
position
public IoBuffer position(int newPosition)
- Specified by:
position
in classIoBuffer
- Parameters:
newPosition
- Sets the new position in the buffer- Returns:
- the modified IoBuffer
- See Also:
Buffer.position(int)
-
limit
public int limit()
- Specified by:
limit
in classIoBuffer
- Returns:
- the modified IoBuffer 's limit
- See Also:
Buffer.limit()
-
limit
public IoBuffer limit(int newLimit)
- Specified by:
limit
in classIoBuffer
- Parameters:
newLimit
- The new buffer's limit- Returns:
- the modified IoBuffer
- See Also:
Buffer.limit(int)
-
mark
public IoBuffer mark()
- Specified by:
mark
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
Buffer.mark()
-
reset
public IoBuffer reset()
- Specified by:
reset
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
Buffer.reset()
-
clear
public IoBuffer clear()
- Specified by:
clear
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
Buffer.clear()
-
sweep
public IoBuffer 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.
-
sweep
public IoBuffer sweep(byte value)
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
public IoBuffer flip()
- Specified by:
flip
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
Buffer.flip()
-
rewind
public IoBuffer rewind()
- Specified by:
rewind
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
Buffer.rewind()
-
remaining
public int remaining()
- Specified by:
remaining
in classIoBuffer
- Returns:
- The remaining bytes in the buffer
- See Also:
Buffer.remaining()
-
hasRemaining
public boolean hasRemaining()
- Specified by:
hasRemaining
in classIoBuffer
- Returns:
true
if there are some remaining bytes in the buffer- See Also:
Buffer.hasRemaining()
-
get
public byte get()
- Specified by:
get
in classIoBuffer
- Returns:
- The byte at the current position
- See Also:
ByteBuffer.get()
-
getUnsigned
public short getUnsigned()
Reads one unsigned byte as a short integer.- Specified by:
getUnsigned
in classIoBuffer
- Returns:
- the unsigned short at the current position
-
put
public IoBuffer put(byte b)
- Specified by:
put
in classIoBuffer
- Parameters:
b
- The byte to put in the buffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.put(byte)
-
get
public byte get(int index)
- Specified by:
get
in classIoBuffer
- Parameters:
index
- The position for which we want to read a byte- Returns:
- the byte at the given position
- See Also:
ByteBuffer.get(int)
-
getUnsigned
public short getUnsigned(int index)
Reads one byte as an unsigned short integer.- Specified by:
getUnsigned
in classIoBuffer
- Parameters:
index
- The position for which we want to read an unsigned byte- Returns:
- the unsigned byte at the given position
-
put
public IoBuffer put(int index, byte b)
- Specified by:
put
in classIoBuffer
- Parameters:
index
- The position where the byte will be putb
- The byte to put- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.put(int, byte)
-
get
public IoBuffer get(byte[] dst, int offset, int length)
- Specified by:
get
in classIoBuffer
- Parameters:
dst
- The destination bufferoffset
- The position in the original bufferlength
- The number of bytes to copy- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.get(byte[], int, int)
-
getSlice
public IoBuffer getSlice(int index, int length)
Get a new IoBuffer containing a slice of the current buffer
-
getSlice
public IoBuffer getSlice(int length)
Get a new IoBuffer containing a slice of the current buffer
-
get
public IoBuffer get(byte[] dst)
- Specified by:
get
in classIoBuffer
- Parameters:
dst
- The byte[] that will contain the read bytes- Returns:
- the IoBuffer
- See Also:
ByteBuffer.get(byte[])
-
put
public IoBuffer put(ByteBuffer src)
Writes the content of the specifiedsrc
into this buffer.
-
put
public IoBuffer put(byte[] src, int offset, int length)
- Specified by:
put
in classIoBuffer
- Parameters:
src
- The byte[] to putoffset
- The position in the sourcelength
- The number of bytes to copy- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.put(byte[], int, int)
-
put
public IoBuffer put(byte[] src)
- Specified by:
put
in classIoBuffer
- Parameters:
src
- The byte[] to put- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.put(byte[])
-
compact
public IoBuffer compact()
- Specified by:
compact
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.compact()
-
compareTo
public int compareTo(IoBuffer that)
-
order
public ByteOrder order()
- Specified by:
order
in classIoBuffer
- Returns:
- the IoBuffer ByteOrder
- See Also:
ByteBuffer.order()
-
order
public IoBuffer order(ByteOrder bo)
- Specified by:
order
in classIoBuffer
- Parameters:
bo
- The new ByteBuffer to use for this IoBuffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.order(ByteOrder)
-
getChar
public char getChar()
- Specified by:
getChar
in classIoBuffer
- Returns:
- The char at the current position
- See Also:
ByteBuffer.getChar()
-
putChar
public IoBuffer putChar(char value)
- Specified by:
putChar
in classIoBuffer
- Parameters:
value
- The char to put at the current position- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putChar(char)
-
getChar
public char getChar(int index)
- Specified by:
getChar
in classIoBuffer
- Parameters:
index
- The index in the IoBuffer where we will read a char from- Returns:
- the char at 'index' position
- See Also:
ByteBuffer.getChar(int)
-
putChar
public IoBuffer putChar(int index, char value)
- Specified by:
putChar
in classIoBuffer
- 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:
ByteBuffer.putChar(int, char)
-
asCharBuffer
public CharBuffer asCharBuffer()
- Specified by:
asCharBuffer
in classIoBuffer
- Returns:
- a new CharBuffer
- See Also:
ByteBuffer.asCharBuffer()
-
getShort
public short getShort()
- Specified by:
getShort
in classIoBuffer
- Returns:
- The read short
- See Also:
ByteBuffer.getShort()
-
getUnsignedShort
public int getUnsignedShort()
Reads two bytes unsigned integer.- Specified by:
getUnsignedShort
in classIoBuffer
- Returns:
- The read unsigned short
-
putShort
public IoBuffer putShort(short value)
- Specified by:
putShort
in classIoBuffer
- Parameters:
value
- The short to put at the current position- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putShort(short)
-
getShort
public short getShort(int index)
- Specified by:
getShort
in classIoBuffer
- Parameters:
index
- The index in the IoBuffer where we will read a short from- Returns:
- The read short
- See Also:
ByteBuffer.getShort()
-
getUnsignedShort
public int getUnsignedShort(int index)
Reads two bytes unsigned integer.- Specified by:
getUnsignedShort
in classIoBuffer
- Parameters:
index
- The index in the IoBuffer where we will read an unsigned short from- Returns:
- the unsigned short at the given position
-
putShort
public IoBuffer putShort(int index, short value)
- Specified by:
putShort
in classIoBuffer
- 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:
ByteBuffer.putShort(int, short)
-
asShortBuffer
public ShortBuffer asShortBuffer()
- Specified by:
asShortBuffer
in classIoBuffer
- Returns:
- A ShortBuffer from this IoBuffer
- See Also:
ByteBuffer.asShortBuffer()
-
getInt
public int getInt()
- Specified by:
getInt
in classIoBuffer
- Returns:
- The int read
- See Also:
ByteBuffer.getInt()
-
getUnsignedInt
public long getUnsignedInt()
Reads four bytes unsigned integer.- Specified by:
getUnsignedInt
in classIoBuffer
- Returns:
- The unsigned int read
-
putInt
public IoBuffer putInt(int value)
- Specified by:
putInt
in classIoBuffer
- Parameters:
value
- The int to put at the current position- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putInt(int)
-
putUnsignedInt
public IoBuffer putUnsignedInt(byte value)
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
value
- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
public IoBuffer putUnsignedInt(int index, byte value)
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
public IoBuffer putUnsignedInt(short value)
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
value
- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
public IoBuffer putUnsignedInt(int index, short value)
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
public IoBuffer putUnsignedInt(int value)
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
value
- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
public IoBuffer putUnsignedInt(int index, int value)
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
public IoBuffer putUnsignedInt(long value)
Writes an unsigned int into the ByteBuffer- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
value
- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedInt
public IoBuffer putUnsignedInt(int index, long value)
Writes an unsigned int into the ByteBuffer at a specified position- Specified by:
putUnsignedInt
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(byte value)
Writes an unsigned short into the ByteBuffer- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
value
- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(int index, byte value)
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the byte to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(short value)
Writes an unsigned Short into the ByteBuffer- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
value
- the short to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(int index, short value)
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the unsigned shortvalue
- the unsigned short to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(int value)
Writes an unsigned Short into the ByteBuffer- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
value
- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(int index, int value)
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the int to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(long value)
Writes an unsigned Short into the ByteBuffer- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
value
- the long to write- Returns:
- the modified IoBuffer
-
putUnsignedShort
public IoBuffer putUnsignedShort(int index, long value)
Writes an unsigned Short into the ByteBuffer at a specified position- Specified by:
putUnsignedShort
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the shortvalue
- the long to write- Returns:
- the modified IoBuffer
-
getInt
public int getInt(int index)
- Specified by:
getInt
in classIoBuffer
- Parameters:
index
- The index in the IoBuffer where we will read an int from- Returns:
- the int at the given position
- See Also:
ByteBuffer.getInt(int)
-
getUnsignedInt
public long getUnsignedInt(int index)
Reads four bytes unsigned integer.- Specified by:
getUnsignedInt
in classIoBuffer
- Parameters:
index
- The index in the IoBuffer where we will read an unsigned int from- Returns:
- The long at the given position
-
putInt
public IoBuffer putInt(int index, int value)
- Specified by:
putInt
in classIoBuffer
- Parameters:
index
- The position where to put the intvalue
- The int to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putInt(int, int)
-
asIntBuffer
public IntBuffer asIntBuffer()
- Specified by:
asIntBuffer
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.asIntBuffer()
-
getLong
public long getLong()
- Specified by:
getLong
in classIoBuffer
- Returns:
- The long at the current position
- See Also:
ByteBuffer.getLong()
-
putLong
public IoBuffer putLong(long value)
- Specified by:
putLong
in classIoBuffer
- Parameters:
value
- The log to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putLong(int, long)
-
getLong
public long getLong(int index)
- Specified by:
getLong
in classIoBuffer
- Parameters:
index
- The index in the IoBuffer where we will read a long from- Returns:
- the long at the given position
- See Also:
ByteBuffer.getLong(int)
-
putLong
public IoBuffer putLong(int index, long value)
- Specified by:
putLong
in classIoBuffer
- Parameters:
index
- The position where to put the longvalue
- The long to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putLong(int, long)
-
asLongBuffer
public LongBuffer asLongBuffer()
- Specified by:
asLongBuffer
in classIoBuffer
- Returns:
- a LongBuffer from this IoBffer
- See Also:
ByteBuffer.asLongBuffer()
-
getFloat
public float getFloat()
- Specified by:
getFloat
in classIoBuffer
- Returns:
- the float at the current position
- See Also:
ByteBuffer.getFloat()
-
putFloat
public IoBuffer putFloat(float value)
- Specified by:
putFloat
in classIoBuffer
- Parameters:
value
- The float to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putFloat(float)
-
getFloat
public float getFloat(int index)
- Specified by:
getFloat
in classIoBuffer
- Parameters:
index
- The index in the IoBuffer where we will read a float from- Returns:
- The float at the given position
- See Also:
ByteBuffer.getFloat(int)
-
putFloat
public IoBuffer putFloat(int index, float value)
- Specified by:
putFloat
in classIoBuffer
- Parameters:
index
- The position where to put the floatvalue
- The float to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putFloat(int, float)
-
asFloatBuffer
public FloatBuffer asFloatBuffer()
- Specified by:
asFloatBuffer
in classIoBuffer
- Returns:
- A FloatBuffer from this IoBuffer
- See Also:
ByteBuffer.asFloatBuffer()
-
getDouble
public double getDouble()
- Specified by:
getDouble
in classIoBuffer
- Returns:
- the double at the current position
- See Also:
ByteBuffer.getDouble()
-
putDouble
public IoBuffer putDouble(double value)
- Specified by:
putDouble
in classIoBuffer
- Parameters:
value
- The double to put at the IoBuffer current position- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putDouble(double)
-
getDouble
public double getDouble(int index)
- Specified by:
getDouble
in classIoBuffer
- Parameters:
index
- The position where to get the double from- Returns:
- The double at the given position
- See Also:
ByteBuffer.getDouble(int)
-
putDouble
public IoBuffer putDouble(int index, double value)
- Specified by:
putDouble
in classIoBuffer
- Parameters:
index
- The position where to put the doublevalue
- The double to put in the IoBuffer- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.putDouble(int, double)
-
asDoubleBuffer
public DoubleBuffer asDoubleBuffer()
- Specified by:
asDoubleBuffer
in classIoBuffer
- Returns:
- A buffer containing Double
- See Also:
ByteBuffer.asDoubleBuffer()
-
getString
public String getString(int fieldSize, CharsetDecoder decoder) throws CharacterCodingException
Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it.- Specified by:
getString
in classIoBuffer
- Parameters:
fieldSize
- the maximum number of bytes to readdecoder
- TheCharsetDecoder
to use- Returns:
- the read String
- Throws:
CharacterCodingException
- Thrown when an error occurred while decoding the buffer
-
getString
public String getString(CharsetDecoder decoder) throws CharacterCodingException
Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it. This method reads until the limit of this buffer if noNUL
is found.- Specified by:
getString
in classIoBuffer
- Parameters:
decoder
- TheCharsetDecoder
to use- Returns:
- the read String
- Throws:
CharacterCodingException
- Thrown when an error occurred while decoding the buffer
-
getPrefixedString
public String getPrefixedString(CharsetDecoder decoder) throws CharacterCodingException
Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoder
and returns it. This method is a shortcut forgetPrefixedString(2, decoder)
.- Specified by:
getPrefixedString
in 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 specifieddecoder
and returns it.- Specified by:
getPrefixedString
in classIoBuffer
- 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
-
putString
public IoBuffer putString(CharSequence in, int fieldSize, CharsetEncoder encoder) throws CharacterCodingException
Writes the content ofin
into 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 twoNUL
s as a terminator.Please note that this method doesn't terminate with
NUL
if the input string is longer thanfieldSize
.- Specified by:
putString
in classIoBuffer
- Parameters:
in
- 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
-
putString
public IoBuffer putString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException
Writes the content ofin
into this buffer using the specifiedencoder
. This method doesn't terminate string withNUL
. You have to do it by yourself.- Specified by:
putString
in 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 String
-
putPrefixedString
public IoBuffer putPrefixedString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException
Writes the content ofin
into 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:
putPrefixedString
in 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 ofin
into 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:
putPrefixedString
in 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 ofin
into 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:
putPrefixedString
in classIoBuffer
- Parameters:
in
- The CharSequence to put in the IoBufferprefixLength
- the length of the length field (1, 2, or 4)padding
- the number of paddedNUL
s (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 in, int prefixLength, int padding, byte padValue, CharsetEncoder encoder) throws CharacterCodingException
Writes the content ofval
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.- Specified by:
putPrefixedString
in classIoBuffer
- Parameters:
in
- 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
-
skip
public IoBuffer skip(int size)
Forwards the position of this buffer as the specifiedsize
bytes.
-
fill
public IoBuffer fill(byte value, int size)
Fills this buffer with the specified value. This method moves buffer position forward.
-
fillAndReset
public IoBuffer fillAndReset(byte value, int size)
Fills this buffer with the specified value. This method does not change buffer position.- Specified by:
fillAndReset
in classIoBuffer
- Parameters:
value
- The value to fill the IoBuffer withsize
- The added size- Returns:
- The modified IoBuffer
-
fill
public IoBuffer fill(int size)
Fills this buffer withNUL (0x00)
. This method moves buffer position forward.
-
fillAndReset
public IoBuffer fillAndReset(int size)
Fills this buffer withNUL (0x00)
. This method does not change buffer position.- Specified by:
fillAndReset
in classIoBuffer
- Parameters:
size
- The added size- Returns:
- The modified IoBuffer
-
isAutoExpand
public boolean isAutoExpand()
- Specified by:
isAutoExpand
in classIoBuffer
- Returns:
true
if and only ifautoExpand
is turned on.
-
setAutoExpand
public IoBuffer setAutoExpand(boolean autoExpand)
Turns on or offautoExpand
.- Specified by:
setAutoExpand
in classIoBuffer
- Parameters:
autoExpand
- The flag value to set- Returns:
- The modified IoBuffer instance
-
expand
public IoBuffer expand(int pos, int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemaining
room from the specifiedposition
. This method works even if you didn't setautoExpand
totrue
. 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
public IoBuffer expand(int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the specifiedexpectedRemaining
room from the current position. This method works even if you didn't setautoExpand
totrue
.
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.
-
getObject
public Object getObject() throws ClassNotFoundException
Reads a Java object from the buffer using the contextClassLoader
of the current thread.- Specified by:
getObject
in classIoBuffer
- Returns:
- The read Object
- Throws:
ClassNotFoundException
- thrown when we can't find the Class to use
-
getObject
public Object getObject(ClassLoader classLoader) throws ClassNotFoundException
Reads a Java object from the buffer using the specifiedclassLoader
.- Specified by:
getObject
in 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
-
asInputStream
public InputStream asInputStream()
- Specified by:
asInputStream
in classIoBuffer
- Returns:
- an
InputStream
that reads the data from this buffer.InputStream.read()
returns-1
if the buffer position reaches to the limit.
-
asOutputStream
public OutputStream asOutputStream()
- Specified by:
asOutputStream
in classIoBuffer
- Returns:
- an
OutputStream
that appends the data into this buffer. Please note that theOutputStream.write(int)
will throw aBufferOverflowException
instead of anIOException
in case of buffer overflow. Please setautoExpand
property by callingIoBuffer.setAutoExpand(boolean)
to prevent the unexpected runtime exception.
-
duplicate
public IoBuffer duplicate()
- Specified by:
duplicate
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.duplicate()
-
slice
public IoBuffer slice()
- Specified by:
slice
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.slice()
-
asReadOnlyBuffer
public IoBuffer asReadOnlyBuffer()
- Specified by:
asReadOnlyBuffer
in classIoBuffer
- Returns:
- the modified IoBuffer
- See Also:
ByteBuffer.asReadOnlyBuffer()
-
array
public byte[] array()
- Specified by:
array
in classIoBuffer
- Returns:
- A byte[] if this IoBuffer supports it
- See Also:
ByteBuffer.array()
-
arrayOffset
public int arrayOffset()
- Specified by:
arrayOffset
in classIoBuffer
- Returns:
- The offset in the returned byte[] when the
IoBuffer.array()
method is called - See Also:
ByteBuffer.arrayOffset()
-
minimumCapacity
public int minimumCapacity()
- Specified by:
minimumCapacity
in 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
public IoBuffer minimumCapacity(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. The default value is the initial capacity of the buffer.- Specified by:
minimumCapacity
in classIoBuffer
- Parameters:
minimumCapacity
- the wanted minimum capacity- Returns:
- the underlying NIO
ByteBuffer
instance.
-
capacity
public IoBuffer capacity(int newCapacity)
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:
capacity
in classIoBuffer
- Parameters:
newCapacity
- the wanted capacity- Returns:
- the underlying NIO
ByteBuffer
instance.
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in classIoBuffer
- Returns:
true
if the buffer is readOnly- See Also:
Buffer.isReadOnly()
-
markValue
public int markValue()
-
hasArray
public boolean hasArray()
- Specified by:
hasArray
in classIoBuffer
- Returns:
true
if theIoBuffer.array()
method will return a byte[]- See Also:
ByteBuffer.hasArray()
-
free
public void free()
Declares this buffer and all its derived buffers are not used anymore so that it can be reused by someIoBufferAllocator
implementations. It is not mandatory to call this method, but you might want to invoke this method for maximum performance.
-
isDerived
public boolean isDerived()
- Specified by:
isDerived
in classIoBuffer
- Returns:
true
if and only if this buffer is derived from another buffer via one of theIoBuffer.duplicate()
,IoBuffer.slice()
orIoBuffer.asReadOnlyBuffer()
methods.
-
isAutoShrink
public boolean isAutoShrink()
- Specified by:
isAutoShrink
in classIoBuffer
- Returns:
true
if and only ifautoShrink
is turned on.
-
setAutoShrink
public IoBuffer setAutoShrink(boolean autoShrink)
Turns on or offautoShrink
.- Specified by:
setAutoShrink
in classIoBuffer
- Parameters:
autoShrink
- The flag value to set- Returns:
- The modified IoBuffer instance
-
shrink
public IoBuffer 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
-
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:
getMediumInt
in 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:
getUnsignedMediumInt
in 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:
getMediumInt
in 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:
getUnsignedMediumInt
in classIoBuffer
- Parameters:
index
- The index from which the unsigned medium int will be read- Returns:
- The unsigned medium int value at the given index
-
putMediumInt
public IoBuffer putMediumInt(int value)
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:
putMediumInt
in classIoBuffer
- Parameters:
value
- The medium int value to be written- Returns:
- the modified IoBuffer
-
putMediumInt
public IoBuffer putMediumInt(int index, int value)
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:
putMediumInt
in classIoBuffer
- Parameters:
index
- The index at which the bytes will be writtenvalue
- The medium int value to be written- Returns:
- the modified IoBuffer
-
prefixedDataAvailable
public boolean prefixedDataAvailable(int prefixLength)
- Specified by:
prefixedDataAvailable
in classIoBuffer
- Parameters:
prefixLength
- the length of the prefix field (1, 2, or 4)- Returns:
true
if 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:
prefixedDataAvailable
in classIoBuffer
- Parameters:
prefixLength
- the length of the prefix field (1, 2, or 4)maxDataLength
- the allowed maximum of the read data length- Returns:
true
if 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
public int indexOf(byte b)
Returns the first occurrence position of the specified byte from the current position to the current limit.
-
getEnum
public <E extends Enum<E>> E getEnum(Class<E> enumClass)
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.
-
getEnum
public <E extends Enum<E>> E getEnum(int index, Class<E> enumClass)
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.
-
getEnumShort
public <E extends Enum<E>> E getEnumShort(Class<E> enumClass)
Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumShort
in classIoBuffer
- Type Parameters:
E
- The enum type to return- Parameters:
enumClass
- The enum's class object- Returns:
- The correlated enum constant
-
getEnumShort
public <E extends Enum<E>> E getEnumShort(int index, Class<E> enumClass)
Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumShort
in 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
public <E extends Enum<E>> E getEnumInt(Class<E> enumClass)
Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumInt
in classIoBuffer
- Type Parameters:
E
- The enum type to return- Parameters:
enumClass
- The enum's class object- Returns:
- The correlated enum constant
-
getEnumInt
public <E extends Enum<E>> E getEnumInt(int index, Class<E> enumClass)
Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumInt
in 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
public IoBuffer putEnum(int index, Enum<?> e)
Writes an enum's ordinal value to the buffer as a byte.
-
putEnumShort
public IoBuffer putEnumShort(Enum<?> e)
Writes an enum's ordinal value to the buffer as a short.- Specified by:
putEnumShort
in classIoBuffer
- Parameters:
e
- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
putEnumShort
public IoBuffer putEnumShort(int index, Enum<?> e)
Description copied from class:IoBuffer
Writes an enum's ordinal value to the buffer as a short.- Specified by:
putEnumShort
in classIoBuffer
- Parameters:
index
- The index at which the bytes will be writtene
- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
putEnumInt
public IoBuffer putEnumInt(Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.- Specified by:
putEnumInt
in classIoBuffer
- Parameters:
e
- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
putEnumInt
public IoBuffer putEnumInt(int index, Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.- Specified by:
putEnumInt
in classIoBuffer
- Parameters:
index
- The index at which the bytes will be writtene
- The enum to write to the buffer- Returns:
- The modified IoBuffer
-
getEnumSet
public <E extends Enum<E>> Set<E> getEnumSet(Class<E> enumClass)
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:
getEnumSet
in 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
public <E extends Enum<E>> Set<E> getEnumSet(int index, Class<E> enumClass)
Reads a byte sized bit vector and converts it to anEnumSet
.- Specified by:
getEnumSet
in 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:
IoBuffer.getEnumSet(Class)
-
getEnumSetShort
public <E extends Enum<E>> Set<E> getEnumSetShort(Class<E> enumClass)
Reads a short sized bit vector and converts it to anEnumSet
.- Specified by:
getEnumSetShort
in 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:
IoBuffer.getEnumSet(Class)
-
getEnumSetShort
public <E extends Enum<E>> Set<E> getEnumSetShort(int index, Class<E> enumClass)
Reads a short sized bit vector and converts it to anEnumSet
.- Specified by:
getEnumSetShort
in 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:
IoBuffer.getEnumSet(Class)
-
getEnumSetInt
public <E extends Enum<E>> Set<E> getEnumSetInt(Class<E> enumClass)
Reads an int sized bit vector and converts it to anEnumSet
.- Specified by:
getEnumSetInt
in 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:
IoBuffer.getEnumSet(Class)
-
getEnumSetInt
public <E extends Enum<E>> Set<E> getEnumSetInt(int index, Class<E> enumClass)
Reads an int sized bit vector and converts it to anEnumSet
.- Specified by:
getEnumSetInt
in 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:
IoBuffer.getEnumSet(Class)
-
getEnumSetLong
public <E extends Enum<E>> Set<E> getEnumSetLong(Class<E> enumClass)
Reads a long sized bit vector and converts it to anEnumSet
.- Specified by:
getEnumSetLong
in 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:
IoBuffer.getEnumSet(Class)
-
getEnumSetLong
public <E extends Enum<E>> Set<E> getEnumSetLong(int index, Class<E> enumClass)
Reads a long sized bit vector and converts it to anEnumSet
.- Specified by:
getEnumSetLong
in 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:
IoBuffer.getEnumSet(Class)
-
putEnumSet
public <E extends Enum<E>> IoBuffer putEnumSet(Set<E> set)
Writes the specifiedSet
to the buffer as a byte sized bit vector.- Specified by:
putEnumSet
in classIoBuffer
- Type Parameters:
E
- the enum type of the Set- Parameters:
set
- the enum set to write to the buffer- Returns:
- the modified IoBuffer
-
putEnumSet
public <E extends Enum<E>> IoBuffer putEnumSet(int index, Set<E> set)
Writes the specifiedSet
to the buffer as a byte sized bit vector.- Specified by:
putEnumSet
in 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
public <E extends Enum<E>> IoBuffer putEnumSetShort(Set<E> set)
Writes the specifiedSet
to the buffer as a short sized bit vector.- Specified by:
putEnumSetShort
in 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
public <E extends Enum<E>> IoBuffer putEnumSetShort(int index, Set<E> set)
Writes the specifiedSet
to the buffer as a short sized bit vector.- Specified by:
putEnumSetShort
in 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
public <E extends Enum<E>> IoBuffer putEnumSetInt(Set<E> set)
Writes the specifiedSet
to the buffer as an int sized bit vector.- Specified by:
putEnumSetInt
in 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
public <E extends Enum<E>> IoBuffer putEnumSetInt(int index, Set<E> set)
Writes the specifiedSet
to the buffer as an int sized bit vector.- Specified by:
putEnumSetInt
in 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
public <E extends Enum<E>> IoBuffer putEnumSetLong(Set<E> set)
Writes the specifiedSet
to the buffer as a long sized bit vector.- Specified by:
putEnumSetLong
in 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
public <E extends Enum<E>> IoBuffer putEnumSetLong(int index, Set<E> set)
Writes the specifiedSet
to the buffer as a long sized bit vector.- Specified by:
putEnumSetLong
in 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
-
putUnsigned
public IoBuffer putUnsigned(byte value)
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
value
- the byte to write- Returns:
- the modified IoBuffer
-
putUnsigned
public IoBuffer putUnsigned(int index, byte value)
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the byte to write- Returns:
- the modified IoBuffer
-
putUnsigned
public IoBuffer putUnsigned(short value)
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
value
- the short to write- Returns:
- the modified IoBuffer
-
putUnsigned
public IoBuffer putUnsigned(int index, short value)
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the short to write- Returns:
- the modified IoBuffer
-
putUnsigned
public IoBuffer putUnsigned(int value)
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
value
- the int to write- Returns:
- the modified IoBuffer
-
putUnsigned
public IoBuffer putUnsigned(int index, int value)
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the int to write- Returns:
- the modified IoBuffer
-
putUnsigned
public IoBuffer putUnsigned(long value)
Writes an unsigned byte into the ByteBuffer- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
value
- the long to write- Returns:
- the modified IoBuffer
-
putUnsigned
public IoBuffer putUnsigned(int index, long value)
Writes an unsigned byte into the ByteBuffer at a specified position- Specified by:
putUnsigned
in classIoBuffer
- Parameters:
index
- the position in the buffer to write the valuevalue
- the long to write- Returns:
- the modified IoBuffer
-
-