public class ByteBufferProxy extends 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.
| Modifier and Type | Field and Description |
|---|---|
protected ByteBuffer |
buf
The buffer proxied by this proxy.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ByteBufferProxy(ByteBuffer buf)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
acquire()
Increases the internal reference count of this buffer to defer
automatic release.
|
byte[] |
array() |
int |
arrayOffset() |
java.nio.CharBuffer |
asCharBuffer() |
java.nio.DoubleBuffer |
asDoubleBuffer() |
java.nio.FloatBuffer |
asFloatBuffer() |
java.io.InputStream |
asInputStream()
Returns an
InputStream that reads the data from this buffer. |
java.nio.IntBuffer |
asIntBuffer() |
java.nio.LongBuffer |
asLongBuffer() |
java.io.OutputStream |
asOutputStream()
Returns an
OutputStream that appends the data into this buffer. |
ByteBuffer |
asReadOnlyBuffer() |
java.nio.ShortBuffer |
asShortBuffer() |
java.nio.ByteBuffer |
buf()
Returns the underlying NIO buffer instance.
|
int |
capacity() |
ByteBuffer |
capacity(int newCapacity)
Changes the capacity of this buffer.
|
ByteBuffer |
clear() |
ByteBuffer |
compact() |
int |
compareTo(ByteBuffer that) |
ByteBuffer |
duplicate() |
boolean |
equals(java.lang.Object ob) |
ByteBuffer |
expand(int expectedRemaining)
Changes the capacity and limit of this buffer so this buffer get
the specified expectedRemaining room from the current position.
|
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). |
ByteBuffer |
flip() |
byte |
get() |
ByteBuffer |
get(byte[] dst) |
ByteBuffer |
get(byte[] dst,
int offset,
int length) |
byte |
get(int index) |
char |
getChar() |
char |
getChar(int index) |
double |
getDouble() |
double |
getDouble(int index) |
float |
getFloat() |
float |
getFloat(int index) |
java.lang.String |
getHexDump()
Returns hexdump of this buffer.
|
int |
getInt() |
int |
getInt(int index) |
long |
getLong() |
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. |
short |
getShort() |
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() |
boolean |
isAutoExpand()
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 |
isReadOnly() |
int |
limit() |
ByteBuffer |
limit(int newLimit) |
ByteBuffer |
mark() |
int |
markValue()
Returns the position of the current mark.
|
java.nio.ByteOrder |
order() |
ByteBuffer |
order(java.nio.ByteOrder bo) |
int |
position() |
ByteBuffer |
position(int newPosition) |
ByteBuffer |
put(byte b) |
ByteBuffer |
put(byte[] src) |
ByteBuffer |
put(byte[] src,
int offset,
int length) |
ByteBuffer |
put(ByteBuffer src)
Writes the content of the specified src into this buffer.
|
ByteBuffer |
put(java.nio.ByteBuffer src)
Writes the content of the specified src into this buffer.
|
ByteBuffer |
put(int index,
byte b) |
ByteBuffer |
putChar(char value) |
ByteBuffer |
putChar(int index,
char value) |
ByteBuffer |
putDouble(double value) |
ByteBuffer |
putDouble(int index,
double value) |
ByteBuffer |
putFloat(float value) |
ByteBuffer |
putFloat(int index,
float value) |
ByteBuffer |
putInt(int value) |
ByteBuffer |
putInt(int index,
int value) |
ByteBuffer |
putLong(int index,
long value) |
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 in,
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. |
ByteBuffer |
putShort(int index,
short value) |
ByteBuffer |
putShort(short value) |
ByteBuffer |
putString(java.lang.CharSequence in,
java.nio.charset.CharsetEncoder encoder)
Writes the content of
in into this buffer using the
specified encoder. |
ByteBuffer |
putString(java.lang.CharSequence in,
int fieldSize,
java.nio.charset.CharsetEncoder encoder)
Writes the content of
in into this buffer as a
NUL-terminated string using the specified
encoder. |
void |
release()
Releases the specified buffer to buffer pool.
|
int |
remaining() |
ByteBuffer |
reset() |
ByteBuffer |
rewind() |
ByteBuffer |
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.
|
ByteBuffer |
skip(int size)
Forwards the position of this buffer as the specified
size
bytes. |
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() |
allocate, allocate, autoExpand, autoExpand, getAllocator, isUseDirectBuffers, prefixedDataAvailable, prefixedDataAvailable, setAllocator, setUseDirectBuffers, wrap, wrap, wrapprotected ByteBuffer buf
protected ByteBufferProxy(ByteBuffer buf)
buf - the buffer to be proxiedpublic void acquire()
ByteBufferByteBuffer.release() as many
as you invoked this method to release this buffer.acquire in class ByteBufferpublic void release()
ByteBufferrelease in class ByteBufferpublic boolean isDirect()
isDirect in class ByteBufferByteBuffer.isDirect()public java.nio.ByteBuffer buf()
ByteBufferbuf in class ByteBufferpublic int capacity()
capacity in class ByteBufferBuffer.capacity()public int position()
position in class ByteBufferBuffer.position()public ByteBuffer position(int newPosition)
position in class ByteBufferBuffer.position(int)public int limit()
limit in class ByteBufferBuffer.limit()public ByteBuffer limit(int newLimit)
limit in class ByteBufferBuffer.limit(int)public ByteBuffer mark()
mark in class ByteBufferBuffer.mark()public ByteBuffer reset()
reset in class ByteBufferBuffer.reset()public ByteBuffer clear()
clear in class ByteBufferBuffer.clear()public ByteBuffer sweep()
ByteBuffersweep in class ByteBufferpublic ByteBuffer sweep(byte value)
ByteBuffersweep in class ByteBufferpublic ByteBuffer flip()
flip in class ByteBufferBuffer.flip()public ByteBuffer rewind()
rewind in class ByteBufferBuffer.rewind()public int remaining()
remaining in class ByteBufferBuffer.remaining()public boolean hasRemaining()
hasRemaining in class ByteBufferBuffer.hasRemaining()public byte get()
get in class ByteBufferByteBuffer.get()public short getUnsigned()
ByteBuffergetUnsigned in class ByteBufferpublic ByteBuffer put(byte b)
put in class ByteBufferByteBuffer.put(byte)public byte get(int index)
get in class ByteBufferByteBuffer.get(int)public short getUnsigned(int index)
ByteBuffergetUnsigned in class ByteBufferpublic ByteBuffer put(int index, byte b)
put in class ByteBufferByteBuffer.put(int, byte)public ByteBuffer get(byte[] dst, int offset, int length)
get in class ByteBufferByteBuffer.get(byte[], int, int)public ByteBuffer get(byte[] dst)
get in class ByteBufferByteBuffer.get(byte[])public ByteBuffer put(ByteBuffer src)
ByteBufferput in class ByteBufferpublic ByteBuffer put(java.nio.ByteBuffer src)
ByteBufferput in class ByteBufferpublic ByteBuffer put(byte[] src, int offset, int length)
put in class ByteBufferByteBuffer.put(byte[], int, int)public ByteBuffer put(byte[] src)
put in class ByteBufferByteBuffer.put(byte[])public ByteBuffer compact()
compact in class ByteBufferByteBuffer.compact()public java.lang.String toString()
toString in class ByteBufferpublic int hashCode()
hashCode in class ByteBufferpublic boolean equals(java.lang.Object ob)
equals in class ByteBufferpublic int compareTo(ByteBuffer that)
compareTo in interface java.lang.Comparable<ByteBuffer>compareTo in class ByteBufferpublic java.nio.ByteOrder order()
order in class ByteBufferByteBuffer.order()public ByteBuffer order(java.nio.ByteOrder bo)
order in class ByteBufferByteBuffer.order(ByteOrder)public char getChar()
getChar in class ByteBufferByteBuffer.getChar()public ByteBuffer putChar(char value)
putChar in class ByteBufferByteBuffer.putChar(char)public char getChar(int index)
getChar in class ByteBufferByteBuffer.getChar(int)public ByteBuffer putChar(int index, char value)
putChar in class ByteBufferByteBuffer.putChar(int, char)public java.nio.CharBuffer asCharBuffer()
asCharBuffer in class ByteBufferByteBuffer.asCharBuffer()public short getShort()
getShort in class ByteBufferByteBuffer.getShort()public int getUnsignedShort()
ByteBuffergetUnsignedShort in class ByteBufferpublic ByteBuffer putShort(short value)
putShort in class ByteBufferByteBuffer.putShort(short)public short getShort(int index)
getShort in class ByteBufferByteBuffer.getShort()public int getUnsignedShort(int index)
ByteBuffergetUnsignedShort in class ByteBufferpublic ByteBuffer putShort(int index, short value)
putShort in class ByteBufferByteBuffer.putShort(int, short)public java.nio.ShortBuffer asShortBuffer()
asShortBuffer in class ByteBufferByteBuffer.asShortBuffer()public int getInt()
getInt in class ByteBufferByteBuffer.getInt()public long getUnsignedInt()
ByteBuffergetUnsignedInt in class ByteBufferpublic ByteBuffer putInt(int value)
putInt in class ByteBufferByteBuffer.putInt(int)public int getInt(int index)
getInt in class ByteBufferByteBuffer.getInt(int)public long getUnsignedInt(int index)
ByteBuffergetUnsignedInt in class ByteBufferpublic ByteBuffer putInt(int index, int value)
putInt in class ByteBufferByteBuffer.putInt(int, int)public java.nio.IntBuffer asIntBuffer()
asIntBuffer in class ByteBufferByteBuffer.asIntBuffer()public long getLong()
getLong in class ByteBufferByteBuffer.getLong()public ByteBuffer putLong(long value)
putLong in class ByteBufferByteBuffer.putLong(int, long)public long getLong(int index)
getLong in class ByteBufferByteBuffer.getLong(int)public ByteBuffer putLong(int index, long value)
putLong in class ByteBufferByteBuffer.putLong(int, long)public java.nio.LongBuffer asLongBuffer()
asLongBuffer in class ByteBufferByteBuffer.asLongBuffer()public float getFloat()
getFloat in class ByteBufferByteBuffer.getFloat()public ByteBuffer putFloat(float value)
putFloat in class ByteBufferByteBuffer.putFloat(float)public float getFloat(int index)
getFloat in class ByteBufferByteBuffer.getFloat(int)public ByteBuffer putFloat(int index, float value)
putFloat in class ByteBufferByteBuffer.putFloat(int, float)public java.nio.FloatBuffer asFloatBuffer()
asFloatBuffer in class ByteBufferByteBuffer.asFloatBuffer()public double getDouble()
getDouble in class ByteBufferByteBuffer.getDouble()public ByteBuffer putDouble(double value)
putDouble in class ByteBufferByteBuffer.putDouble(double)public double getDouble(int index)
getDouble in class ByteBufferByteBuffer.getDouble(int)public ByteBuffer putDouble(int index, double value)
putDouble in class ByteBufferByteBuffer.putDouble(int, double)public java.nio.DoubleBuffer asDoubleBuffer()
asDoubleBuffer in class ByteBufferByteBuffer.asDoubleBuffer()public java.lang.String getHexDump()
ByteBuffergetHexDump in class ByteBufferpublic java.lang.String getString(int fieldSize,
java.nio.charset.CharsetDecoder decoder)
throws java.nio.charset.CharacterCodingException
ByteBufferNUL-terminated string from this buffer using the
specified decoder and returns it.getString in class ByteBufferfieldSize - the maximum number of bytes to readjava.nio.charset.CharacterCodingExceptionpublic java.lang.String getString(java.nio.charset.CharsetDecoder decoder)
throws java.nio.charset.CharacterCodingException
ByteBufferNUL-terminated string from this buffer using the
specified decoder and returns it. This method reads
until the limit of this buffer if no NUL is found.getString in class ByteBufferjava.nio.charset.CharacterCodingExceptionpublic java.lang.String getPrefixedString(java.nio.charset.CharsetDecoder decoder)
throws java.nio.charset.CharacterCodingException
ByteBufferdecoder and returns it.
This method is a shortcut for getPrefixedString(2, decoder).getPrefixedString in class ByteBufferjava.nio.charset.CharacterCodingExceptionpublic java.lang.String getPrefixedString(int prefixLength,
java.nio.charset.CharsetDecoder decoder)
throws java.nio.charset.CharacterCodingException
ByteBufferdecoder and returns it.getPrefixedString in class ByteBufferprefixLength - the length of the length field (1, 2, or 4)java.nio.charset.CharacterCodingExceptionpublic ByteBuffer putString(java.lang.CharSequence in, int fieldSize, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBufferin 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
NULs as a terminator.
Please note that this method doesn't terminate with NUL
if the input string is longer than fieldSize.
putString in class ByteBufferfieldSize - the maximum number of bytes to writejava.nio.charset.CharacterCodingExceptionpublic ByteBuffer putString(java.lang.CharSequence in, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBufferin into this buffer using the
specified encoder. This method doesn't terminate
string with NUL. You have to do it by yourself.putString in class ByteBufferjava.nio.charset.CharacterCodingExceptionpublic ByteBuffer putPrefixedString(java.lang.CharSequence in, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBufferin into this buffer as a
string which has a 16-bit length field before the actual
encoded string, using the specified encoder.
This method is a shortcut for putPrefixedString(in, 2, 0, encoder).putPrefixedString in class ByteBufferjava.nio.charset.CharacterCodingExceptionpublic ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBufferin into this buffer as a
string which has a 16-bit length field before the actual
encoded string, using the specified encoder.
This method is a shortcut for putPrefixedString(in, prefixLength, 0, encoder).putPrefixedString in class ByteBufferprefixLength - the length of the length field (1, 2, or 4)java.nio.charset.CharacterCodingExceptionpublic ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, int padding, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBufferin into this buffer as a
string which has a 16-bit length field before the actual
encoded string, using the specified encoder.
This method is a shortcut for putPrefixedString(in, prefixLength, padding, ( byte ) 0, encoder).putPrefixedString in class ByteBufferprefixLength - the length of the length field (1, 2, or 4)padding - the number of padded NULs (1 (or 0), 2, or 4)java.nio.charset.CharacterCodingExceptionpublic ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, int padding, byte padValue, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBufferin into this buffer as a
string which has a 16-bit length field before the actual
encoded string, using the specified encoder.putPrefixedString in class ByteBufferprefixLength - 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.charset.CharacterCodingExceptionpublic ByteBuffer skip(int size)
ByteBuffersize
bytes.skip in class ByteBufferpublic ByteBuffer fill(byte value, int size)
ByteBufferfill in class ByteBufferpublic ByteBuffer fillAndReset(byte value, int size)
ByteBufferfillAndReset in class ByteBufferpublic ByteBuffer fill(int size)
ByteBufferNUL (0x00).
This method moves buffer position forward.fill in class ByteBufferpublic ByteBuffer fillAndReset(int size)
ByteBufferNUL (0x00).
This method does not change buffer position.fillAndReset in class ByteBufferpublic boolean isAutoExpand()
ByteBufferisAutoExpand in class ByteBufferpublic ByteBuffer setAutoExpand(boolean autoExpand)
ByteBuffersetAutoExpand in class ByteBufferpublic ByteBuffer expand(int pos, int expectedRemaining)
ByteBufferexpand in class ByteBufferpublic ByteBuffer expand(int expectedRemaining)
ByteBufferexpand in class ByteBufferpublic boolean isPooled()
ByteBuffer
The default value of this property is true if and only if you
allocated this buffer using ByteBuffer.allocate(int) or ByteBuffer.allocate(int, boolean),
or false otherwise. (i.e. ByteBuffer.wrap(byte[]), ByteBuffer.wrap(byte[], int, int),
and ByteBuffer.wrap(java.nio.ByteBuffer))
isPooled in class ByteBufferpublic void setPooled(boolean pooled)
ByteBuffer
The default value of this property is true if and only if you
allocated this buffer using ByteBuffer.allocate(int) or ByteBuffer.allocate(int, boolean),
or false otherwise. (i.e. ByteBuffer.wrap(byte[]), ByteBuffer.wrap(byte[], int, int),
and ByteBuffer.wrap(java.nio.ByteBuffer))
setPooled in class ByteBufferpublic java.lang.Object getObject()
throws java.lang.ClassNotFoundException
ByteBufferClassLoader
of the current thread.getObject in class ByteBufferjava.lang.ClassNotFoundExceptionpublic java.lang.Object getObject(java.lang.ClassLoader classLoader)
throws java.lang.ClassNotFoundException
ByteBuffergetObject in class ByteBufferjava.lang.ClassNotFoundExceptionpublic ByteBuffer putObject(java.lang.Object o)
ByteBufferputObject in class ByteBufferpublic java.io.InputStream asInputStream()
ByteBufferInputStream that reads the data from this buffer.
InputStream.read() returns -1 if the buffer position
reaches to the limit.asInputStream in class ByteBufferpublic java.io.OutputStream asOutputStream()
ByteBufferOutputStream 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 ByteBuffer.setAutoExpand(boolean) to prevent the unexpected runtime
exception.asOutputStream in class ByteBufferpublic ByteBuffer duplicate()
duplicate in class ByteBufferByteBuffer.duplicate()public ByteBuffer slice()
slice in class ByteBufferByteBuffer.slice()public ByteBuffer asReadOnlyBuffer()
asReadOnlyBuffer in class ByteBufferByteBuffer.asReadOnlyBuffer()public byte[] array()
array in class ByteBufferByteBuffer.array()public int arrayOffset()
arrayOffset in class ByteBufferByteBuffer.arrayOffset()public ByteBuffer capacity(int newCapacity)
ByteBuffercapacity in class ByteBufferpublic boolean isReadOnly()
isReadOnly in class ByteBufferBuffer.isReadOnly()public int markValue()
ByteBuffermarkValue in class ByteBuffer