org.apache.mina.common
Class ByteBufferProxy

java.lang.Object
  extended by org.apache.mina.common.ByteBuffer
      extended by org.apache.mina.common.ByteBufferProxy

public class ByteBufferProxy
extends ByteBuffer

A 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.

Version:
$Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
Author:
The Apache Directory Project (dev@directory.apache.org)

Field Summary
protected  ByteBuffer buf
          The buffer proxied by this proxy.
 
Constructor Summary
protected ByteBufferProxy(ByteBuffer buf)
          Create a new instance.
 
Method Summary
 void acquire()
          Increases the internal reference count of this buffer to defer automatic release.
 CharBuffer asCharBuffer()
           
 DoubleBuffer asDoubleBuffer()
           
 FloatBuffer asFloatBuffer()
           
 IntBuffer asIntBuffer()
           
 LongBuffer asLongBuffer()
           
 ShortBuffer asShortBuffer()
           
 ByteBuffer buf()
          Returns the underlying NIO buffer instance.
 int capacity()
           
 ByteBuffer clear()
           
 ByteBuffer compact()
           
 int compareTo(ByteBuffer that)
           
 boolean equals(Object ob)
           
 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)
           
 String getHexDump()
          Returns hexdump of this buffer.
 int getInt()
           
 int getInt(int index)
           
 long getLong()
           
 long getLong(int index)
           
 short getShort()
           
 short getShort(int index)
           
 String getString(CharsetDecoder decoder)
          Reads a NUL-terminated string from this buffer using the specified decoder and returns it.
 String getString(int fieldSize, CharsetDecoder decoder)
          Reads a NUL-terminated string from this buffer using the specified decoder and returns it.
 short getUnsigned()
           
 short getUnsigned(int index)
           
 long getUnsignedInt()
           
 long getUnsignedInt(int index)
           
 int getUnsignedShort()
           
 int getUnsignedShort(int index)
           
 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.
 int limit()
           
 ByteBuffer limit(int newLimit)
           
 ByteBuffer mark()
           
 ByteOrder order()
           
 ByteBuffer order(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)
           
 ByteBuffer put(ByteBuffer src)
           
 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 putShort(int index, short value)
           
 ByteBuffer putShort(short value)
           
 ByteBuffer putString(CharSequence in, CharsetEncoder encoder)
          Writes the content of in into this buffer using the specified encoder.
 ByteBuffer putString(CharSequence in, int fieldSize, 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.
 String toString()
           
 
Methods inherited from class org.apache.mina.common.ByteBuffer
allocate, allocate, wrap, wrap, wrap
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

buf

protected ByteBuffer buf
The buffer proxied by this proxy.

Constructor Detail

ByteBufferProxy

protected ByteBufferProxy(ByteBuffer buf)
Create a new instance.

Parameters:
buf - the buffer to be proxied
Method Detail

acquire

public void acquire()
Description copied from class: ByteBuffer
Increases the internal reference count of this buffer to defer automatic release. You have to invoke ByteBuffer.release() as many as you invoked this method to release this buffer.

Specified by:
acquire in class ByteBuffer

release

public void release()
Description copied from class: ByteBuffer
Releases the specified buffer to buffer pool.

Specified by:
release in class ByteBuffer

isDirect

public boolean isDirect()
Specified by:
isDirect in class ByteBuffer

buf

public ByteBuffer buf()
Description copied from class: ByteBuffer
Returns the underlying NIO buffer instance.

Specified by:
buf in class ByteBuffer

capacity

public int capacity()
Specified by:
capacity in class ByteBuffer

position

public int position()
Specified by:
position in class ByteBuffer

position

public ByteBuffer position(int newPosition)
Specified by:
position in class ByteBuffer

limit

public int limit()
Specified by:
limit in class ByteBuffer

limit

public ByteBuffer limit(int newLimit)
Specified by:
limit in class ByteBuffer

mark

public ByteBuffer mark()
Specified by:
mark in class ByteBuffer

reset

public ByteBuffer reset()
Specified by:
reset in class ByteBuffer

clear

public ByteBuffer clear()
Specified by:
clear in class ByteBuffer

flip

public ByteBuffer flip()
Specified by:
flip in class ByteBuffer

rewind

public ByteBuffer rewind()
Specified by:
rewind in class ByteBuffer

remaining

public int remaining()
Specified by:
remaining in class ByteBuffer

hasRemaining

public boolean hasRemaining()
Specified by:
hasRemaining in class ByteBuffer

get

public byte get()
Specified by:
get in class ByteBuffer

getUnsigned

public short getUnsigned()
Specified by:
getUnsigned in class ByteBuffer

put

public ByteBuffer put(byte b)
Specified by:
put in class ByteBuffer

get

public byte get(int index)
Specified by:
get in class ByteBuffer

getUnsigned

public short getUnsigned(int index)
Specified by:
getUnsigned in class ByteBuffer

put

public ByteBuffer put(int index,
                      byte b)
Specified by:
put in class ByteBuffer

get

public ByteBuffer get(byte[] dst,
                      int offset,
                      int length)
Specified by:
get in class ByteBuffer

get

public ByteBuffer get(byte[] dst)
Specified by:
get in class ByteBuffer

put

public ByteBuffer put(ByteBuffer src)
Specified by:
put in class ByteBuffer

put

public ByteBuffer put(ByteBuffer src)
Specified by:
put in class ByteBuffer

put

public ByteBuffer put(byte[] src,
                      int offset,
                      int length)
Specified by:
put in class ByteBuffer

put

public ByteBuffer put(byte[] src)
Specified by:
put in class ByteBuffer

compact

public ByteBuffer compact()
Specified by:
compact in class ByteBuffer

toString

public String toString()
Specified by:
toString in class ByteBuffer

hashCode

public int hashCode()
Specified by:
hashCode in class ByteBuffer

equals

public boolean equals(Object ob)
Specified by:
equals in class ByteBuffer

compareTo

public int compareTo(ByteBuffer that)
Specified by:
compareTo in class ByteBuffer

order

public ByteOrder order()
Specified by:
order in class ByteBuffer

order

public ByteBuffer order(ByteOrder bo)
Specified by:
order in class ByteBuffer

getChar

public char getChar()
Specified by:
getChar in class ByteBuffer

putChar

public ByteBuffer putChar(char value)
Specified by:
putChar in class ByteBuffer

getChar

public char getChar(int index)
Specified by:
getChar in class ByteBuffer

putChar

public ByteBuffer putChar(int index,
                          char value)
Specified by:
putChar in class ByteBuffer

asCharBuffer

public CharBuffer asCharBuffer()
Specified by:
asCharBuffer in class ByteBuffer

getShort

public short getShort()
Specified by:
getShort in class ByteBuffer

getUnsignedShort

public int getUnsignedShort()
Specified by:
getUnsignedShort in class ByteBuffer

putShort

public ByteBuffer putShort(short value)
Specified by:
putShort in class ByteBuffer

getShort

public short getShort(int index)
Specified by:
getShort in class ByteBuffer

getUnsignedShort

public int getUnsignedShort(int index)
Specified by:
getUnsignedShort in class ByteBuffer

putShort

public ByteBuffer putShort(int index,
                           short value)
Specified by:
putShort in class ByteBuffer

asShortBuffer

public ShortBuffer asShortBuffer()
Specified by:
asShortBuffer in class ByteBuffer

getInt

public int getInt()
Specified by:
getInt in class ByteBuffer

getUnsignedInt

public long getUnsignedInt()
Specified by:
getUnsignedInt in class ByteBuffer

putInt

public ByteBuffer putInt(int value)
Specified by:
putInt in class ByteBuffer

getInt

public int getInt(int index)
Specified by:
getInt in class ByteBuffer

getUnsignedInt

public long getUnsignedInt(int index)
Specified by:
getUnsignedInt in class ByteBuffer

putInt

public ByteBuffer putInt(int index,
                         int value)
Specified by:
putInt in class ByteBuffer

asIntBuffer

public IntBuffer asIntBuffer()
Specified by:
asIntBuffer in class ByteBuffer

getLong

public long getLong()
Specified by:
getLong in class ByteBuffer

putLong

public ByteBuffer putLong(long value)
Specified by:
putLong in class ByteBuffer

getLong

public long getLong(int index)
Specified by:
getLong in class ByteBuffer

putLong

public ByteBuffer putLong(int index,
                          long value)
Specified by:
putLong in class ByteBuffer

asLongBuffer

public LongBuffer asLongBuffer()
Specified by:
asLongBuffer in class ByteBuffer

getFloat

public float getFloat()
Specified by:
getFloat in class ByteBuffer

putFloat

public ByteBuffer putFloat(float value)
Specified by:
putFloat in class ByteBuffer

getFloat

public float getFloat(int index)
Specified by:
getFloat in class ByteBuffer

putFloat

public ByteBuffer putFloat(int index,
                           float value)
Specified by:
putFloat in class ByteBuffer

asFloatBuffer

public FloatBuffer asFloatBuffer()
Specified by:
asFloatBuffer in class ByteBuffer

getDouble

public double getDouble()
Specified by:
getDouble in class ByteBuffer

putDouble

public ByteBuffer putDouble(double value)
Specified by:
putDouble in class ByteBuffer

getDouble

public double getDouble(int index)
Specified by:
getDouble in class ByteBuffer

putDouble

public ByteBuffer putDouble(int index,
                            double value)
Specified by:
putDouble in class ByteBuffer

asDoubleBuffer

public DoubleBuffer asDoubleBuffer()
Specified by:
asDoubleBuffer in class ByteBuffer

getHexDump

public String getHexDump()
Description copied from class: ByteBuffer
Returns hexdump of this buffer.

Specified by:
getHexDump in class ByteBuffer

getString

public String getString(int fieldSize,
                        CharsetDecoder decoder)
                 throws CharacterCodingException
Description copied from class: ByteBuffer
Reads a NUL-terminated string from this buffer using the specified decoder and returns it.

Specified by:
getString in class ByteBuffer
Parameters:
fieldSize - the maximum number of bytes to read
Throws:
CharacterCodingException

getString

public String getString(CharsetDecoder decoder)
                 throws CharacterCodingException
Description copied from class: ByteBuffer
Reads a 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.

Specified by:
getString in class ByteBuffer
Throws:
CharacterCodingException

putString

public ByteBuffer putString(CharSequence in,
                            int fieldSize,
                            CharsetEncoder encoder)
                     throws CharacterCodingException
Description copied from class: ByteBuffer
Writes the content of 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 NULs as a terminator.

Please note that this method doesn't terminate with NUL if the input string is longer than fieldSize.

Specified by:
putString in class ByteBuffer
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 of in into this buffer using the specified encoder. This method doesn't terminate string with NUL. You have to do it by yourself.

Specified by:
putString in class ByteBuffer
Throws:
CharacterCodingException

skip

public ByteBuffer skip(int size)
Description copied from class: ByteBuffer
Forwards the position of this buffer as the specified size bytes.

Specified by:
skip in class ByteBuffer

fill

public ByteBuffer fill(byte value,
                       int size)
Description copied from class: ByteBuffer
Fills this buffer with the specified value. This method moves buffer position forward.

Specified by:
fill in class ByteBuffer

fillAndReset

public ByteBuffer fillAndReset(byte value,
                               int size)
Description copied from class: ByteBuffer
Fills this buffer with the specified value. This method does not change buffer position.

Specified by:
fillAndReset in class ByteBuffer

fill

public ByteBuffer fill(int size)
Description copied from class: ByteBuffer
Fills this buffer with NUL (0x00). This method moves buffer position forward.

Specified by:
fill in class ByteBuffer

fillAndReset

public ByteBuffer fillAndReset(int size)
Description copied from class: ByteBuffer
Fills this buffer with NUL (0x00). This method does not change buffer position.

Specified by:
fillAndReset in class ByteBuffer

isAutoExpand

public boolean isAutoExpand()
Description copied from class: ByteBuffer
Returns true if and only if autoExpand is turned on.

Specified by:
isAutoExpand in class ByteBuffer

setAutoExpand

public ByteBuffer setAutoExpand(boolean autoExpand)
Description copied from class: ByteBuffer
Turns on or off autoExpand.

Specified by:
setAutoExpand in class ByteBuffer

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) or ByteBuffer.allocate(int, boolean), or false otherwise. (i.e. ByteBuffer.wrap(byte[]), ByteBuffer.wrap(byte[], int, int), and ByteBuffer.wrap(java.nio.ByteBuffer))

Specified by:
isPooled in class ByteBuffer

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) or ByteBuffer.allocate(int, boolean), or false otherwise. (i.e. ByteBuffer.wrap(byte[]), ByteBuffer.wrap(byte[], int, int), and ByteBuffer.wrap(java.nio.ByteBuffer))

Specified by:
setPooled in class ByteBuffer


Copyright © 2004-2005 . All Rights Reserved.