public abstract class AbstractIoBuffer extends IoBuffer
IoBuffer
. This implementation
assumes that IoBuffer.buf()
always returns a correct NIO
ByteBuffer
instance. Most implementations could
extend this class and implement their own buffer management mechanism.IoBufferAllocator
Modifier | Constructor and Description |
---|---|
protected |
AbstractIoBuffer(AbstractIoBuffer parent)
Creates a new derived buffer.
|
protected |
AbstractIoBuffer(IoBufferAllocator allocator,
int initialCapacity)
Creates a new parent buffer.
|
Modifier and Type | Method and Description |
---|---|
CharBuffer |
asCharBuffer() |
DoubleBuffer |
asDoubleBuffer() |
FloatBuffer |
asFloatBuffer() |
InputStream |
asInputStream() |
IntBuffer |
asIntBuffer() |
LongBuffer |
asLongBuffer() |
OutputStream |
asOutputStream() |
IoBuffer |
asReadOnlyBuffer() |
protected abstract IoBuffer |
asReadOnlyBuffer0()
Implement this method to return the unexpandable read only version of
this buffer.
|
ShortBuffer |
asShortBuffer() |
protected abstract void |
buf(ByteBuffer newBuf)
Sets the underlying NIO buffer instance.
|
int |
capacity() |
IoBuffer |
capacity(int newCapacity)
Increases the capacity of this buffer.
|
IoBuffer |
clear() |
IoBuffer |
compact() |
int |
compareTo(IoBuffer that) |
IoBuffer |
duplicate() |
protected abstract IoBuffer |
duplicate0()
Implement this method to return the unexpandable duplicate of this
buffer.
|
boolean |
equals(Object o) |
IoBuffer |
expand(int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the
specified expectedRemaining room from the current position.
|
IoBuffer |
expand(int pos,
int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get the
specified expectedRemaining room from the specified
position.
|
IoBuffer |
fill(byte value,
int size)
Fills this buffer with the specified value.
|
IoBuffer |
fill(int size)
Fills this buffer with
NUL (0x00) . |
IoBuffer |
fillAndReset(byte value,
int size)
Fills this buffer with the specified value.
|
IoBuffer |
fillAndReset(int size)
Fills this buffer with
NUL (0x00) . |
IoBuffer |
flip() |
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>> |
getEnum(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>> |
getEnum(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>> |
getEnumInt(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>> |
getEnumInt(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>> |
getEnumSet(Class<E> enumClass)
Reads a byte sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumSet(int index,
Class<E> enumClass)
Reads a byte sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumSetInt(Class<E> enumClass)
Reads an int sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumSetInt(int index,
Class<E> enumClass)
Reads an int sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumSetLong(Class<E> enumClass)
Reads a long sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumSetLong(int index,
Class<E> enumClass)
Reads a long sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumSetShort(Class<E> enumClass)
Reads a short sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumSetShort(int index,
Class<E> enumClass)
Reads a short sized bit vector and converts it to an
EnumSet . |
<E extends Enum<E>> |
getEnumShort(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>> |
getEnumShort(int index,
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) |
String |
getHexDump()
Returns hexdump of this buffer.
|
String |
getHexDump(int lengthLimit)
Return hexdump of this buffer with limited length.
|
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 context
ClassLoader
of the current thread. |
Object |
getObject(ClassLoader classLoader)
Reads a Java object from the buffer using the specified
classLoader.
|
String |
getPrefixedString(CharsetDecoder decoder)
Reads a string which has a 16-bit length field before the actual encoded
string, using the specified
decoder and returns it. |
String |
getPrefixedString(int prefixLength,
CharsetDecoder decoder)
Reads a string which has a length field before the actual
encoded string, using the specified
decoder and returns it. |
short |
getShort() |
short |
getShort(int index) |
IoBuffer |
getSlice(int length)
Get a new IoBuffer containing a slice of the current buffer
|
IoBuffer |
getSlice(int index,
int length)
Get a new IoBuffer containing a slice of the current buffer
|
String |
getString(CharsetDecoder decoder)
Reads a
NUL -terminated string from this buffer using the
specified decoder and returns it. |
String |
getString(int fieldSize,
CharsetDecoder decoder)
Reads a
NUL -terminated string from this buffer using the
specified decoder 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.
|
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 by
IoBuffer.compact() and
IoBuffer.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(ByteBuffer src)
Writes the content of the specified src into this buffer.
|
IoBuffer |
put(int index,
byte b) |
IoBuffer |
put(IoBuffer src)
Writes the content of the specified src 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(Enum<?> e)
Writes an enum's ordinal value to the buffer as a byte.
|
IoBuffer |
putEnum(int index,
Enum<?> e)
Writes an enum's ordinal value to the buffer as a byte.
|
IoBuffer |
putEnumInt(Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.
|
IoBuffer |
putEnumInt(int index,
Enum<?> e)
Writes an enum's ordinal value to the buffer as an integer.
|
<E extends Enum<E>> |
putEnumSet(int index,
Set<E> set)
Writes the specified
Set to the buffer as a byte sized bit
vector. |
<E extends Enum<E>> |
putEnumSet(Set<E> set)
Writes the specified
Set to the buffer as a byte sized bit
vector. |
<E extends Enum<E>> |
putEnumSetInt(int index,
Set<E> set)
Writes the specified
Set to the buffer as an int sized bit
vector. |
<E extends Enum<E>> |
putEnumSetInt(Set<E> set)
Writes the specified
Set to the buffer as an int sized bit
vector. |
<E extends Enum<E>> |
putEnumSetLong(int index,
Set<E> set)
Writes the specified
Set to the buffer as a long sized bit
vector. |
<E extends Enum<E>> |
putEnumSetLong(Set<E> set)
Writes the specified
Set to the buffer as a long sized bit
vector. |
<E extends Enum<E>> |
putEnumSetShort(int index,
Set<E> set)
Writes the specified
Set to the buffer as a short sized bit
vector. |
<E extends Enum<E>> |
putEnumSetShort(Set<E> set)
Writes the specified
Set to the buffer as a short sized bit
vector. |
IoBuffer |
putEnumShort(Enum<?> e)
Writes an enum's ordinal value to the buffer as a short.
|
IoBuffer |
putEnumShort(int index,
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,
CharsetEncoder encoder)
Writes the content of
in into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder . |
IoBuffer |
putPrefixedString(CharSequence in,
int prefixLength,
CharsetEncoder encoder)
Writes the content of
in into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder . |
IoBuffer |
putPrefixedString(CharSequence val,
int prefixLength,
int padding,
byte padValue,
CharsetEncoder encoder)
Writes the content of
val into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder . |
IoBuffer |
putPrefixedString(CharSequence in,
int prefixLength,
int padding,
CharsetEncoder encoder)
Writes the content of
in into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder . |
IoBuffer |
putShort(int index,
short value) |
IoBuffer |
putShort(short value) |
IoBuffer |
putString(CharSequence val,
CharsetEncoder encoder)
Writes the content of
in into this buffer using the
specified encoder . |
IoBuffer |
putString(CharSequence val,
int fieldSize,
CharsetEncoder encoder)
Writes the content of
in into this buffer as a
NUL -terminated string using the specified
encoder . |
IoBuffer |
putUnsigned(byte value)
Writes an unsigned byte into the ByteBuffer
|
IoBuffer |
putUnsigned(int value)
Writes an unsigned byte into the ByteBuffer
|
IoBuffer |
putUnsigned(int index,
byte value)
Writes an unsigned byte into the ByteBuffer at a specified position
|
IoBuffer |
putUnsigned(int index,
int value)
Writes an unsigned byte into the ByteBuffer at a specified position
|
IoBuffer |
putUnsigned(int index,
long value)
Writes an unsigned byte into the ByteBuffer at a specified position
|
IoBuffer |
putUnsigned(int index,
short value)
Writes an unsigned byte into the ByteBuffer at a specified position
|
IoBuffer |
putUnsigned(long value)
Writes an unsigned byte into the ByteBuffer
|
IoBuffer |
putUnsigned(short value)
Writes an unsigned byte into the ByteBuffer
|
IoBuffer |
putUnsignedInt(byte value)
Writes an unsigned int into the ByteBuffer
|
IoBuffer |
putUnsignedInt(int value)
Writes an unsigned int into the ByteBuffer
|
IoBuffer |
putUnsignedInt(int index,
byte value)
Writes an unsigned int into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedInt(int index,
int value)
Writes an unsigned int into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedInt(int index,
long value)
Writes an unsigned int into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedInt(int index,
short value)
Writes an unsigned int into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedInt(long value)
Writes an unsigned int into the ByteBuffer
|
IoBuffer |
putUnsignedInt(short value)
Writes an unsigned int into the ByteBuffer
|
IoBuffer |
putUnsignedShort(byte value)
Writes an unsigned short into the ByteBuffer
|
IoBuffer |
putUnsignedShort(int value)
Writes an unsigned Short into the ByteBuffer
|
IoBuffer |
putUnsignedShort(int index,
byte value)
Writes an unsigned Short into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedShort(int index,
int value)
Writes an unsigned Short into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedShort(int index,
long value)
Writes an unsigned Short into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedShort(int index,
short value)
Writes an unsigned Short into the ByteBuffer at a specified position
|
IoBuffer |
putUnsignedShort(long value)
Writes an unsigned Short into the ByteBuffer
|
IoBuffer |
putUnsignedShort(short value)
Writes an unsigned Short into the ByteBuffer
|
int |
remaining() |
IoBuffer |
reset() |
IoBuffer |
rewind() |
IoBuffer |
setAutoExpand(boolean autoExpand)
Turns on or off autoExpand.
|
IoBuffer |
setAutoShrink(boolean autoShrink)
Turns on or off autoShrink.
|
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 specified
size
bytes. |
IoBuffer |
slice() |
protected abstract IoBuffer |
slice0()
Implement this method to return the unexpandable slice of this
buffer.
|
IoBuffer |
sweep()
Clears this buffer and fills its content with NUL.
|
IoBuffer |
sweep(byte value)
double Clears this buffer and fills its content with value.
|
String |
toString() |
allocate, allocate, array, arrayOffset, buf, free, getAllocator, hasArray, isUseDirectBuffer, normalizeCapacity, setAllocator, setUseDirectBuffer, wrap, wrap, wrap
protected AbstractIoBuffer(IoBufferAllocator allocator, int initialCapacity)
allocator
- The allocator to use to create new buffersinitialCapacity
- The initial buffer capacity when createdprotected AbstractIoBuffer(AbstractIoBuffer parent)
parent
- The buffer we get the properties frompublic final boolean isDirect()
isDirect
in class IoBuffer
ByteBuffer.isDirect()
public final boolean isReadOnly()
isReadOnly
in class IoBuffer
Buffer.isReadOnly()
protected abstract void buf(ByteBuffer newBuf)
newBuf
- The buffer to store within this IoBufferpublic final int minimumCapacity()
minimumCapacity
in class IoBuffer
IoBuffer.compact()
and
IoBuffer.shrink()
operation. The default value is the initial capacity of
the buffer.public final IoBuffer minimumCapacity(int minimumCapacity)
IoBuffer.compact()
and
IoBuffer.shrink()
operation. The default value is the initial capacity of
the buffer.minimumCapacity
in class IoBuffer
minimumCapacity
- the wanted minimum capacityByteBuffer
instance.public final int capacity()
capacity
in class IoBuffer
Buffer.capacity()
public final IoBuffer capacity(int newCapacity)
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.
capacity
in class IoBuffer
newCapacity
- the wanted capacityByteBuffer
instance.public final boolean isAutoExpand()
isAutoExpand
in class IoBuffer
public final boolean isAutoShrink()
isAutoShrink
in class IoBuffer
public final boolean isDerived()
isDerived
in class IoBuffer
IoBuffer.duplicate()
, IoBuffer.slice()
or
IoBuffer.asReadOnlyBuffer()
methods.public final IoBuffer setAutoExpand(boolean autoExpand)
setAutoExpand
in class IoBuffer
autoExpand
- The flag value to setpublic final IoBuffer setAutoShrink(boolean autoShrink)
setAutoShrink
in class IoBuffer
autoShrink
- The flag value to setpublic final IoBuffer expand(int expectedRemaining)
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.
public final IoBuffer expand(int pos, int expectedRemaining)
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.
public final IoBuffer shrink()
IoBuffer.minimumCapacity()
IoBuffer.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
public final int position()
position
in class IoBuffer
Buffer.position()
public final IoBuffer position(int newPosition)
position
in class IoBuffer
newPosition
- Sets the new position in the bufferBuffer.position(int)
public final int limit()
limit
in class IoBuffer
Buffer.limit()
public final IoBuffer limit(int newLimit)
limit
in class IoBuffer
newLimit
- The new buffer's limitBuffer.limit(int)
public final IoBuffer mark()
mark
in class IoBuffer
Buffer.mark()
public final int markValue()
public final IoBuffer reset()
reset
in class IoBuffer
Buffer.reset()
public final IoBuffer clear()
clear
in class IoBuffer
Buffer.clear()
public final IoBuffer sweep()
public final IoBuffer sweep(byte value)
public final IoBuffer flip()
flip
in class IoBuffer
Buffer.flip()
public final IoBuffer rewind()
rewind
in class IoBuffer
Buffer.rewind()
public final int remaining()
remaining
in class IoBuffer
Buffer.remaining()
public final boolean hasRemaining()
hasRemaining
in class IoBuffer
Buffer.hasRemaining()
public final byte get()
get
in class IoBuffer
ByteBuffer.get()
public final short getUnsigned()
getUnsigned
in class IoBuffer
public final IoBuffer put(byte b)
put
in class IoBuffer
b
- The byte to put in the bufferByteBuffer.put(byte)
public IoBuffer putUnsigned(byte value)
putUnsigned
in class IoBuffer
value
- the byte to writepublic IoBuffer putUnsigned(int index, byte value)
putUnsigned
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the byte to writepublic IoBuffer putUnsigned(short value)
putUnsigned
in class IoBuffer
value
- the short to writepublic IoBuffer putUnsigned(int index, short value)
putUnsigned
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the short to writepublic IoBuffer putUnsigned(int value)
putUnsigned
in class IoBuffer
value
- the int to writepublic IoBuffer putUnsigned(int index, int value)
putUnsigned
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the int to writepublic IoBuffer putUnsigned(long value)
putUnsigned
in class IoBuffer
value
- the long to writepublic IoBuffer putUnsigned(int index, long value)
putUnsigned
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the long to writepublic final byte get(int index)
get
in class IoBuffer
index
- The position for which we want to read a byteByteBuffer.get(int)
public final short getUnsigned(int index)
getUnsigned
in class IoBuffer
index
- The position for which we want to read an unsigned bytepublic final IoBuffer put(int index, byte b)
put
in class IoBuffer
index
- The position where the byte will be putb
- The byte to putByteBuffer.put(int, byte)
public final IoBuffer get(byte[] dst, int offset, int length)
get
in class IoBuffer
dst
- The destination bufferoffset
- The position in the original bufferlength
- The number of bytes to copyByteBuffer.get(byte[], int, int)
public final IoBuffer put(ByteBuffer src)
public final IoBuffer put(byte[] src, int offset, int length)
put
in class IoBuffer
src
- The byte[] to putoffset
- The position in the sourcelength
- The number of bytes to copyByteBuffer.put(byte[], int, int)
public final IoBuffer compact()
compact
in class IoBuffer
ByteBuffer.compact()
public final ByteOrder order()
order
in class IoBuffer
ByteBuffer.order()
public final IoBuffer order(ByteOrder bo)
order
in class IoBuffer
bo
- The new ByteBuffer to use for this IoBufferByteBuffer.order(ByteOrder)
public final char getChar()
getChar
in class IoBuffer
ByteBuffer.getChar()
public final IoBuffer putChar(char value)
putChar
in class IoBuffer
value
- The char to put at the current positionByteBuffer.putChar(char)
public final char getChar(int index)
getChar
in class IoBuffer
index
- The index in the IoBuffer where we will read a char fromByteBuffer.getChar(int)
public final IoBuffer putChar(int index, char value)
putChar
in class IoBuffer
index
- The index in the IoBuffer where we will put a char invalue
- The char to put at the current positionByteBuffer.putChar(int, char)
public final CharBuffer asCharBuffer()
asCharBuffer
in class IoBuffer
ByteBuffer.asCharBuffer()
public final short getShort()
getShort
in class IoBuffer
ByteBuffer.getShort()
public final IoBuffer putShort(short value)
putShort
in class IoBuffer
value
- The short to put at the current positionByteBuffer.putShort(short)
public final short getShort(int index)
getShort
in class IoBuffer
index
- The index in the IoBuffer where we will read a short fromByteBuffer.getShort()
public final IoBuffer putShort(int index, short value)
putShort
in class IoBuffer
index
- The position at which the short should be writtenvalue
- The short to put at the current positionByteBuffer.putShort(int, short)
public final ShortBuffer asShortBuffer()
asShortBuffer
in class IoBuffer
ByteBuffer.asShortBuffer()
public final int getInt()
getInt
in class IoBuffer
ByteBuffer.getInt()
public final IoBuffer putInt(int value)
putInt
in class IoBuffer
value
- The int to put at the current positionByteBuffer.putInt(int)
public final IoBuffer putUnsignedInt(byte value)
putUnsignedInt
in class IoBuffer
value
- the byte to writepublic final IoBuffer putUnsignedInt(int index, byte value)
putUnsignedInt
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the byte to writepublic final IoBuffer putUnsignedInt(short value)
putUnsignedInt
in class IoBuffer
value
- the short to writepublic final IoBuffer putUnsignedInt(int index, short value)
putUnsignedInt
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the short to writepublic final IoBuffer putUnsignedInt(int value)
putUnsignedInt
in class IoBuffer
value
- the int to writepublic final IoBuffer putUnsignedInt(int index, int value)
putUnsignedInt
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the int to writepublic final IoBuffer putUnsignedInt(long value)
putUnsignedInt
in class IoBuffer
value
- the long to writepublic final IoBuffer putUnsignedInt(int index, long value)
putUnsignedInt
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the long to writepublic final IoBuffer putUnsignedShort(byte value)
putUnsignedShort
in class IoBuffer
value
- the byte to writepublic final IoBuffer putUnsignedShort(int index, byte value)
putUnsignedShort
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the byte to writepublic final IoBuffer putUnsignedShort(short value)
putUnsignedShort
in class IoBuffer
value
- the short to writepublic final IoBuffer putUnsignedShort(int index, short value)
putUnsignedShort
in class IoBuffer
index
- the position in the buffer to write the unsigned shortvalue
- the unsigned short to writepublic final IoBuffer putUnsignedShort(int value)
putUnsignedShort
in class IoBuffer
value
- the int to writepublic final IoBuffer putUnsignedShort(int index, int value)
putUnsignedShort
in class IoBuffer
index
- the position in the buffer to write the valuevalue
- the int to writepublic final IoBuffer putUnsignedShort(long value)
putUnsignedShort
in class IoBuffer
value
- the long to writepublic final IoBuffer putUnsignedShort(int index, long value)
putUnsignedShort
in class IoBuffer
index
- the position in the buffer to write the shortvalue
- the long to writepublic final int getInt(int index)
getInt
in class IoBuffer
index
- The index in the IoBuffer where we will read an int fromByteBuffer.getInt(int)
public final IoBuffer putInt(int index, int value)
putInt
in class IoBuffer
index
- The position where to put the intvalue
- The int to put in the IoBufferByteBuffer.putInt(int, int)
public final IntBuffer asIntBuffer()
asIntBuffer
in class IoBuffer
ByteBuffer.asIntBuffer()
public final long getLong()
getLong
in class IoBuffer
ByteBuffer.getLong()
public final IoBuffer putLong(long value)
putLong
in class IoBuffer
value
- The log to put in the IoBufferByteBuffer.putLong(int, long)
public final long getLong(int index)
getLong
in class IoBuffer
index
- The index in the IoBuffer where we will read a long fromByteBuffer.getLong(int)
public final IoBuffer putLong(int index, long value)
putLong
in class IoBuffer
index
- The position where to put the longvalue
- The long to put in the IoBufferByteBuffer.putLong(int, long)
public final LongBuffer asLongBuffer()
asLongBuffer
in class IoBuffer
ByteBuffer.asLongBuffer()
public final float getFloat()
getFloat
in class IoBuffer
ByteBuffer.getFloat()
public final IoBuffer putFloat(float value)
putFloat
in class IoBuffer
value
- The float to put in the IoBufferByteBuffer.putFloat(float)
public final float getFloat(int index)
getFloat
in class IoBuffer
index
- The index in the IoBuffer where we will read a float fromByteBuffer.getFloat(int)
public final IoBuffer putFloat(int index, float value)
putFloat
in class IoBuffer
index
- The position where to put the floatvalue
- The float to put in the IoBufferByteBuffer.putFloat(int, float)
public final FloatBuffer asFloatBuffer()
asFloatBuffer
in class IoBuffer
ByteBuffer.asFloatBuffer()
public final double getDouble()
getDouble
in class IoBuffer
ByteBuffer.getDouble()
public final IoBuffer putDouble(double value)
putDouble
in class IoBuffer
value
- The double to put at the IoBuffer current positionByteBuffer.putDouble(double)
public final double getDouble(int index)
getDouble
in class IoBuffer
index
- The position where to get the double fromByteBuffer.getDouble(int)
public final IoBuffer putDouble(int index, double value)
putDouble
in class IoBuffer
index
- The position where to put the doublevalue
- The double to put in the IoBufferByteBuffer.putDouble(int, double)
public final DoubleBuffer asDoubleBuffer()
asDoubleBuffer
in class IoBuffer
ByteBuffer.asDoubleBuffer()
public final IoBuffer asReadOnlyBuffer()
asReadOnlyBuffer
in class IoBuffer
ByteBuffer.asReadOnlyBuffer()
protected abstract IoBuffer asReadOnlyBuffer0()
public final IoBuffer duplicate()
duplicate
in class IoBuffer
ByteBuffer.duplicate()
protected abstract IoBuffer duplicate0()
public final IoBuffer slice()
slice
in class IoBuffer
ByteBuffer.slice()
public final IoBuffer getSlice(int index, int length)
public final IoBuffer getSlice(int length)
protected abstract IoBuffer slice0()
public int compareTo(IoBuffer that)
public IoBuffer get(byte[] dst)
get
in class IoBuffer
dst
- The byte[] that will contain the read bytesByteBuffer.get(byte[])
public IoBuffer put(byte[] src)
put
in class IoBuffer
src
- The byte[] to putByteBuffer.put(byte[])
public int getUnsignedShort()
getUnsignedShort
in class IoBuffer
public int getUnsignedShort(int index)
getUnsignedShort
in class IoBuffer
index
- The index in the IoBuffer where we will read an unsigned short frompublic long getUnsignedInt()
getUnsignedInt
in class IoBuffer
public int getMediumInt()
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.
getMediumInt
in class IoBuffer
public int getUnsignedMediumInt()
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.
getUnsignedMediumInt
in class IoBuffer
public int getMediumInt(int index)
Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order.
getMediumInt
in class IoBuffer
index
- The index from which the medium int will be readpublic int getUnsignedMediumInt(int index)
Reads the next three bytes at this buffer's current position, composing them into an int value according to the current byte order.
getUnsignedMediumInt
in class IoBuffer
index
- The index from which the unsigned medium int will be readpublic IoBuffer putMediumInt(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.
putMediumInt
in class IoBuffer
value
- The medium int value to be writtenpublic IoBuffer putMediumInt(int index, int value)
Writes three bytes containing the given int value, in the current byte order, into this buffer at the given index.
putMediumInt
in class IoBuffer
index
- The index at which the bytes will be writtenvalue
- The medium int value to be writtenpublic long getUnsignedInt(int index)
getUnsignedInt
in class IoBuffer
index
- The index in the IoBuffer where we will read an unsigned int frompublic InputStream asInputStream()
asInputStream
in class IoBuffer
InputStream
that reads the data from this buffer.
InputStream.read()
returns -1 if the buffer position
reaches to the limit.public OutputStream asOutputStream()
asOutputStream
in class IoBuffer
OutputStream
that appends the data into this buffer.
Please note that the OutputStream.write(int)
will throw a
BufferOverflowException
instead of an IOException
in case
of buffer overflow. Please set autoExpand property by calling
IoBuffer.setAutoExpand(boolean)
to prevent the unexpected runtime
exception.public String getHexDump()
getHexDump
in class IoBuffer
public String getHexDump(int lengthLimit)
getHexDump
in class IoBuffer
lengthLimit
- The maximum number of bytes to dump from the current buffer
position.public String getString(CharsetDecoder decoder) throws CharacterCodingException
NUL
-terminated string from this buffer using the
specified decoder
and returns it. This method reads until
the limit of this buffer if no NUL is found.getString
in class IoBuffer
decoder
- The CharsetDecoder
to useCharacterCodingException
- Thrown when an error occurred while decoding the bufferpublic String getString(int fieldSize, CharsetDecoder decoder) throws CharacterCodingException
NUL
-terminated string from this buffer using the
specified decoder
and returns it.getString
in class IoBuffer
fieldSize
- the maximum number of bytes to readdecoder
- The CharsetDecoder
to useCharacterCodingException
- Thrown when an error occurred while decoding the bufferpublic IoBuffer putString(CharSequence val, CharsetEncoder encoder) throws CharacterCodingException
in
into this buffer using the
specified encoder
. This method doesn't terminate string with
NUL. You have to do it by yourself.putString
in class IoBuffer
val
- The CharSequence to put in the IoBufferencoder
- The CharsetEncoder to useCharacterCodingException
- When we have an error while decoding the Stringpublic IoBuffer putString(CharSequence val, int fieldSize, CharsetEncoder encoder) throws CharacterCodingException
in
into this buffer as a
NUL
-terminated string using the specified
encoder
.
If the charset name of the encoder is UTF-16, you cannot specify odd
fieldSize
, and this method will append two NUL
s
as a terminator.
Please note that this method doesn't terminate with NUL
if
the input string is longer than fieldSize.
putString
in class IoBuffer
val
- The CharSequence to put in the IoBufferfieldSize
- the maximum number of bytes to writeencoder
- The CharsetEncoder to useCharacterCodingException
- When we have an error while decoding the Stringpublic String getPrefixedString(CharsetDecoder decoder) throws CharacterCodingException
decoder
and returns it. This
method is a shortcut for getPrefixedString(2, decoder).getPrefixedString
in class IoBuffer
decoder
- The CharsetDecoder to useCharacterCodingException
- When we have an error while decoding the Stringpublic String getPrefixedString(int prefixLength, CharsetDecoder decoder) throws CharacterCodingException
decoder
and returns it.getPrefixedString
in class IoBuffer
prefixLength
- the length of the length field (1, 2, or 4)decoder
- the decoder to use for decoding the stringCharacterCodingException
- when decoding failsBufferUnderflowException
- when there is not enough data availablepublic IoBuffer putPrefixedString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException
in
into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder
. This method is a shortcut for
putPrefixedString(in, 2, 0, encoder).putPrefixedString
in class IoBuffer
in
- The CharSequence to put in the IoBufferencoder
- The CharsetEncoder to useCharacterCodingException
- When we have an error while decoding the CharSequencepublic IoBuffer putPrefixedString(CharSequence in, int prefixLength, CharsetEncoder encoder) throws CharacterCodingException
in
into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder
. This method is a shortcut for
putPrefixedString(in, prefixLength, 0, encoder).putPrefixedString
in class IoBuffer
in
- The CharSequence to put in the IoBufferprefixLength
- the length of the length field (1, 2, or 4)encoder
- The CharsetEncoder to useCharacterCodingException
- When we have an error while decoding the CharSequencepublic IoBuffer putPrefixedString(CharSequence in, int prefixLength, int padding, CharsetEncoder encoder) throws CharacterCodingException
in
into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder
. This method is a shortcut for
putPrefixedString(in, prefixLength, padding, ( byte ) 0, encoder)putPrefixedString
in class IoBuffer
in
- The CharSequence to put in the IoBufferprefixLength
- the length of the length field (1, 2, or 4)padding
- the number of padded NULs (1 (or 0), 2, or 4)encoder
- The CharsetEncoder to useCharacterCodingException
- When we have an error while decoding the CharSequencepublic IoBuffer putPrefixedString(CharSequence val, int prefixLength, int padding, byte padValue, CharsetEncoder encoder) throws CharacterCodingException
val
into this buffer as a string which
has a 16-bit length field before the actual encoded string, using the
specified encoder
.putPrefixedString
in class IoBuffer
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 useCharacterCodingException
- When we have an error while decoding the CharSequencepublic Object getObject() throws ClassNotFoundException
ClassLoader
of the current thread.getObject
in class IoBuffer
ClassNotFoundException
- thrown when we can't find the Class to usepublic Object getObject(ClassLoader classLoader) throws ClassNotFoundException
getObject
in class IoBuffer
classLoader
- The classLoader to use to read an Object from the IoBufferClassNotFoundException
- thrown when we can't find the Class to usepublic boolean prefixedDataAvailable(int prefixLength)
prefixedDataAvailable
in class IoBuffer
prefixLength
- the length of the prefix field (1, 2, or 4)IoBuffer.prefixedDataAvailable(int, int)
instead.public boolean prefixedDataAvailable(int prefixLength, int maxDataLength)
prefixedDataAvailable
in class IoBuffer
prefixLength
- the length of the prefix field (1, 2, or 4)maxDataLength
- the allowed maximum of the read data lengthpublic int indexOf(byte b)
public IoBuffer skip(int size)
size
bytes.public IoBuffer fill(byte value, int size)
public IoBuffer fillAndReset(byte value, int size)
fillAndReset
in class IoBuffer
value
- The value to fill the IoBuffer withsize
- The added sizepublic IoBuffer fill(int size)
NUL (0x00)
. This method moves buffer
position forward.public IoBuffer fillAndReset(int size)
NUL (0x00)
. This method does not
change buffer position.fillAndReset
in class IoBuffer
size
- The added sizepublic <E extends Enum<E>> E getEnum(Class<E> enumClass)
public <E extends Enum<E>> E getEnum(int index, Class<E> enumClass)
public <E extends Enum<E>> E getEnumShort(Class<E> enumClass)
getEnumShort
in class IoBuffer
E
- The enum type to returnenumClass
- The enum's class objectpublic <E extends Enum<E>> E getEnumShort(int index, Class<E> enumClass)
getEnumShort
in class IoBuffer
E
- The enum type to returnindex
- the index from which the bytes will be readenumClass
- The enum's class objectpublic <E extends Enum<E>> E getEnumInt(Class<E> enumClass)
getEnumInt
in class IoBuffer
E
- The enum type to returnenumClass
- The enum's class objectpublic <E extends Enum<E>> E getEnumInt(int index, Class<E> enumClass)
getEnumInt
in class IoBuffer
E
- The enum type to returnindex
- the index from which the bytes will be readenumClass
- The enum's class objectpublic IoBuffer putEnum(int index, Enum<?> e)
public IoBuffer putEnumShort(Enum<?> e)
putEnumShort
in class IoBuffer
e
- The enum to write to the bufferpublic IoBuffer putEnumShort(int index, Enum<?> e)
putEnumShort
in class IoBuffer
index
- The index at which the bytes will be writtene
- The enum to write to the bufferpublic IoBuffer putEnumInt(Enum<?> e)
putEnumInt
in class IoBuffer
e
- The enum to write to the bufferpublic IoBuffer putEnumInt(int index, Enum<?> e)
putEnumInt
in class IoBuffer
index
- The index at which the bytes will be writtene
- The enum to write to the bufferpublic <E extends Enum<E>> Set<E> getEnumSet(Class<E> enumClass)
EnumSet
.
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.
getEnumSet
in class IoBuffer
E
- the enum typeenumClass
- the enum class used to create the EnumSetpublic <E extends Enum<E>> Set<E> getEnumSet(int index, Class<E> enumClass)
EnumSet
.getEnumSet
in class IoBuffer
E
- the enum typeindex
- the index from which the byte will be readenumClass
- the enum class used to create the EnumSetIoBuffer.getEnumSet(Class)
public <E extends Enum<E>> Set<E> getEnumSetShort(Class<E> enumClass)
EnumSet
.getEnumSetShort
in class IoBuffer
E
- the enum typeenumClass
- the enum class used to create the EnumSetIoBuffer.getEnumSet(Class)
public <E extends Enum<E>> Set<E> getEnumSetShort(int index, Class<E> enumClass)
EnumSet
.getEnumSetShort
in class IoBuffer
E
- the enum typeindex
- the index from which the bytes will be readenumClass
- the enum class used to create the EnumSetIoBuffer.getEnumSet(Class)
public <E extends Enum<E>> Set<E> getEnumSetInt(Class<E> enumClass)
EnumSet
.getEnumSetInt
in class IoBuffer
E
- the enum typeenumClass
- the enum class used to create the EnumSetIoBuffer.getEnumSet(Class)
public <E extends Enum<E>> Set<E> getEnumSetInt(int index, Class<E> enumClass)
EnumSet
.getEnumSetInt
in class IoBuffer
E
- the enum typeindex
- the index from which the bytes will be readenumClass
- the enum class used to create the EnumSetIoBuffer.getEnumSet(Class)
public <E extends Enum<E>> Set<E> getEnumSetLong(Class<E> enumClass)
EnumSet
.getEnumSetLong
in class IoBuffer
E
- the enum typeenumClass
- the enum class used to create the EnumSetIoBuffer.getEnumSet(Class)
public <E extends Enum<E>> Set<E> getEnumSetLong(int index, Class<E> enumClass)
EnumSet
.getEnumSetLong
in class IoBuffer
E
- the enum typeindex
- the index from which the bytes will be readenumClass
- the enum class used to create the EnumSetIoBuffer.getEnumSet(Class)
public <E extends Enum<E>> IoBuffer putEnumSet(Set<E> set)
Set
to the buffer as a byte sized bit
vector.putEnumSet
in class IoBuffer
E
- the enum type of the Setset
- the enum set to write to the bufferpublic <E extends Enum<E>> IoBuffer putEnumSet(int index, Set<E> set)
Set
to the buffer as a byte sized bit
vector.putEnumSet
in class IoBuffer
E
- the enum type of the Setindex
- the index at which the byte will be writtenset
- the enum set to write to the bufferpublic <E extends Enum<E>> IoBuffer putEnumSetShort(Set<E> set)
Set
to the buffer as a short sized bit
vector.putEnumSetShort
in class IoBuffer
E
- the enum type of the Setset
- the enum set to write to the bufferpublic <E extends Enum<E>> IoBuffer putEnumSetShort(int index, Set<E> set)
Set
to the buffer as a short sized bit
vector.putEnumSetShort
in class IoBuffer
E
- the enum type of the Setindex
- the index at which the bytes will be writtenset
- the enum set to write to the bufferpublic <E extends Enum<E>> IoBuffer putEnumSetInt(Set<E> set)
Set
to the buffer as an int sized bit
vector.putEnumSetInt
in class IoBuffer
E
- the enum type of the Setset
- the enum set to write to the bufferpublic <E extends Enum<E>> IoBuffer putEnumSetInt(int index, Set<E> set)
Set
to the buffer as an int sized bit
vector.putEnumSetInt
in class IoBuffer
E
- the enum type of the Setindex
- the index at which the bytes will be writtenset
- the enum set to write to the bufferpublic <E extends Enum<E>> IoBuffer putEnumSetLong(Set<E> set)
Set
to the buffer as a long sized bit
vector.putEnumSetLong
in class IoBuffer
E
- the enum type of the Setset
- the enum set to write to the bufferpublic <E extends Enum<E>> IoBuffer putEnumSetLong(int index, Set<E> set)
Set
to the buffer as a long sized bit
vector.putEnumSetLong
in class IoBuffer
E
- the enum type of the Setindex
- the index at which the bytes will be writtenset
- the enum set to write to the bufferCopyright © 2004–2018 Apache MINA Project. All rights reserved.