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 TypeMethodDescriptionvoidacquire()Increases the internal reference count of this buffer to defer automatic release.byte[]array()intReturns anInputStreamthat reads the data from this buffer.Returns anOutputStreamthat appends the data into this buffer.buf()Returns the underlying NIO buffer instance.intcapacity()capacity(int newCapacity) Changes the capacity of this buffer.clear()compact()intcompareTo(ByteBuffer that) booleanexpand(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()byteget()get(byte[] dst) get(byte[] dst, int offset, int length) byteget(int index) chargetChar()chargetChar(int index) doubledoublegetDouble(int index) floatgetFloat()floatgetFloat(int index) Returns hexdump of this buffer.intgetInt()intgetInt(int index) longgetLong()longgetLong(int index) Reads a Java object from the buffer using the contextClassLoaderof 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 specifieddecoderand returns it.getPrefixedString(CharsetDecoder decoder) Reads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoderand returns it.shortgetShort()shortgetShort(int index) getString(int fieldSize, CharsetDecoder decoder) Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.getString(CharsetDecoder decoder) Reads aNUL-terminated string from this buffer using the specifieddecoderand returns it.shortReads one unsigned byte as a short integer.shortgetUnsigned(int index) Reads one byte as an unsigned short integer.longReads four bytes unsigned integer.longgetUnsignedInt(int index) Reads four bytes unsigned integer.intReads two bytes unsigned integer.intgetUnsignedShort(int index) Reads two bytes unsigned integer.inthashCode()booleanbooleanReturns true if and only if autoExpand is turned on.booleanisDirect()booleanisPooled()Returns true if and only if this buffer is returned back to the buffer pool when released.booleanintlimit()limit(int newLimit) mark()intReturns the position of the current mark.order()intposition()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 ofininto 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 ofininto 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 ofininto 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 ofininto 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 ofininto this buffer as aNUL-terminated string using the specifiedencoder.putString(CharSequence in, CharsetEncoder encoder) Writes the content ofininto this buffer using the specifiedencoder.voidrelease()Releases the specified buffer to buffer pool.intreset()rewind()setAutoExpand(boolean autoExpand) Turns on or off autoExpand.voidsetPooled(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 specifiedsizebytes.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:ByteBufferIncreases 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:
acquirein classByteBuffer
-
release
public void release()Description copied from class:ByteBufferReleases the specified buffer to buffer pool.- Specified by:
releasein classByteBuffer
-
isDirect
public boolean isDirect()- Specified by:
isDirectin classByteBuffer- See Also:
-
buf
Description copied from class:ByteBufferReturns the underlying NIO buffer instance.- Specified by:
bufin classByteBuffer
-
capacity
public int capacity()- Specified by:
capacityin classByteBuffer- See Also:
-
position
public int position()- Specified by:
positionin classByteBuffer- See Also:
-
position
- Specified by:
positionin classByteBuffer- See Also:
-
limit
public int limit()- Specified by:
limitin classByteBuffer- See Also:
-
limit
- Specified by:
limitin classByteBuffer- See Also:
-
mark
- Specified by:
markin classByteBuffer- See Also:
-
reset
- Specified by:
resetin classByteBuffer- See Also:
-
clear
- Specified by:
clearin classByteBuffer- See Also:
-
sweep
Description copied from class:ByteBufferClears 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:
sweepin classByteBuffer
-
sweep
Description copied from class:ByteBufferClears 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:
sweepin classByteBuffer
-
flip
- Specified by:
flipin classByteBuffer- See Also:
-
rewind
- Specified by:
rewindin classByteBuffer- See Also:
-
remaining
public int remaining()- Overrides:
remainingin classByteBuffer- See Also:
-
hasRemaining
public boolean hasRemaining()- Overrides:
hasRemainingin classByteBuffer- See Also:
-
get
public byte get()- Specified by:
getin classByteBuffer- See Also:
-
getUnsigned
public short getUnsigned()Description copied from class:ByteBufferReads one unsigned byte as a short integer.- Overrides:
getUnsignedin classByteBuffer
-
put
- Specified by:
putin classByteBuffer- See Also:
-
get
public byte get(int index) - Specified by:
getin classByteBuffer- See Also:
-
getUnsigned
public short getUnsigned(int index) Description copied from class:ByteBufferReads one byte as an unsigned short integer.- Overrides:
getUnsignedin classByteBuffer
-
put
- Specified by:
putin classByteBuffer- See Also:
-
get
- Specified by:
getin classByteBuffer- See Also:
-
get
- Overrides:
getin classByteBuffer- See Also:
-
put
Description copied from class:ByteBufferWrites the content of the specified src into this buffer.- Overrides:
putin classByteBuffer
-
put
Description copied from class:ByteBufferWrites the content of the specified src into this buffer.- Specified by:
putin classByteBuffer
-
put
- Specified by:
putin classByteBuffer- See Also:
-
put
- Overrides:
putin classByteBuffer- See Also:
-
compact
- Specified by:
compactin classByteBuffer- See Also:
-
toString
- Overrides:
toStringin classByteBuffer
-
hashCode
public int hashCode()- Overrides:
hashCodein classByteBuffer
-
equals
- Overrides:
equalsin classByteBuffer
-
compareTo
- Specified by:
compareToin interfaceComparable<ByteBuffer>- Overrides:
compareToin classByteBuffer
-
order
- Specified by:
orderin classByteBuffer- See Also:
-
order
- Specified by:
orderin classByteBuffer- See Also:
-
getChar
public char getChar()- Specified by:
getCharin classByteBuffer- See Also:
-
putChar
- Specified by:
putCharin classByteBuffer- See Also:
-
getChar
public char getChar(int index) - Specified by:
getCharin classByteBuffer- See Also:
-
putChar
- Specified by:
putCharin classByteBuffer- See Also:
-
asCharBuffer
- Specified by:
asCharBufferin classByteBuffer- See Also:
-
getShort
public short getShort()- Specified by:
getShortin classByteBuffer- See Also:
-
getUnsignedShort
public int getUnsignedShort()Description copied from class:ByteBufferReads two bytes unsigned integer.- Overrides:
getUnsignedShortin classByteBuffer
-
putShort
- Specified by:
putShortin classByteBuffer- See Also:
-
getShort
public short getShort(int index) - Specified by:
getShortin classByteBuffer- See Also:
-
getUnsignedShort
public int getUnsignedShort(int index) Description copied from class:ByteBufferReads two bytes unsigned integer.- Overrides:
getUnsignedShortin classByteBuffer
-
putShort
- Specified by:
putShortin classByteBuffer- See Also:
-
asShortBuffer
- Specified by:
asShortBufferin classByteBuffer- See Also:
-
getInt
public int getInt()- Specified by:
getIntin classByteBuffer- See Also:
-
getUnsignedInt
public long getUnsignedInt()Description copied from class:ByteBufferReads four bytes unsigned integer.- Overrides:
getUnsignedIntin classByteBuffer
-
putInt
- Specified by:
putIntin classByteBuffer- See Also:
-
getInt
public int getInt(int index) - Specified by:
getIntin classByteBuffer- See Also:
-
getUnsignedInt
public long getUnsignedInt(int index) Description copied from class:ByteBufferReads four bytes unsigned integer.- Overrides:
getUnsignedIntin classByteBuffer
-
putInt
- Specified by:
putIntin classByteBuffer- See Also:
-
asIntBuffer
- Specified by:
asIntBufferin classByteBuffer- See Also:
-
getLong
public long getLong()- Specified by:
getLongin classByteBuffer- See Also:
-
putLong
- Specified by:
putLongin classByteBuffer- See Also:
-
getLong
public long getLong(int index) - Specified by:
getLongin classByteBuffer- See Also:
-
putLong
- Specified by:
putLongin classByteBuffer- See Also:
-
asLongBuffer
- Specified by:
asLongBufferin classByteBuffer- See Also:
-
getFloat
public float getFloat()- Specified by:
getFloatin classByteBuffer- See Also:
-
putFloat
- Specified by:
putFloatin classByteBuffer- See Also:
-
getFloat
public float getFloat(int index) - Specified by:
getFloatin classByteBuffer- See Also:
-
putFloat
- Specified by:
putFloatin classByteBuffer- See Also:
-
asFloatBuffer
- Specified by:
asFloatBufferin classByteBuffer- See Also:
-
getDouble
public double getDouble()- Specified by:
getDoublein classByteBuffer- See Also:
-
putDouble
- Specified by:
putDoublein classByteBuffer- See Also:
-
getDouble
public double getDouble(int index) - Specified by:
getDoublein classByteBuffer- See Also:
-
putDouble
- Specified by:
putDoublein classByteBuffer- See Also:
-
asDoubleBuffer
- Specified by:
asDoubleBufferin classByteBuffer- See Also:
-
getHexDump
Description copied from class:ByteBufferReturns hexdump of this buffer.- Overrides:
getHexDumpin classByteBuffer
-
getString
Description copied from class:ByteBufferReads aNUL-terminated string from this buffer using the specifieddecoderand returns it.- Overrides:
getStringin classByteBuffer- Parameters:
fieldSize- the maximum number of bytes to read- Throws:
CharacterCodingException
-
getString
Description copied from class:ByteBufferReads aNUL-terminated string from this buffer using the specifieddecoderand returns it. This method reads until the limit of this buffer if no NUL is found.- Overrides:
getStringin classByteBuffer- Throws:
CharacterCodingException
-
getPrefixedString
Description copied from class:ByteBufferReads a string which has a 16-bit length field before the actual encoded string, using the specifieddecoderand returns it. This method is a shortcut for getPrefixedString(2, decoder).- Overrides:
getPrefixedStringin classByteBuffer- Throws:
CharacterCodingException
-
getPrefixedString
public String getPrefixedString(int prefixLength, CharsetDecoder decoder) throws CharacterCodingException Description copied from class:ByteBufferReads a string which has a length field before the actual encoded string, using the specifieddecoderand returns it.- Overrides:
getPrefixedStringin 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:ByteBufferWrites the content ofininto 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 twoNULs as a terminator.Please note that this method doesn't terminate with
NULif the input string is longer than fieldSize.- Overrides:
putStringin classByteBufferfieldSize- the maximum number of bytes to write- Throws:
CharacterCodingException
-
putString
public ByteBuffer putString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBufferWrites the content ofininto this buffer using the specifiedencoder. This method doesn't terminate string with NUL. You have to do it by yourself.- Overrides:
putStringin classByteBuffer- Throws:
CharacterCodingException
-
putPrefixedString
public ByteBuffer putPrefixedString(CharSequence in, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBufferWrites the content ofininto 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:
putPrefixedStringin classByteBuffer- Throws:
CharacterCodingException
-
putPrefixedString
public ByteBuffer putPrefixedString(CharSequence in, int prefixLength, CharsetEncoder encoder) throws CharacterCodingException Description copied from class:ByteBufferWrites the content ofininto 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:
putPrefixedStringin classByteBufferprefixLength- 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:ByteBufferWrites the content ofininto 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:
putPrefixedStringin classByteBufferprefixLength- 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:ByteBufferWrites the content ofininto this buffer as a string which has a 16-bit length field before the actual encoded string, using the specifiedencoder.- Overrides:
putPrefixedStringin classByteBufferprefixLength- 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:ByteBufferForwards the position of this buffer as the specifiedsizebytes.- Overrides:
skipin classByteBuffer
-
fill
Description copied from class:ByteBufferFills this buffer with the specified value. This method moves buffer position forward.- Overrides:
fillin classByteBuffer
-
fillAndReset
Description copied from class:ByteBufferFills this buffer with the specified value. This method does not change buffer position.- Overrides:
fillAndResetin classByteBuffer
-
fill
Description copied from class:ByteBufferFills this buffer withNUL (0x00). This method moves buffer position forward.- Overrides:
fillin classByteBuffer
-
fillAndReset
Description copied from class:ByteBufferFills this buffer withNUL (0x00). This method does not change buffer position.- Overrides:
fillAndResetin classByteBuffer
-
isAutoExpand
public boolean isAutoExpand()Description copied from class:ByteBufferReturns true if and only if autoExpand is turned on.- Specified by:
isAutoExpandin classByteBuffer
-
setAutoExpand
Description copied from class:ByteBufferTurns on or off autoExpand.- Specified by:
setAutoExpandin classByteBuffer
-
expand
Description copied from class:ByteBufferChanges 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:
expandin classByteBuffer
-
expand
Description copied from class:ByteBufferChanges 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:
expandin classByteBuffer
-
isPooled
public boolean isPooled()Description copied from class:ByteBufferReturns 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:
isPooledin classByteBuffer
-
setPooled
public void setPooled(boolean pooled) Description copied from class:ByteBufferSets 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:
setPooledin classByteBuffer
-
getObject
Description copied from class:ByteBufferReads a Java object from the buffer using the contextClassLoaderof the current thread.- Overrides:
getObjectin classByteBuffer- Throws:
ClassNotFoundException
-
getObject
Description copied from class:ByteBufferReads a Java object from the buffer using the specified classLoader.- Overrides:
getObjectin classByteBuffer- Throws:
ClassNotFoundException
-
putObject
Description copied from class:ByteBufferWrites the specified Java object to the buffer.- Overrides:
putObjectin classByteBuffer
-
asInputStream
Description copied from class:ByteBufferReturns anInputStreamthat reads the data from this buffer.InputStream.read()returns -1 if the buffer position reaches to the limit.- Overrides:
asInputStreamin classByteBuffer
-
asOutputStream
Description copied from class:ByteBufferReturns anOutputStreamthat appends the data into this buffer. Please note that theOutputStream.write(int)will throw aBufferOverflowExceptioninstead of anIOExceptionin case of buffer overflow. Please set autoExpand property by callingByteBuffer.setAutoExpand(boolean)to prevent the unexpected runtime exception.- Overrides:
asOutputStreamin classByteBuffer
-
duplicate
- Specified by:
duplicatein classByteBuffer- See Also:
-
slice
- Specified by:
slicein classByteBuffer- See Also:
-
asReadOnlyBuffer
- Specified by:
asReadOnlyBufferin classByteBuffer- See Also:
-
array
public byte[] array()- Specified by:
arrayin classByteBuffer- See Also:
-
arrayOffset
public int arrayOffset()- Specified by:
arrayOffsetin classByteBuffer- See Also:
-
capacity
Description copied from class:ByteBufferChanges the capacity of this buffer.- Specified by:
capacityin classByteBuffer
-
isReadOnly
public boolean isReadOnly()- Specified by:
isReadOnlyin classByteBuffer- See Also:
-
markValue
public int markValue()Description copied from class:ByteBufferReturns the position of the current mark. This method returns -1 if no mark is set.- Specified by:
markValuein classByteBuffer
-