Class AbstractIoBuffer
- All Implemented Interfaces:
Comparable<IoBuffer>
- Direct Known Subclasses:
CachedBufferAllocator.CachedBuffer
,SimpleBufferAllocator.SimpleBuffer
IoBuffer
. This implementation assumes that
IoBuffer.buf()
always returns a correct NIO ByteBuffer
instance. Most
implementations could extend this class and implement their own buffer management mechanism.- Version:
- $Rev: 748210 $, $Date: 2009-02-26 18:05:40 +0100 (Thu, 26 Feb 2009) $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
A flag set to true if the buffer can extend automaticallyprivate boolean
A flag set to true if the buffer can shrink automaticallyprivate static final long
A mask for a byteprivate final boolean
Tells if a buffer has been created from an existing bufferprivate static final long
A mask for an intprivate int
We don't have any access to Buffer.markValue(), so we need to track it down, which will cause small extra overhead.private int
The minimum number of bytes the IoBuffer can holdprivate boolean
Tells if a buffer can be expandedprivate static final long
A mask for a short -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractIoBuffer
(AbstractIoBuffer parent) Creates a new derived buffer.protected
AbstractIoBuffer
(IoBufferAllocator allocator, int initialCapacity) Creates a new parent buffer. -
Method Summary
Modifier and TypeMethodDescriptionfinal CharBuffer
final DoubleBuffer
final FloatBuffer
Returns anInputStream
that reads the data from this buffer.final IntBuffer
final LongBuffer
Returns anOutputStream
that appends the data into this buffer.final IoBuffer
protected abstract IoBuffer
Implement this method to return the unexpandable read only version of this buffer.final ShortBuffer
private IoBuffer
autoExpand
(int expectedRemaining) This method forwards the call toexpand(int)
only when autoExpand property is true.private IoBuffer
autoExpand
(int pos, int expectedRemaining) This method forwards the call toexpand(int)
only when autoExpand property is true.protected abstract void
buf
(ByteBuffer newBuf) Sets the underlying NIO buffer instance.final int
capacity()
final IoBuffer
capacity
(int newCapacity) Increases the capacity of this buffer.private static void
checkFieldSize
(int fieldSize) final IoBuffer
clear()
final IoBuffer
compact()
int
final IoBuffer
protected abstract IoBuffer
Implement this method to return the unexpandable duplicate of this buffer.private String
enumConversionErrorMessage
(Enum<?> e, String type) boolean
final IoBuffer
expand
(int expectedRemaining) Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the current position.private IoBuffer
expand
(int expectedRemaining, boolean autoExpand) final 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.private IoBuffer
expand
(int pos, int expectedRemaining, boolean autoExpand) fill
(byte value, int size) Fills this buffer with the specified value.fill
(int size) Fills this buffer withNUL (0x00)
.fillAndReset
(byte value, int size) Fills this buffer with the specified value.fillAndReset
(int size) Fills this buffer withNUL (0x00)
.final IoBuffer
flip()
final byte
get()
get
(byte[] dst) final IoBuffer
get
(byte[] dst, int offset, int length) final byte
get
(int index) final char
getChar()
final char
getChar
(int index) final double
final double
getDouble
(int index) <E extends Enum<E>>
EReads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EReads a byte from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EgetEnumInt
(int index, Class<E> enumClass) Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EgetEnumInt
(Class<E> enumClass) Reads an int from the buffer and returns the correlating enum constant defined by the specified enum type.getEnumSet
(int index, Class<E> enumClass) Reads a byte sized bit vector and converts it to anEnumSet
.getEnumSet
(Class<E> enumClass) Reads a byte sized bit vector and converts it to anEnumSet
.getEnumSetInt
(int index, Class<E> enumClass) Reads an int sized bit vector and converts it to anEnumSet
.getEnumSetInt
(Class<E> enumClass) Reads an int sized bit vector and converts it to anEnumSet
.getEnumSetLong
(int index, Class<E> enumClass) Reads a long sized bit vector and converts it to anEnumSet
.getEnumSetLong
(Class<E> enumClass) Reads a long sized bit vector and converts it to anEnumSet
.getEnumSetShort
(int index, Class<E> enumClass) Reads a short sized bit vector and converts it to anEnumSet
.getEnumSetShort
(Class<E> enumClass) Reads a short sized bit vector and converts it to anEnumSet
.<E extends Enum<E>>
EgetEnumShort
(int index, Class<E> enumClass) Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.<E extends Enum<E>>
EgetEnumShort
(Class<E> enumClass) Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.final float
getFloat()
final float
getFloat
(int index) Returns hexdump of this buffer.getHexDump
(int lengthLimit) Return hexdump of this buffer with limited length.final int
getInt()
final int
getInt
(int index) final long
getLong()
final long
getLong
(int index) int
Relative get method for reading a medium int value.private int
getMediumInt
(byte b1, byte b2, byte b3) int
getMediumInt
(int index) Absolute get method for reading a medium int value.Reads a Java object from the buffer using the contextClassLoader
of the current thread.getObject
(ClassLoader classLoader) Reads a Java object from the buffer using the specified classLoader.getPrefixedString
(int prefixLength, CharsetDecoder decoder) Reads a string which has a length field before the actual encoded string, using the specifieddecoder
and returns it.getPrefixedString
(CharsetDecoder decoder) Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoder
and returns it.final short
getShort()
final short
getShort
(int index) final IoBuffer
getSlice
(int length) TODO document me.final IoBuffer
getSlice
(int index, int length) TODO document me.getString
(int fieldSize, CharsetDecoder decoder) Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it.getString
(CharsetDecoder decoder) Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it.final short
Reads one unsigned byte as a short integer.final short
getUnsigned
(int index) Reads one byte as an unsigned short integer.long
Reads four bytes unsigned integer.long
getUnsignedInt
(int index) Reads four bytes unsigned integer.int
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
Reads two bytes unsigned integer.int
getUnsignedShort
(int index) Reads two bytes unsigned integer.int
hashCode()
final boolean
int
indexOf
(byte b) Returns the first occurence position of the specified byte from the current position to the current limit.final boolean
Returns true if and only if autoExpand is turned on.final boolean
Returns true if and only if autoShrink is turned on.final boolean
returns true if and only if this buffer is derived from other buffer viaIoBuffer.duplicate()
,IoBuffer.slice()
orIoBuffer.asReadOnlyBuffer()
.final boolean
isDirect()
final boolean
final int
limit()
final IoBuffer
limit
(int newLimit) final IoBuffer
mark()
final int
Returns the position of the current mark.final int
Returns the minimum capacity of this buffer which is used to determine the new capacity of the buffer shrunk byIoBuffer.compact()
andIoBuffer.shrink()
operation.final 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.final ByteOrder
order()
final IoBuffer
final int
position()
final IoBuffer
position
(int newPosition) boolean
prefixedDataAvailable
(int prefixLength) 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.boolean
prefixedDataAvailable
(int prefixLength, int maxDataLength) 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.final IoBuffer
put
(byte b) put
(byte[] src) final IoBuffer
put
(byte[] src, int offset, int length) final IoBuffer
put
(int index, byte b) Writes the content of the specified src into this buffer.final IoBuffer
put
(ByteBuffer src) Writes the content of the specified src into this buffer.final IoBuffer
putChar
(char value) final IoBuffer
putChar
(int index, char value) final IoBuffer
putDouble
(double value) final IoBuffer
putDouble
(int index, double value) Writes an enum's ordinal value to the buffer as a byte.Writes an enum's ordinal value to the buffer as a byte.putEnumInt
(int index, Enum<?> e) Writes an enum's ordinal value to the buffer as an integer.putEnumInt
(Enum<?> e) Writes an enum's ordinal value to the buffer as an integer.putEnumSet
(int index, Set<E> set) Writes the specifiedSet
to the buffer as a byte sized bit vector.putEnumSet
(Set<E> set) Writes the specifiedSet
to the buffer as a byte sized bit vector.putEnumSetInt
(int index, Set<E> set) Writes the specifiedSet
to the buffer as an int sized bit vector.putEnumSetInt
(Set<E> set) Writes the specifiedSet
to the buffer as an int sized bit vector.putEnumSetLong
(int index, Set<E> set) Writes the specifiedSet
to the buffer as a long sized bit vector.putEnumSetLong
(Set<E> set) Writes the specifiedSet
to the buffer as a long sized bit vector.putEnumSetShort
(int index, Set<E> set) Writes the specifiedSet
to the buffer as a short sized bit vector.putEnumSetShort
(Set<E> set) Writes the specifiedSet
to the buffer as a short sized bit vector.putEnumShort
(int index, Enum<?> e) Writes an enum's ordinal value to the buffer as a short.putEnumShort
(Enum<?> e) Writes an enum's ordinal value to the buffer as a short.final IoBuffer
putFloat
(float value) final IoBuffer
putFloat
(int index, float value) final IoBuffer
putInt
(int value) final IoBuffer
putInt
(int index, int value) final IoBuffer
putLong
(int index, long value) final IoBuffer
putLong
(long value) putMediumInt
(int value) Relative put method for writing a medium int value.putMediumInt
(int index, int value) Absolute put method for writing a medium int value.Writes the specified Java object to the buffer.putPrefixedString
(CharSequence val, int prefixLength, int padding, byte padValue, CharsetEncoder encoder) Writes the content ofin
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.putPrefixedString
(CharSequence in, int prefixLength, int padding, CharsetEncoder encoder) Writes the content ofin
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.putPrefixedString
(CharSequence in, int prefixLength, CharsetEncoder encoder) Writes the content ofin
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.putPrefixedString
(CharSequence in, CharsetEncoder encoder) Writes the content ofin
into this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder
.final IoBuffer
putShort
(int index, short value) final IoBuffer
putShort
(short value) putString
(CharSequence val, int fieldSize, CharsetEncoder encoder) Writes the content ofin
into this buffer as aNUL
-terminated string using the specifiedencoder
.putString
(CharSequence val, CharsetEncoder encoder) Writes the content ofin
into this buffer using the specifiedencoder
.final int
final IoBuffer
reset()
final IoBuffer
rewind()
final IoBuffer
setAutoExpand
(boolean autoExpand) Turns on or off autoExpand.final IoBuffer
setAutoShrink
(boolean autoShrink) Turns on or off autoShrink.final 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.skip
(int size) Forwards the position of this buffer as the specifiedsize
bytes.final IoBuffer
slice()
protected abstract IoBuffer
slice0()
Implement this method to return the unexpandable slice of this buffer.final IoBuffer
sweep()
Clears this buffer and fills its content with NUL.final IoBuffer
sweep
(byte value) double Clears this buffer and fills its content with value.private <E> E
private <E extends Enum<E>>
longtoString()
Methods inherited from class com.google.code.yanf4j.buffer.IoBuffer
allocate, allocate, array, arrayOffset, buf, free, getAllocator, hasArray, isUseDirectBuffer, normalizeCapacity, setAllocator, setUseDirectBuffer, wrap, wrap, wrap
-
Field Details
-
derived
private final boolean derivedTells if a buffer has been created from an existing buffer -
autoExpand
private boolean autoExpandA flag set to true if the buffer can extend automatically -
autoShrink
private boolean autoShrinkA flag set to true if the buffer can shrink automatically -
recapacityAllowed
private boolean recapacityAllowedTells if a buffer can be expanded -
minimumCapacity
private int minimumCapacityThe minimum number of bytes the IoBuffer can hold -
BYTE_MASK
private static final long BYTE_MASKA mask for a byte- See Also:
-
SHORT_MASK
private static final long SHORT_MASKA mask for a short- See Also:
-
INT_MASK
private static final long INT_MASKA mask for an int- See Also:
-
mark
private int markWe don't have any access to Buffer.markValue(), so we need to track it down, which will cause small extra overhead.
-
-
Constructor Details
-
AbstractIoBuffer
Creates a new parent buffer.- Parameters:
allocator
- The allocator to use to create new buffersinitialCapacity
- The initial buffer capacity when created
-
AbstractIoBuffer
Creates a new derived buffer. A derived buffer uses an existing buffer properties - the allocator and capacity -.- Parameters:
parent
- The buffer we get the properties from
-
-
Method Details
-
isDirect
public final boolean isDirect() -
isReadOnly
public final boolean isReadOnly()- Specified by:
isReadOnly
in classIoBuffer
- See Also:
-
buf
Sets the underlying NIO buffer instance.- Parameters:
newBuf
- The buffer to store within this IoBuffer
-
minimumCapacity
public final int minimumCapacity()Returns 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
-
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
-
capacity
public final int capacity() -
capacity
Increases the capacity of this buffer. If the new capacity is less than or equal to the current capacity, this method returns silently. 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. -
isAutoExpand
public final boolean isAutoExpand()Returns true if and only if autoExpand is turned on.- Specified by:
isAutoExpand
in classIoBuffer
-
isAutoShrink
public final boolean isAutoShrink()Returns true if and only if autoShrink is turned on.- Specified by:
isAutoShrink
in classIoBuffer
-
isDerived
public final boolean isDerived()returns true if and only if this buffer is derived from other buffer viaIoBuffer.duplicate()
,IoBuffer.slice()
orIoBuffer.asReadOnlyBuffer()
. -
setAutoExpand
Turns on or off autoExpand.- Specified by:
setAutoExpand
in classIoBuffer
-
setAutoShrink
Turns on or off autoShrink.- Specified by:
setAutoShrink
in classIoBuffer
-
expand
Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the current position. This method works even if you didn't set autoExpand to true. -
expand
-
expand
Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the specified position. This method works even if you didn't set autoExpand to true. -
expand
-
shrink
Changes the capacity of this buffer so this buffer occupies as less memory as possible while retaining the position, limit and the buffer content between the position and limit. The capacity of the buffer never becomes less thanIoBuffer.minimumCapacity()
. The mark is discarded once the capacity changes. -
position
public final int position() -
position
-
limit
public final int limit() -
limit
-
mark
-
markValue
public final int markValue()Returns the position of the current mark. This method returns -1 if no mark is set. -
reset
-
clear
-
sweep
Clears this buffer and fills its content with NUL. The position is set to zero, the limit is set to the capacity, and the mark is discarded. -
sweep
double Clears this buffer and fills its content with value. The position is set to zero, the limit is set to the capacity, and the mark is discarded. -
flip
-
rewind
-
remaining
public final int remaining() -
hasRemaining
public final boolean hasRemaining()- Specified by:
hasRemaining
in classIoBuffer
- See Also:
-
get
public final byte get() -
getUnsigned
public final short getUnsigned()Reads one unsigned byte as a short integer.- Specified by:
getUnsigned
in classIoBuffer
-
put
-
get
public final byte get(int index) -
getUnsigned
public final short getUnsigned(int index) Reads one byte as an unsigned short integer.- Specified by:
getUnsigned
in classIoBuffer
-
put
-
get
-
put
Writes the content of the specified src into this buffer. -
put
-
compact
-
order
-
order
-
getChar
public final char getChar() -
putChar
-
getChar
public final char getChar(int index) -
putChar
-
asCharBuffer
- Specified by:
asCharBuffer
in classIoBuffer
- See Also:
-
getShort
public final short getShort() -
putShort
-
getShort
public final short getShort(int index) -
putShort
-
asShortBuffer
- Specified by:
asShortBuffer
in classIoBuffer
- See Also:
-
getInt
public final int getInt() -
putInt
-
getInt
public final int getInt(int index) -
putInt
-
asIntBuffer
- Specified by:
asIntBuffer
in classIoBuffer
- See Also:
-
getLong
public final long getLong() -
putLong
-
getLong
public final long getLong(int index) -
putLong
-
asLongBuffer
- Specified by:
asLongBuffer
in classIoBuffer
- See Also:
-
getFloat
public final float getFloat() -
putFloat
-
getFloat
public final float getFloat(int index) -
putFloat
-
asFloatBuffer
- Specified by:
asFloatBuffer
in classIoBuffer
- See Also:
-
getDouble
public final double getDouble() -
putDouble
-
getDouble
public final double getDouble(int index) -
putDouble
-
asDoubleBuffer
- Specified by:
asDoubleBuffer
in classIoBuffer
- See Also:
-
asReadOnlyBuffer
- Specified by:
asReadOnlyBuffer
in classIoBuffer
- See Also:
-
asReadOnlyBuffer0
Implement this method to return the unexpandable read only version of this buffer. -
duplicate
-
duplicate0
Implement this method to return the unexpandable duplicate of this buffer. -
slice
-
getSlice
TODO document me. -
getSlice
TODO document me. -
slice0
Implement this method to return the unexpandable slice of this buffer. -
hashCode
public int hashCode() -
equals
-
compareTo
-
toString
-
get
-
put
Writes the content of the specified src into this buffer. -
put
-
getUnsignedShort
public int getUnsignedShort()Reads two bytes unsigned integer.- Specified by:
getUnsignedShort
in classIoBuffer
-
getUnsignedShort
public int getUnsignedShort(int index) Reads two bytes unsigned integer.- Specified by:
getUnsignedShort
in classIoBuffer
-
getUnsignedInt
public long getUnsignedInt()Reads four bytes unsigned integer.- Specified by:
getUnsignedInt
in classIoBuffer
-
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
-
getMediumInt
private int getMediumInt(byte b1, byte b2, byte b3) -
putMediumInt
Relative put method for writing a medium int value.Writes three bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by three.
- Specified by:
putMediumInt
in classIoBuffer
- Parameters:
value
- The medium int value to be written- Returns:
- This buffer
-
putMediumInt
Absolute put method for writing a medium int value.Writes three bytes containing the given int value, in the current byte order, into this buffer at the given index.
- Specified by:
putMediumInt
in classIoBuffer
- Parameters:
index
- The index at which the bytes will be writtenvalue
- The medium int value to be written- Returns:
- This buffer
-
getUnsignedInt
public long getUnsignedInt(int index) Reads four bytes unsigned integer.- Specified by:
getUnsignedInt
in classIoBuffer
-
asInputStream
Returns anInputStream
that reads the data from this buffer.InputStream.read()
returns -1 if the buffer position reaches to the limit.- Specified by:
asInputStream
in classIoBuffer
-
asOutputStream
Returns anOutputStream
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 set autoExpand property by callingIoBuffer.setAutoExpand(boolean)
to prevent the unexpected runtime exception.- Specified by:
asOutputStream
in classIoBuffer
-
getHexDump
Returns hexdump of this buffer. The data and pointer are not changed as a result of this method call.- Specified by:
getHexDump
in classIoBuffer
- Returns:
- hexidecimal representation of this buffer
-
getHexDump
Return hexdump of this buffer with limited length.- Specified by:
getHexDump
in classIoBuffer
- Parameters:
lengthLimit
- The maximum number of bytes to dump from the current buffer position.- Returns:
- hexidecimal representation of this buffer
-
getString
Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it. This method reads until the limit of this buffer if no NUL is found.- Specified by:
getString
in classIoBuffer
- Throws:
CharacterCodingException
-
getString
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 read- Throws:
CharacterCodingException
-
putString
Writes the content ofin
into this buffer using the specifiedencoder
. This method doesn't terminate string with NUL. You have to do it by yourself.- Specified by:
putString
in classIoBuffer
- Throws:
CharacterCodingException
-
putString
public IoBuffer putString(CharSequence val, 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 than fieldSize.- Specified by:
putString
in classIoBuffer
- Parameters:
fieldSize
- the maximum number of bytes to write- Throws:
CharacterCodingException
-
getPrefixedString
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 for getPrefixedString(2, decoder).- Specified by:
getPrefixedString
in classIoBuffer
- Throws:
CharacterCodingException
-
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 decoder to use for decoding the string- Returns:
- the prefixed string
- Throws:
CharacterCodingException
- when decoding failsBufferUnderflowException
- when there is not enough data available
-
putPrefixedString
public IoBuffer putPrefixedString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException Writes the content 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 for putPrefixedString(in, 2, 0, encoder).- Specified by:
putPrefixedString
in classIoBuffer
- Throws:
CharacterCodingException
-
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 for putPrefixedString(in, prefixLength, 0, encoder).- Specified by:
putPrefixedString
in classIoBuffer
- Parameters:
prefixLength
- the length of the length field (1, 2, or 4)- Throws:
CharacterCodingException
-
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 for putPrefixedString(in, prefixLength, padding, ( byte ) 0, encoder) .- Specified by:
putPrefixedString
in classIoBuffer
- Parameters:
prefixLength
- the length of the length field (1, 2, or 4)padding
- the number of padded NULs (1 (or 0), 2, or 4)- Throws:
CharacterCodingException
-
putPrefixedString
public IoBuffer putPrefixedString(CharSequence val, int prefixLength, int padding, byte padValue, 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
.- Specified by:
putPrefixedString
in classIoBuffer
- Parameters:
prefixLength
- 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 bytes- Throws:
CharacterCodingException
-
getObject
Reads a Java object from the buffer using the contextClassLoader
of the current thread.- Specified by:
getObject
in classIoBuffer
- Throws:
ClassNotFoundException
-
getObject
Reads a Java object from the buffer using the specified classLoader.- Specified by:
getObject
in classIoBuffer
- Throws:
ClassNotFoundException
-
putObject
Writes the specified Java object to the buffer. -
prefixedDataAvailable
public boolean prefixedDataAvailable(int prefixLength) 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 with prefixedDataAvailable( 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.- Specified by:
prefixedDataAvailable
in classIoBuffer
- Parameters:
prefixLength
- the length of the prefix field (1, 2, or 4)
-
prefixedDataAvailable
public boolean prefixedDataAvailable(int prefixLength, int maxDataLength) 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.- 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
-
indexOf
public int indexOf(byte b) Returns the first occurence position of the specified byte from the current position to the current limit. -
skip
Forwards the position of this buffer as the specifiedsize
bytes. -
fill
Fills this buffer with the specified value. This method moves buffer position forward. -
fillAndReset
Fills this buffer with the specified value. This method does not change buffer position.- Specified by:
fillAndReset
in classIoBuffer
-
fill
Fills this buffer withNUL (0x00)
. This method moves buffer position forward. -
fillAndReset
Fills this buffer withNUL (0x00)
. This method does not change buffer position.- Specified by:
fillAndReset
in classIoBuffer
-
getEnum
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type. -
getEnum
Reads a byte from the buffer and returns the correlating enum constant defined by the specified enum type. -
getEnumShort
Reads a short from the buffer and returns the correlating enum constant defined by the specified enum type.- Specified by:
getEnumShort
in classIoBuffer
- Type Parameters:
E
- The enum type to return- Parameters:
enumClass
- The enum's class object
-
getEnumShort
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
-
getEnumInt
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
-
getEnumInt
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
-
putEnum
Writes an enum's ordinal value to the buffer as a byte. -
putEnum
Writes an enum's ordinal value to the buffer as a byte. -
putEnumShort
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
-
putEnumShort
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
-
putEnumInt
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
-
putEnumInt
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
-
toEnum
-
enumConversionErrorMessage
-
getEnumSet
Reads a byte sized bit vector and converts it to anEnumSet
.Each bit is mapped to a value in the specified enum. The least significant bit maps to the first entry in the specified enum and each subsequent bit maps to each subsequent bit as mapped to the subsequent enum value.
- Specified by:
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
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:
-
getEnumSetShort
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:
-
getEnumSetShort
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:
-
getEnumSetInt
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:
-
getEnumSetInt
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:
-
getEnumSetLong
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:
-
getEnumSetLong
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:
-
toEnumSet
-
putEnumSet
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
-
putEnumSet
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
-
putEnumSetShort
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
-
putEnumSetShort
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
-
putEnumSetInt
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
-
putEnumSetInt
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
-
putEnumSetLong
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
-
putEnumSetLong
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
-
toLong
-
autoExpand
This method forwards the call toexpand(int)
only when autoExpand property is true. -
autoExpand
This method forwards the call toexpand(int)
only when autoExpand property is true. -
checkFieldSize
private static void checkFieldSize(int fieldSize)
-