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, wrap
protected ByteBuffer buf
protected ByteBufferProxy(ByteBuffer buf)
buf
- the buffer to be proxiedpublic void acquire()
ByteBuffer
ByteBuffer.release()
as many
as you invoked this method to release this buffer.acquire
in class ByteBuffer
public void release()
ByteBuffer
release
in class ByteBuffer
public boolean isDirect()
isDirect
in class ByteBuffer
ByteBuffer.isDirect()
public java.nio.ByteBuffer buf()
ByteBuffer
buf
in class ByteBuffer
public int capacity()
capacity
in class ByteBuffer
Buffer.capacity()
public int position()
position
in class ByteBuffer
Buffer.position()
public ByteBuffer position(int newPosition)
position
in class ByteBuffer
Buffer.position(int)
public int limit()
limit
in class ByteBuffer
Buffer.limit()
public ByteBuffer limit(int newLimit)
limit
in class ByteBuffer
Buffer.limit(int)
public ByteBuffer mark()
mark
in class ByteBuffer
Buffer.mark()
public ByteBuffer reset()
reset
in class ByteBuffer
Buffer.reset()
public ByteBuffer clear()
clear
in class ByteBuffer
Buffer.clear()
public ByteBuffer sweep()
ByteBuffer
sweep
in class ByteBuffer
public ByteBuffer sweep(byte value)
ByteBuffer
sweep
in class ByteBuffer
public ByteBuffer flip()
flip
in class ByteBuffer
Buffer.flip()
public ByteBuffer rewind()
rewind
in class ByteBuffer
Buffer.rewind()
public int remaining()
remaining
in class ByteBuffer
Buffer.remaining()
public boolean hasRemaining()
hasRemaining
in class ByteBuffer
Buffer.hasRemaining()
public byte get()
get
in class ByteBuffer
ByteBuffer.get()
public short getUnsigned()
ByteBuffer
getUnsigned
in class ByteBuffer
public ByteBuffer put(byte b)
put
in class ByteBuffer
ByteBuffer.put(byte)
public byte get(int index)
get
in class ByteBuffer
ByteBuffer.get(int)
public short getUnsigned(int index)
ByteBuffer
getUnsigned
in class ByteBuffer
public ByteBuffer put(int index, byte b)
put
in class ByteBuffer
ByteBuffer.put(int, byte)
public ByteBuffer get(byte[] dst, int offset, int length)
get
in class ByteBuffer
ByteBuffer.get(byte[], int, int)
public ByteBuffer get(byte[] dst)
get
in class ByteBuffer
ByteBuffer.get(byte[])
public ByteBuffer put(ByteBuffer src)
ByteBuffer
put
in class ByteBuffer
public ByteBuffer put(java.nio.ByteBuffer src)
ByteBuffer
put
in class ByteBuffer
public ByteBuffer put(byte[] src, int offset, int length)
put
in class ByteBuffer
ByteBuffer.put(byte[], int, int)
public ByteBuffer put(byte[] src)
put
in class ByteBuffer
ByteBuffer.put(byte[])
public ByteBuffer compact()
compact
in class ByteBuffer
ByteBuffer.compact()
public java.lang.String toString()
toString
in class ByteBuffer
public int hashCode()
hashCode
in class ByteBuffer
public boolean equals(java.lang.Object ob)
equals
in class ByteBuffer
public int compareTo(ByteBuffer that)
compareTo
in interface java.lang.Comparable<ByteBuffer>
compareTo
in class ByteBuffer
public java.nio.ByteOrder order()
order
in class ByteBuffer
ByteBuffer.order()
public ByteBuffer order(java.nio.ByteOrder bo)
order
in class ByteBuffer
ByteBuffer.order(ByteOrder)
public char getChar()
getChar
in class ByteBuffer
ByteBuffer.getChar()
public ByteBuffer putChar(char value)
putChar
in class ByteBuffer
ByteBuffer.putChar(char)
public char getChar(int index)
getChar
in class ByteBuffer
ByteBuffer.getChar(int)
public ByteBuffer putChar(int index, char value)
putChar
in class ByteBuffer
ByteBuffer.putChar(int, char)
public java.nio.CharBuffer asCharBuffer()
asCharBuffer
in class ByteBuffer
ByteBuffer.asCharBuffer()
public short getShort()
getShort
in class ByteBuffer
ByteBuffer.getShort()
public int getUnsignedShort()
ByteBuffer
getUnsignedShort
in class ByteBuffer
public ByteBuffer putShort(short value)
putShort
in class ByteBuffer
ByteBuffer.putShort(short)
public short getShort(int index)
getShort
in class ByteBuffer
ByteBuffer.getShort()
public int getUnsignedShort(int index)
ByteBuffer
getUnsignedShort
in class ByteBuffer
public ByteBuffer putShort(int index, short value)
putShort
in class ByteBuffer
ByteBuffer.putShort(int, short)
public java.nio.ShortBuffer asShortBuffer()
asShortBuffer
in class ByteBuffer
ByteBuffer.asShortBuffer()
public int getInt()
getInt
in class ByteBuffer
ByteBuffer.getInt()
public long getUnsignedInt()
ByteBuffer
getUnsignedInt
in class ByteBuffer
public ByteBuffer putInt(int value)
putInt
in class ByteBuffer
ByteBuffer.putInt(int)
public int getInt(int index)
getInt
in class ByteBuffer
ByteBuffer.getInt(int)
public long getUnsignedInt(int index)
ByteBuffer
getUnsignedInt
in class ByteBuffer
public ByteBuffer putInt(int index, int value)
putInt
in class ByteBuffer
ByteBuffer.putInt(int, int)
public java.nio.IntBuffer asIntBuffer()
asIntBuffer
in class ByteBuffer
ByteBuffer.asIntBuffer()
public long getLong()
getLong
in class ByteBuffer
ByteBuffer.getLong()
public ByteBuffer putLong(long value)
putLong
in class ByteBuffer
ByteBuffer.putLong(int, long)
public long getLong(int index)
getLong
in class ByteBuffer
ByteBuffer.getLong(int)
public ByteBuffer putLong(int index, long value)
putLong
in class ByteBuffer
ByteBuffer.putLong(int, long)
public java.nio.LongBuffer asLongBuffer()
asLongBuffer
in class ByteBuffer
ByteBuffer.asLongBuffer()
public float getFloat()
getFloat
in class ByteBuffer
ByteBuffer.getFloat()
public ByteBuffer putFloat(float value)
putFloat
in class ByteBuffer
ByteBuffer.putFloat(float)
public float getFloat(int index)
getFloat
in class ByteBuffer
ByteBuffer.getFloat(int)
public ByteBuffer putFloat(int index, float value)
putFloat
in class ByteBuffer
ByteBuffer.putFloat(int, float)
public java.nio.FloatBuffer asFloatBuffer()
asFloatBuffer
in class ByteBuffer
ByteBuffer.asFloatBuffer()
public double getDouble()
getDouble
in class ByteBuffer
ByteBuffer.getDouble()
public ByteBuffer putDouble(double value)
putDouble
in class ByteBuffer
ByteBuffer.putDouble(double)
public double getDouble(int index)
getDouble
in class ByteBuffer
ByteBuffer.getDouble(int)
public ByteBuffer putDouble(int index, double value)
putDouble
in class ByteBuffer
ByteBuffer.putDouble(int, double)
public java.nio.DoubleBuffer asDoubleBuffer()
asDoubleBuffer
in class ByteBuffer
ByteBuffer.asDoubleBuffer()
public java.lang.String getHexDump()
ByteBuffer
getHexDump
in class ByteBuffer
public java.lang.String getString(int fieldSize, java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
NUL
-terminated string from this buffer using the
specified decoder
and returns it.getString
in class ByteBuffer
fieldSize
- the maximum number of bytes to readjava.nio.charset.CharacterCodingException
public java.lang.String getString(java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
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.getString
in class ByteBuffer
java.nio.charset.CharacterCodingException
public java.lang.String getPrefixedString(java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
decoder
and returns it.
This method is a shortcut for getPrefixedString(2, decoder).getPrefixedString
in class ByteBuffer
java.nio.charset.CharacterCodingException
public java.lang.String getPrefixedString(int prefixLength, java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
decoder
and returns it.getPrefixedString
in class ByteBuffer
prefixLength
- the length of the length field (1, 2, or 4)java.nio.charset.CharacterCodingException
public ByteBuffer putString(java.lang.CharSequence in, int fieldSize, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
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.
putString
in class ByteBuffer
fieldSize
- the maximum number of bytes to writejava.nio.charset.CharacterCodingException
public ByteBuffer putString(java.lang.CharSequence in, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
in
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 ByteBuffer
java.nio.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence in, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
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).putPrefixedString
in class ByteBuffer
java.nio.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
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).putPrefixedString
in class ByteBuffer
prefixLength
- the length of the length field (1, 2, or 4)java.nio.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, int padding, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
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).putPrefixedString
in class ByteBuffer
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.charset.CharacterCodingException
public ByteBuffer putPrefixedString(java.lang.CharSequence in, int prefixLength, int padding, byte padValue, java.nio.charset.CharsetEncoder encoder) throws java.nio.charset.CharacterCodingException
ByteBuffer
in
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 ByteBuffer
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.charset.CharacterCodingException
public ByteBuffer skip(int size)
ByteBuffer
size
bytes.skip
in class ByteBuffer
public ByteBuffer fill(byte value, int size)
ByteBuffer
fill
in class ByteBuffer
public ByteBuffer fillAndReset(byte value, int size)
ByteBuffer
fillAndReset
in class ByteBuffer
public ByteBuffer fill(int size)
ByteBuffer
NUL (0x00)
.
This method moves buffer position forward.fill
in class ByteBuffer
public ByteBuffer fillAndReset(int size)
ByteBuffer
NUL (0x00)
.
This method does not change buffer position.fillAndReset
in class ByteBuffer
public boolean isAutoExpand()
ByteBuffer
isAutoExpand
in class ByteBuffer
public ByteBuffer setAutoExpand(boolean autoExpand)
ByteBuffer
setAutoExpand
in class ByteBuffer
public ByteBuffer expand(int pos, int expectedRemaining)
ByteBuffer
expand
in class ByteBuffer
public ByteBuffer expand(int expectedRemaining)
ByteBuffer
expand
in class ByteBuffer
public 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 ByteBuffer
public 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 ByteBuffer
public java.lang.Object getObject() throws java.lang.ClassNotFoundException
ByteBuffer
ClassLoader
of the current thread.getObject
in class ByteBuffer
java.lang.ClassNotFoundException
public java.lang.Object getObject(java.lang.ClassLoader classLoader) throws java.lang.ClassNotFoundException
ByteBuffer
getObject
in class ByteBuffer
java.lang.ClassNotFoundException
public ByteBuffer putObject(java.lang.Object o)
ByteBuffer
putObject
in class ByteBuffer
public java.io.InputStream asInputStream()
ByteBuffer
InputStream
that reads the data from this buffer.
InputStream.read()
returns -1 if the buffer position
reaches to the limit.asInputStream
in class ByteBuffer
public java.io.OutputStream asOutputStream()
ByteBuffer
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 ByteBuffer.setAutoExpand(boolean)
to prevent the unexpected runtime
exception.asOutputStream
in class ByteBuffer
public ByteBuffer duplicate()
duplicate
in class ByteBuffer
ByteBuffer.duplicate()
public ByteBuffer slice()
slice
in class ByteBuffer
ByteBuffer.slice()
public ByteBuffer asReadOnlyBuffer()
asReadOnlyBuffer
in class ByteBuffer
ByteBuffer.asReadOnlyBuffer()
public byte[] array()
array
in class ByteBuffer
ByteBuffer.array()
public int arrayOffset()
arrayOffset
in class ByteBuffer
ByteBuffer.arrayOffset()
public ByteBuffer capacity(int newCapacity)
ByteBuffer
capacity
in class ByteBuffer
public boolean isReadOnly()
isReadOnly
in class ByteBuffer
Buffer.isReadOnly()
public int markValue()
ByteBuffer
markValue
in class ByteBuffer
Copyright © 2004-2019 Apache MINA Project. All Rights Reserved.