Class ByteBufferProxy
- All Implemented Interfaces:
Comparable<ByteBuffer>
ByteBuffer
that wraps a buffer and proxies any operations to it.
You can think this class like a FilterOutputStream
. All operations
are proxied by default so that you can extend this class and override existing
operations selectively. You can introduce new operations, too.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acquire()
Increases the internal reference count of this buffer to defer automatic release.byte[]
array()
int
Returns anInputStream
that reads the data from this buffer.Returns anOutputStream
that appends the data into this buffer.buf()
Returns the underlying NIO buffer instance.int
capacity()
capacity
(int newCapacity) Changes the capacity of this buffer.clear()
compact()
int
compareTo
(ByteBuffer that) boolean
expand
(int expectedRemaining) Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the current position.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.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)
.flip()
byte
get()
get
(byte[] dst) get
(byte[] dst, int offset, int length) byte
get
(int index) char
getChar()
char
getChar
(int index) double
double
getDouble
(int index) float
getFloat()
float
getFloat
(int index) Returns hexdump of this buffer.int
getInt()
int
getInt
(int index) long
getLong()
long
getLong
(int index) 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.short
getShort()
short
getShort
(int index) 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.short
Reads one unsigned byte as a short integer.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
Reads two bytes unsigned integer.int
getUnsignedShort
(int index) Reads two bytes unsigned integer.int
hashCode()
boolean
boolean
Returns true if and only if autoExpand is turned on.boolean
isDirect()
boolean
isPooled()
Returns true if and only if this buffer is returned back to the buffer pool when released.boolean
int
limit()
limit
(int newLimit) mark()
int
Returns the position of the current mark.order()
int
position()
position
(int newPosition) put
(byte b) put
(byte[] src) put
(byte[] src, int offset, int length) put
(int index, byte b) put
(ByteBuffer src) Writes the content of the specified src into this buffer.put
(ByteBuffer src) Writes the content of the specified src into this buffer.putChar
(char value) putChar
(int index, char value) putDouble
(double value) putDouble
(int index, double value) putFloat
(float value) putFloat
(int index, float value) putInt
(int value) putInt
(int index, int value) putLong
(int index, long value) putLong
(long value) Writes the specified Java object to the buffer.putPrefixedString
(CharSequence in, 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
.putShort
(int index, short value) putShort
(short value) putString
(CharSequence in, int fieldSize, CharsetEncoder encoder) Writes the content ofin
into this buffer as aNUL
-terminated string using the specifiedencoder
.putString
(CharSequence in, CharsetEncoder encoder) Writes the content ofin
into this buffer using the specifiedencoder
.void
release()
Releases the specified buffer to buffer pool.int
reset()
rewind()
setAutoExpand
(boolean autoExpand) Turns on or off autoExpand.void
setPooled
(boolean pooled) Sets whether this buffer is returned back to the buffer pool when released.skip
(int size) Forwards the position of this buffer as the specifiedsize
bytes.slice()
sweep()
Clears this buffer and fills its content with NUL.sweep
(byte value) Clears this buffer and fills its content with value.toString()
Methods inherited from class org.apache.mina.common.ByteBuffer
allocate, allocate, autoExpand, autoExpand, getAllocator, isUseDirectBuffers, prefixedDataAvailable, prefixedDataAvailable, setAllocator, setUseDirectBuffers, wrap, wrap, wrap
-
Field Details
-
buf
The buffer proxied by this proxy.
-
-
Constructor Details
-
ByteBufferProxy
Create a new instance.- Parameters:
buf
- the buffer to be proxied
-
-
Method Details
-
acquire
public void acquire()Description copied from class:ByteBuffer
Increases the internal reference count of this buffer to defer automatic release. You have to invokeByteBuffer.release()
as many as you invoked this method to release this buffer.- Specified by:
acquire
in classByteBuffer
-
release
public void release()Description copied from class:ByteBuffer
Releases the specified buffer to buffer pool.- Specified by:
release
in classByteBuffer
-
isDirect
public boolean isDirect()- Specified by:
isDirect
in classByteBuffer
- See Also:
-
buf
Description copied from class:ByteBuffer
Returns the underlying NIO buffer instance.- Specified by:
buf
in classByteBuffer
-
capacity
public int capacity()- Specified by:
capacity
in classByteBuffer
- See Also:
-
position
public int position()- Specified by:
position
in classByteBuffer
- See Also:
-
position
- Specified by:
position
in classByteBuffer
- See Also:
-
limit
public int limit()- Specified by:
limit
in classByteBuffer
- See Also:
-
limit
- Specified by:
limit
in classByteBuffer
- See Also:
-
mark
- Specified by:
mark
in classByteBuffer
- See Also:
-
reset
- Specified by:
reset
in classByteBuffer
- See Also:
-
clear
- Specified by:
clear
in classByteBuffer
- See Also:
-
sweep
Description copied from class:ByteBuffer
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.- Overrides:
sweep
in classByteBuffer
-
sweep
Description copied from class:ByteBuffer
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.- Overrides:
sweep
in classByteBuffer
-
flip
- Specified by:
flip
in classByteBuffer
- See Also:
-
rewind
- Specified by:
rewind
in classByteBuffer
- See Also:
-
remaining
public int remaining()- Overrides:
remaining
in classByteBuffer
- See Also:
-
hasRemaining
public boolean hasRemaining()- Overrides:
hasRemaining
in classByteBuffer
- See Also:
-
get
public byte get()- Specified by:
get
in classByteBuffer
- See Also:
-
getUnsigned
public short getUnsigned()Description copied from class:ByteBuffer
Reads one unsigned byte as a short integer.- Overrides:
getUnsigned
in classByteBuffer
-
put
- Specified by:
put
in classByteBuffer
- See Also:
-
get
public byte get(int index) - Specified by:
get
in classByteBuffer
- See Also:
-
getUnsigned
public short getUnsigned(int index) Description copied from class:ByteBuffer
Reads one byte as an unsigned short integer.- Overrides:
getUnsigned
in classByteBuffer
-
put
- Specified by:
put
in classByteBuffer
- See Also:
-
get
- Specified by:
get
in classByteBuffer
- See Also:
-
get
- Overrides:
get
in classByteBuffer
- See Also:
-
put
Description copied from class:ByteBuffer
Writes the content of the specified src into this buffer.- Overrides:
put
in classByteBuffer
-
put
Description copied from class:ByteBuffer
Writes the content of the specified src into this buffer.- Specified by:
put
in classByteBuffer
-
put
- Specified by:
put
in classByteBuffer
- See Also:
-
put
- Overrides:
put
in classByteBuffer
- See Also:
-
compact
- Specified by:
compact
in classByteBuffer
- See Also:
-
toString
- Overrides:
toString
in classByteBuffer
-
hashCode
public int hashCode()- Overrides:
hashCode
in classByteBuffer
-
equals
- Overrides:
equals
in classByteBuffer
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ByteBuffer>
- Overrides:
compareTo
in classByteBuffer
-
order
- Specified by:
order
in classByteBuffer
- See Also:
-
order
- Specified by:
order
in classByteBuffer
- See Also:
-
getChar
public char getChar()- Specified by:
getChar
in classByteBuffer
- See Also:
-
putChar
- Specified by:
putChar
in classByteBuffer
- See Also:
-
getChar
public char getChar(int index) - Specified by:
getChar
in classByteBuffer
- See Also:
-
putChar
- Specified by:
putChar
in classByteBuffer
- See Also:
-
asCharBuffer
- Specified by:
asCharBuffer
in classByteBuffer
- See Also:
-
getShort
public short getShort()- Specified by:
getShort
in classByteBuffer
- See Also:
-
getUnsignedShort
public int getUnsignedShort()Description copied from class:ByteBuffer
Reads two bytes unsigned integer.- Overrides:
getUnsignedShort
in classByteBuffer
-
putShort
- Specified by:
putShort
in classByteBuffer
- See Also:
-
getShort
public short getShort(int index) - Specified by:
getShort
in classByteBuffer
- See Also:
-
getUnsignedShort
public int getUnsignedShort(int index) Description copied from class:ByteBuffer
Reads two bytes unsigned integer.- Overrides:
getUnsignedShort
in classByteBuffer
-
putShort
- Specified by:
putShort
in classByteBuffer
- See Also:
-
asShortBuffer
- Specified by:
asShortBuffer
in classByteBuffer
- See Also:
-
getInt
public int getInt()- Specified by:
getInt
in classByteBuffer
- See Also:
-
getUnsignedInt
public long getUnsignedInt()Description copied from class:ByteBuffer
Reads four bytes unsigned integer.- Overrides:
getUnsignedInt
in classByteBuffer
-
putInt
- Specified by:
putInt
in classByteBuffer
- See Also:
-
getInt
public int getInt(int index) - Specified by:
getInt
in classByteBuffer
- See Also:
-
getUnsignedInt
public long getUnsignedInt(int index) Description copied from class:ByteBuffer
Reads four bytes unsigned integer.- Overrides:
getUnsignedInt
in classByteBuffer
-
putInt
- Specified by:
putInt
in classByteBuffer
- See Also:
-
asIntBuffer
- Specified by:
asIntBuffer
in classByteBuffer
- See Also:
-
getLong
public long getLong()- Specified by:
getLong
in classByteBuffer
- See Also:
-
putLong
- Specified by:
putLong
in classByteBuffer
- See Also:
-
getLong
public long getLong(int index) - Specified by:
getLong
in classByteBuffer
- See Also:
-
putLong
- Specified by:
putLong
in classByteBuffer
- See Also:
-
asLongBuffer
- Specified by:
asLongBuffer
in classByteBuffer
- See Also:
-
getFloat
public float getFloat()- Specified by:
getFloat
in classByteBuffer
- See Also:
-
putFloat
- Specified by:
putFloat
in classByteBuffer
- See Also:
-
getFloat
public float getFloat(int index) - Specified by:
getFloat
in classByteBuffer
- See Also:
-
putFloat
- Specified by:
putFloat
in classByteBuffer
- See Also:
-
asFloatBuffer
- Specified by:
asFloatBuffer
in classByteBuffer
- See Also:
-
getDouble
public double getDouble()- Specified by:
getDouble
in classByteBuffer
- See Also:
-
putDouble
- Specified by:
putDouble
in classByteBuffer
- See Also:
-
getDouble
public double getDouble(int index) - Specified by:
getDouble
in classByteBuffer
- See Also:
-
putDouble
- Specified by:
putDouble
in classByteBuffer
- See Also:
-
asDoubleBuffer
- Specified by:
asDoubleBuffer
in classByteBuffer
- See Also:
-
getHexDump
Description copied from class:ByteBuffer
Returns hexdump of this buffer.- Overrides:
getHexDump
in classByteBuffer
-
getString
Description copied from class:ByteBuffer
Reads aNUL
-terminated string from this buffer using the specifieddecoder
and returns it.- Overrides:
getString
in classByteBuffer
- Parameters:
fieldSize
- the maximum number of bytes to read- Throws:
CharacterCodingException
-
getString
Description copied from class:ByteBuffer
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.- Overrides:
getString
in classByteBuffer
- Throws:
CharacterCodingException
-
getPrefixedString
Description copied from class:ByteBuffer
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).- Overrides:
getPrefixedString
in classByteBuffer
- Throws:
CharacterCodingException
-
getPrefixedString
public String getPrefixedString(int prefixLength, CharsetDecoder decoder) throws CharacterCodingException Description copied from class:ByteBuffer
Reads a string which has a length field before the actual encoded string, using the specifieddecoder
and returns it.- Overrides:
getPrefixedString
in classByteBuffer
- Parameters:
prefixLength
- the length of the length field (1, 2, or 4)- Throws:
CharacterCodingException
-
putString
public ByteBuffer putString(CharSequence in, int fieldSize, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBuffer
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.- Overrides:
putString
in classByteBuffer
- Parameters:
fieldSize
- the maximum number of bytes to write- Throws:
CharacterCodingException
-
putString
public ByteBuffer putString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBuffer
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.- Overrides:
putString
in classByteBuffer
- Throws:
CharacterCodingException
-
putPrefixedString
public ByteBuffer putPrefixedString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBuffer
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).- Overrides:
putPrefixedString
in classByteBuffer
- Throws:
CharacterCodingException
-
putPrefixedString
public ByteBuffer putPrefixedString(CharSequence in, int prefixLength, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBuffer
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).- Overrides:
putPrefixedString
in classByteBuffer
- Parameters:
prefixLength
- the length of the length field (1, 2, or 4)- Throws:
CharacterCodingException
-
putPrefixedString
public ByteBuffer putPrefixedString(CharSequence in, int prefixLength, int padding, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBuffer
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).- Overrides:
putPrefixedString
in classByteBuffer
- 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 ByteBuffer putPrefixedString(CharSequence in, int prefixLength, int padding, byte padValue, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBuffer
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
.- Overrides:
putPrefixedString
in classByteBuffer
- 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
-
skip
Description copied from class:ByteBuffer
Forwards the position of this buffer as the specifiedsize
bytes.- Overrides:
skip
in classByteBuffer
-
fill
Description copied from class:ByteBuffer
Fills this buffer with the specified value. This method moves buffer position forward.- Overrides:
fill
in classByteBuffer
-
fillAndReset
Description copied from class:ByteBuffer
Fills this buffer with the specified value. This method does not change buffer position.- Overrides:
fillAndReset
in classByteBuffer
-
fill
Description copied from class:ByteBuffer
Fills this buffer withNUL (0x00)
. This method moves buffer position forward.- Overrides:
fill
in classByteBuffer
-
fillAndReset
Description copied from class:ByteBuffer
Fills this buffer withNUL (0x00)
. This method does not change buffer position.- Overrides:
fillAndReset
in classByteBuffer
-
isAutoExpand
public boolean isAutoExpand()Description copied from class:ByteBuffer
Returns true if and only if autoExpand is turned on.- Specified by:
isAutoExpand
in classByteBuffer
-
setAutoExpand
Description copied from class:ByteBuffer
Turns on or off autoExpand.- Specified by:
setAutoExpand
in classByteBuffer
-
expand
Description copied from class:ByteBuffer
Changes the capacity and limit of this buffer so this buffer get the specified expectedRemaining room from the specified pos. This method works even if you didn't set autoExpand to true.- Specified by:
expand
in classByteBuffer
-
expand
Description copied from class:ByteBuffer
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.- Overrides:
expand
in classByteBuffer
-
isPooled
public boolean isPooled()Description copied from class:ByteBuffer
Returns true if and only if this buffer is returned back to the buffer pool when released.The default value of this property is true if and only if you allocated this buffer using
ByteBuffer.allocate(int)
orByteBuffer.allocate(int, boolean)
, or false otherwise. (i.e.ByteBuffer.wrap(byte[])
,ByteBuffer.wrap(byte[], int, int)
, andByteBuffer.wrap(java.nio.ByteBuffer)
)- Specified by:
isPooled
in classByteBuffer
-
setPooled
public void setPooled(boolean pooled) Description copied from class:ByteBuffer
Sets whether this buffer is returned back to the buffer pool when released.The default value of this property is true if and only if you allocated this buffer using
ByteBuffer.allocate(int)
orByteBuffer.allocate(int, boolean)
, or false otherwise. (i.e.ByteBuffer.wrap(byte[])
,ByteBuffer.wrap(byte[], int, int)
, andByteBuffer.wrap(java.nio.ByteBuffer)
)- Specified by:
setPooled
in classByteBuffer
-
getObject
Description copied from class:ByteBuffer
Reads a Java object from the buffer using the contextClassLoader
of the current thread.- Overrides:
getObject
in classByteBuffer
- Throws:
ClassNotFoundException
-
getObject
Description copied from class:ByteBuffer
Reads a Java object from the buffer using the specified classLoader.- Overrides:
getObject
in classByteBuffer
- Throws:
ClassNotFoundException
-
putObject
Description copied from class:ByteBuffer
Writes the specified Java object to the buffer.- Overrides:
putObject
in classByteBuffer
-
asInputStream
Description copied from class:ByteBuffer
Returns anInputStream
that reads the data from this buffer.InputStream.read()
returns -1 if the buffer position reaches to the limit.- Overrides:
asInputStream
in classByteBuffer
-
asOutputStream
Description copied from class:ByteBuffer
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 callingByteBuffer.setAutoExpand(boolean)
to prevent the unexpected runtime exception.- Overrides:
asOutputStream
in classByteBuffer
-
duplicate
- Specified by:
duplicate
in classByteBuffer
- See Also:
-
slice
- Specified by:
slice
in classByteBuffer
- See Also:
-
asReadOnlyBuffer
- Specified by:
asReadOnlyBuffer
in classByteBuffer
- See Also:
-
array
public byte[] array()- Specified by:
array
in classByteBuffer
- See Also:
-
arrayOffset
public int arrayOffset()- Specified by:
arrayOffset
in classByteBuffer
- See Also:
-
capacity
Description copied from class:ByteBuffer
Changes the capacity of this buffer.- Specified by:
capacity
in classByteBuffer
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnly
in classByteBuffer
- See Also:
-
markValue
public int markValue()Description copied from class:ByteBuffer
Returns the position of the current mark. This method returns -1 if no mark is set.- Specified by:
markValue
in classByteBuffer
-