public abstract class ByteBuffer extends java.lang.Object implements java.lang.Comparable<ByteBuffer>
This is a replacement for ByteBuffer
. Please refer to
ByteBuffer
and Buffer
documentation for
usage. MINA does not use NIO ByteBuffer
directly for two
reasons:
fill
, get/putString
, and
get/putAsciiInt()
enough.You can get a heap buffer from buffer pool:
ByteBuffer buf = ByteBuffer.allocate(1024, false);you can also get a direct buffer from buffer pool:
ByteBuffer buf = ByteBuffer.allocate(1024, true);or you can let MINA choose:
ByteBuffer buf = ByteBuffer.allocate(1024);
Please note that you never need to release the allocated buffer because MINA will release it automatically when:
IoSession.write(Object)
.IoFilter.NextFilter.filterWrite(IoSession,IoFilter.WriteRequest)
.ProtocolEncoderOutput.write(ByteBuffer)
.ByteBuffer
which is passed as a parameter
of IoHandler.messageReceived(IoSession, Object)
method. They are released
automatically when the method returns.
You have to release buffers manually by calling release()
when:
acquire()
to prevent the buffer from being released.
This class provides a few wrap(...) methods that wraps
any NIO buffers and byte arrays. Wrapped MINA buffers are not returned
to the buffer pool by default to prevent unexpected memory leakage by default.
In case you want to make it pooled, you can call setPooled(boolean)
with true flag to enable pooling.
Writing variable-length data using NIO ByteBuffers is not really
easy, and it is because its size is fixed. MINA ByteBuffer
introduces autoExpand property. If autoExpand property
is true, you never get BufferOverflowException
or
IndexOutOfBoundsException
(except when index is negative).
It automatically expands its capacity and limit value. For example:
String greeting = messageBundle.getMessage( "hello" ); ByteBuffer buf = ByteBuffer.allocate( 16 ); // Turn on autoExpand (it is off by default) buf.setAutoExpand( true ); buf.putString( greeting, utf8encoder );NIO ByteBuffer is reallocated by MINA ByteBuffer behind the scene if the encoded data is larger than 16 bytes. Its capacity and its limit will increase to the last position the string is written.
Derived buffers are the buffers which were created by
duplicate()
, slice()
, or asReadOnlyBuffer()
.
They are useful especially when you broadcast the same messages to
multiple IoSession
s. Please note that the derived buffers are
neither pooled nor auto-expandable. Trying to expand a derived buffer will
raise IllegalStateException
.
MINA provides a ByteBufferAllocator
interface to let you override
the default buffer management behavior. There are two allocators provided
out-of-the-box:
setAllocator(ByteBufferAllocator)
.
ByteBufferAllocator
限定符 | 构造器和说明 |
---|---|
protected |
ByteBuffer() |
限定符和类型 | 方法和说明 |
---|---|
abstract void |
acquire()
Increases the internal reference count of this buffer to defer
automatic release.
|
static ByteBuffer |
allocate(int capacity)
Returns the direct or heap buffer which is capable of the specified
size.
|
static ByteBuffer |
allocate(int capacity,
boolean direct)
Returns the buffer which is capable of the specified size.
|
abstract byte[] |
array() |
abstract int |
arrayOffset() |
abstract java.nio.CharBuffer |
asCharBuffer() |
abstract java.nio.DoubleBuffer |
asDoubleBuffer() |
abstract java.nio.FloatBuffer |
asFloatBuffer() |
java.io.InputStream |
asInputStream()
Returns an
InputStream that reads the data from this buffer. |
abstract java.nio.IntBuffer |
asIntBuffer() |
abstract java.nio.LongBuffer |
asLongBuffer() |
java.io.OutputStream |
asOutputStream()
Returns an
OutputStream that appends the data into this buffer. |
abstract ByteBuffer |
asReadOnlyBuffer() |
abstract java.nio.ShortBuffer |
asShortBuffer() |
protected ByteBuffer |
autoExpand(int expectedRemaining)
This method forwards the call to
expand(int) only when
autoExpand property is true. |
protected ByteBuffer |
autoExpand(int pos,
int expectedRemaining)
This method forwards the call to
expand(int) only when
autoExpand property is true. |
abstract java.nio.ByteBuffer |
buf()
Returns the underlying NIO buffer instance.
|
abstract int |
capacity() |
abstract ByteBuffer |
capacity(int newCapacity)
Changes the capacity of this buffer.
|
abstract ByteBuffer |
clear() |
abstract ByteBuffer |
compact() |
int |
compareTo(ByteBuffer that) |
abstract ByteBuffer |
duplicate() |
boolean |
equals(java.lang.Object o) |
ByteBuffer |
expand(int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get
the specified expectedRemaining room from the current position.
|
abstract ByteBuffer |
expand(int pos,
int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get
the specified expectedRemaining room from the specified
pos.
|
ByteBuffer |
fill(byte value,
int size)
Fills this buffer with the specified value.
|
ByteBuffer |
fill(int size)
Fills this buffer with
NUL (0x00) . |
ByteBuffer |
fillAndReset(byte value,
int size)
Fills this buffer with the specified value.
|
ByteBuffer |
fillAndReset(int size)
Fills this buffer with
NUL (0x00) . |
abstract ByteBuffer |
flip() |
abstract byte |
get() |
ByteBuffer |
get(byte[] dst) |
abstract ByteBuffer |
get(byte[] dst,
int offset,
int length) |
abstract byte |
get(int index) |
static ByteBufferAllocator |
getAllocator()
Returns the current allocator which manages the allocated buffers.
|
abstract char |
getChar() |
abstract char |
getChar(int index) |
abstract double |
getDouble() |
abstract double |
getDouble(int index) |
abstract float |
getFloat() |
abstract float |
getFloat(int index) |
java.lang.String |
getHexDump()
Returns hexdump of this buffer.
|
abstract int |
getInt() |
abstract int |
getInt(int index) |
abstract long |
getLong() |
abstract long |
getLong(int index) |
java.lang.Object |
getObject()
Reads a Java object from the buffer using the context
ClassLoader
of the current thread. |
java.lang.Object |
getObject(java.lang.ClassLoader classLoader)
Reads a Java object from the buffer using the specified classLoader.
|
java.lang.String |
getPrefixedString(java.nio.charset.CharsetDecoder decoder)
Reads a string which has a 16-bit length field before the actual
encoded string, using the specified
decoder and returns it. |
java.lang.String |
getPrefixedString(int prefixLength,
java.nio.charset.CharsetDecoder decoder)
Reads a string which has a length field before the actual
encoded string, using the specified
decoder and returns it. |
abstract short |
getShort() |
abstract short |
getShort(int index) |
java.lang.String |
getString(java.nio.charset.CharsetDecoder decoder)
Reads a
NUL -terminated string from this buffer using the
specified decoder and returns it. |
java.lang.String |
getString(int fieldSize,
java.nio.charset.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 |
getUnsignedShort()
Reads two bytes unsigned integer.
|
int |
getUnsignedShort(int index)
Reads two bytes unsigned integer.
|
int |
hashCode() |
boolean |
hasRemaining() |
abstract boolean |
isAutoExpand()
Returns true if and only if autoExpand is turned on.
|
abstract boolean |
isDirect() |
abstract boolean |
isPooled()
Returns true if and only if this buffer is returned back
to the buffer pool when released.
|
abstract boolean |
isReadOnly() |
static boolean |
isUseDirectBuffers() |
abstract int |
limit() |
abstract ByteBuffer |
limit(int newLimit) |
abstract ByteBuffer |
mark() |
abstract int |
markValue()
Returns the position of the current mark.
|
abstract java.nio.ByteOrder |
order() |
abstract ByteBuffer |
order(java.nio.ByteOrder bo) |
abstract int |
position() |
abstract ByteBuffer |
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.
|
abstract ByteBuffer |
put(byte b) |
ByteBuffer |
put(byte[] src) |
abstract ByteBuffer |
put(byte[] src,
int offset,
int length) |
abstract ByteBuffer |
put(java.nio.ByteBuffer src)
Writes the content of the specified src into this buffer.
|
ByteBuffer |
put(ByteBuffer src)
Writes the content of the specified src into this buffer.
|
abstract ByteBuffer |
put(int index,
byte b) |
abstract ByteBuffer |
putChar(char value) |
abstract ByteBuffer |
putChar(int index,
char value) |
abstract ByteBuffer |
putDouble(double value) |
abstract ByteBuffer |
putDouble(int index,
double value) |
abstract ByteBuffer |
putFloat(float value) |
abstract ByteBuffer |
putFloat(int index,
float value) |
abstract ByteBuffer |
putInt(int value) |
abstract ByteBuffer |
putInt(int index,
int value) |
abstract ByteBuffer |
putLong(int index,
long value) |
abstract ByteBuffer |
putLong(long value) |
ByteBuffer |
putObject(java.lang.Object o)
Writes the specified Java object to the buffer.
|
ByteBuffer |
putPrefixedString(java.lang.CharSequence in,
java.nio.charset.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 . |
ByteBuffer |
putPrefixedString(java.lang.CharSequence in,
int prefixLength,
java.nio.charset.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 . |
ByteBuffer |
putPrefixedString(java.lang.CharSequence val,
int prefixLength,
int padding,
byte padValue,
java.nio.charset.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 . |
ByteBuffer |
putPrefixedString(java.lang.CharSequence in,
int prefixLength,
int padding,
java.nio.charset.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 . |
abstract ByteBuffer |
putShort(int index,
short value) |
abstract ByteBuffer |
putShort(short value) |
ByteBuffer |
putString(java.lang.CharSequence val,
java.nio.charset.CharsetEncoder encoder)
Writes the content of
in into this buffer using the
specified encoder . |
ByteBuffer |
putString(java.lang.CharSequence val,
int fieldSize,
java.nio.charset.CharsetEncoder encoder)
Writes the content of
in into this buffer as a
NUL -terminated string using the specified
encoder . |
abstract void |
release()
Releases the specified buffer to buffer pool.
|
int |
remaining() |
abstract ByteBuffer |
reset() |
abstract ByteBuffer |
rewind() |
static void |
setAllocator(ByteBufferAllocator newAllocator)
Changes the current allocator with the specified one to manage
the allocated buffers from now.
|
abstract ByteBuffer |
setAutoExpand(boolean autoExpand)
Turns on or off autoExpand.
|
abstract void |
setPooled(boolean pooled)
Sets whether this buffer is returned back to the buffer pool when released.
|
static void |
setUseDirectBuffers(boolean useDirectBuffers) |
ByteBuffer |
skip(int size)
Forwards the position of this buffer as the specified
size
bytes. |
abstract ByteBuffer |
slice() |
ByteBuffer |
sweep()
Clears this buffer and fills its content with NUL.
|
ByteBuffer |
sweep(byte value)
Clears this buffer and fills its content with value.
|
java.lang.String |
toString() |
static ByteBuffer |
wrap(byte[] byteArray)
Wraps the specified byte array into MINA heap buffer.
|
static ByteBuffer |
wrap(byte[] byteArray,
int offset,
int length)
Wraps the specified byte array into MINA heap buffer.
|
static ByteBuffer |
wrap(java.nio.ByteBuffer nioBuffer)
Wraps the specified NIO
ByteBuffer into MINA buffer. |
public static ByteBufferAllocator getAllocator()
public static void setAllocator(ByteBufferAllocator newAllocator)
public static boolean isUseDirectBuffers()
public static void setUseDirectBuffers(boolean useDirectBuffers)
public static ByteBuffer allocate(int capacity)
allocate(int, boolean)
to allocate buffers of specific type.capacity
- the capacity of the bufferpublic static ByteBuffer allocate(int capacity, boolean direct)
capacity
- the capacity of the bufferdirect
- true to get a direct buffer,
false to get a heap buffer.public static ByteBuffer wrap(java.nio.ByteBuffer nioBuffer)
ByteBuffer
into MINA buffer.public static ByteBuffer wrap(byte[] byteArray)
public static ByteBuffer wrap(byte[] byteArray, int offset, int length)
public abstract void acquire()
release()
as many
as you invoked this method to release this buffer.java.lang.IllegalStateException
- if you attempt to acquire already
released buffer.public abstract void release()
java.lang.IllegalStateException
- if you attempt to release already
released buffer.public abstract java.nio.ByteBuffer buf()
public abstract boolean isDirect()
ByteBuffer.isDirect()
public abstract boolean isReadOnly()
Buffer.isReadOnly()
public abstract int capacity()
Buffer.capacity()
public abstract ByteBuffer capacity(int newCapacity)
public abstract boolean isAutoExpand()
public abstract ByteBuffer setAutoExpand(boolean autoExpand)
public ByteBuffer expand(int expectedRemaining)
public abstract ByteBuffer expand(int pos, int expectedRemaining)
public abstract boolean isPooled()
The default value of this property is true if and only if you
allocated this buffer using allocate(int)
or allocate(int, boolean)
,
or false otherwise. (i.e. wrap(byte[])
, wrap(byte[], int, int)
,
and wrap(java.nio.ByteBuffer)
)
public abstract void setPooled(boolean pooled)
The default value of this property is true if and only if you
allocated this buffer using allocate(int)
or allocate(int, boolean)
,
or false otherwise. (i.e. wrap(byte[])
, wrap(byte[], int, int)
,
and wrap(java.nio.ByteBuffer)
)
public abstract int position()
Buffer.position()
public abstract ByteBuffer position(int newPosition)
Buffer.position(int)
public abstract int limit()
Buffer.limit()
public abstract ByteBuffer limit(int newLimit)
Buffer.limit(int)
public abstract ByteBuffer mark()
Buffer.mark()
public abstract int markValue()
public abstract ByteBuffer reset()
Buffer.reset()
public abstract ByteBuffer clear()
Buffer.clear()
public ByteBuffer sweep()
public ByteBuffer sweep(byte value)
public abstract ByteBuffer flip()
Buffer.flip()
public abstract ByteBuffer rewind()
Buffer.rewind()
public int remaining()
Buffer.remaining()
public boolean hasRemaining()
Buffer.hasRemaining()
public abstract ByteBuffer duplicate()
ByteBuffer.duplicate()
public abstract ByteBuffer slice()
ByteBuffer.slice()
public abstract ByteBuffer asReadOnlyBuffer()
ByteBuffer.asReadOnlyBuffer()
public abstract byte[] array()
ByteBuffer.array()
public abstract int arrayOffset()
ByteBuffer.arrayOffset()
public abstract byte get()
ByteBuffer.get()
public short getUnsigned()
public abstract ByteBuffer put(byte b)
ByteBuffer.put(byte)
public abstract byte get(int index)
ByteBuffer.get(int)
public short getUnsigned(int index)
public abstract ByteBuffer put(int index, byte b)
ByteBuffer.put(int, byte)
public abstract ByteBuffer get(byte[] dst, int offset, int length)
ByteBuffer.get(byte[], int, int)
public ByteBuffer get(byte[] dst)
ByteBuffer.get(byte[])
public abstract ByteBuffer put(java.nio.ByteBuffer src)
public ByteBuffer put(ByteBuffer src)
public abstract ByteBuffer put(byte[] src, int offset, int length)
ByteBuffer.put(byte[], int, int)
public ByteBuffer put(byte[] src)
ByteBuffer.put(byte[])
public abstract ByteBuffer compact()
ByteBuffer.compact()
public java.lang.String toString()
toString
在类中 java.lang.Object
public int hashCode()
hashCode
在类中 java.lang.Object
public boolean equals(java.lang.Object o)
equals
在类中 java.lang.Object
public int compareTo(ByteBuffer that)
compareTo
在接口中 java.lang.Comparable<ByteBuffer>
public abstract java.nio.ByteOrder order()
ByteBuffer.order()
public abstract ByteBuffer order(java.nio.ByteOrder bo)
ByteBuffer.order(ByteOrder)
public abstract char getChar()
ByteBuffer.getChar()
public abstract ByteBuffer putChar(char value)
ByteBuffer.putChar(char)
public abstract char getChar(int index)
ByteBuffer.getChar(int)
public abstract ByteBuffer putChar(int index, char value)
ByteBuffer.putChar(int, char)
public abstract java.nio.CharBuffer asCharBuffer()
ByteBuffer.asCharBuffer()
public abstract short getShort()
ByteBuffer.getShort()
public int getUnsignedShort()
public abstract ByteBuffer putShort(short value)
ByteBuffer.putShort(short)
public abstract short getShort(int index)
ByteBuffer.getShort()
public int getUnsignedShort(int index)
public abstract ByteBuffer putShort(int index, short value)
ByteBuffer.putShort(int, short)
public abstract java.nio.ShortBuffer asShortBuffer()
ByteBuffer.asShortBuffer()
public abstract int getInt()
ByteBuffer.getInt()
public long getUnsignedInt()
public abstract ByteBuffer putInt(int value)
ByteBuffer.putInt(int)
public abstract int getInt(int index)
ByteBuffer.getInt(int)
public long getUnsignedInt(int index)
public abstract ByteBuffer putInt(int index, int value)
ByteBuffer.putInt(int, int)
public abstract java.nio.IntBuffer asIntBuffer()
ByteBuffer.asIntBuffer()
public abstract long getLong()
ByteBuffer.getLong()
public abstract ByteBuffer putLong(long value)
ByteBuffer.putLong(int, long)
public abstract long getLong(int index)
ByteBuffer.getLong(int)
public abstract ByteBuffer putLong(int index, long value)
ByteBuffer.putLong(int, long)
public abstract java.nio.LongBuffer asLongBuffer()
ByteBuffer.asLongBuffer()
public abstract float getFloat()
ByteBuffer.getFloat()
public abstract ByteBuffer putFloat(float value)
ByteBuffer.putFloat(float)
public abstract float getFloat(int index)
ByteBuffer.getFloat(int)
public abstract ByteBuffer putFloat(int index, float value)
ByteBuffer.putFloat(int, float)
public abstract java.nio.FloatBuffer asFloatBuffer()
ByteBuffer.asFloatBuffer()
public abstract double getDouble()
ByteBuffer.getDouble()
public abstract ByteBuffer putDouble(double value)
ByteBuffer.putDouble(double)
public abstract double getDouble(int index)
ByteBuffer.getDouble(int)
public abstract ByteBuffer putDouble(int index, double value)
ByteBuffer.putDouble(int, double)
public abstract java.nio.DoubleBuffer asDoubleBuffer()
ByteBuffer.asDoubleBuffer()
public java.io.InputStream asInputStream()
InputStream
that reads the data from this buffer.
InputStream.read()
returns -1 if the buffer position
reaches to the limit.public java.io.OutputStream asOutputStream()
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 setAutoExpand(boolean)
to prevent the unexpected runtime
exception.public java.lang.String getHexDump()
public java.lang.String getString(java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.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.java.nio.charset.CharacterCodingException
public java.lang.String getString(int fieldSize, java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
NUL
-terminated string from this buffer using the
specified decoder
and returns it.fieldSize
- the maximum number of bytes to readjava.nio.charset.CharacterCodingException
public ByteBuffer putString(java.lang.CharSequence val, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
in
into this buffer using the
specified encoder
. This method doesn't terminate
string with NUL. You have to do it by yourself.java.nio.BufferOverflowException
- if the specified string doesn't fitjava.nio.charset.CharacterCodingException
public ByteBuffer putString(java.lang.CharSequence val, int fieldSize, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.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.
fieldSize
- the maximum number of bytes to writejava.nio.charset.CharacterCodingException
public java.lang.String getPrefixedString(java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
decoder
and returns it.
This method is a shortcut for getPrefixedString(2, decoder).java.nio.charset.CharacterCodingException
public java.lang.String getPrefixedString(int prefixLength, java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
decoder
and returns it.prefixLength
- the length of the length field (1, 2, or 4)java.nio.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence in, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.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).java.nio.BufferOverflowException
- if the specified string doesn't fitjava.nio.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.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).prefixLength
- the length of the length field (1, 2, or 4)java.nio.BufferOverflowException
- if the specified string doesn't fitjava.nio.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, int padding, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.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).prefixLength
- the length of the length field (1, 2, or 4)padding
- the number of padded NULs (1 (or 0), 2, or 4)java.nio.BufferOverflowException
- if the specified string doesn't fitjava.nio.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence val, int prefixLength, int padding, byte padValue, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
in
into this buffer as a
string which has a 16-bit length field before the actual
encoded string, using the specified encoder
.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 bytesjava.nio.BufferOverflowException
- if the specified string doesn't fitjava.nio.charset.CharacterCodingException
public java.lang.Object getObject() throws java.lang.ClassNotFoundException
ClassLoader
of the current thread.java.lang.ClassNotFoundException
public java.lang.Object getObject(java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public ByteBuffer putObject(java.lang.Object o)
public boolean prefixedDataAvailable(int prefixLength)
prefixedDataAvailable(int, int)
instead.prefixLength
- the length of the prefix field (1, 2, or 4)java.lang.IllegalArgumentException
- if prefixLength is wrongBufferDataException
- if data length is negativepublic boolean prefixedDataAvailable(int prefixLength, int maxDataLength)
prefixLength
- the length of the prefix field (1, 2, or 4)maxDataLength
- the allowed maximum of the read data lengthjava.lang.IllegalArgumentException
- if prefixLength is wrongBufferDataException
- if data length is negative or greater then maxDataLengthpublic ByteBuffer skip(int size)
size
bytes.public ByteBuffer fill(byte value, int size)
public ByteBuffer fillAndReset(byte value, int size)
public ByteBuffer fill(int size)
NUL (0x00)
.
This method moves buffer position forward.public ByteBuffer fillAndReset(int size)
NUL (0x00)
.
This method does not change buffer position.protected ByteBuffer autoExpand(int expectedRemaining)
expand(int)
only when
autoExpand property is true.protected ByteBuffer autoExpand(int pos, int expectedRemaining)
expand(int)
only when
autoExpand property is true.