net.sf.cindy.buffer
Class DelegateBuffer

java.lang.Object
  extended by net.sf.cindy.buffer.DelegateBuffer
All Implemented Interfaces:
Buffer

public class DelegateBuffer
extends java.lang.Object
implements Buffer

Delegate buffer.

Version:
$id$
Author:
Roger Chen

Field Summary
protected  Buffer delegate
          Delegate buffer.
 
Constructor Summary
DelegateBuffer(Buffer delegate)
           
 
Method Summary
 java.nio.ByteBuffer asByteBuffer()
          Creates a view of this buffer as a byte buffer.
 Buffer asReadOnlyBuffer()
           
 int capacity()
           
 Buffer clear()
           
 Buffer compact()
           
 java.lang.String dump()
          Dump current buffer to string.
 Buffer duplicate()
           
 Buffer flip()
           
 byte get()
           
 Buffer get(Buffer dst)
           
 Buffer get(Buffer dst, int length)
           
 Buffer get(byte[] dst)
           
 Buffer get(byte[] dst, int offset, int length)
           
 Buffer get(java.nio.ByteBuffer dst)
           
 Buffer get(java.nio.ByteBuffer dst, int length)
           
 byte get(int index)
           
 Buffer get(int index, Buffer dst)
           
 Buffer get(int index, Buffer dst, int length)
           
 Buffer get(int index, byte[] dst)
           
 Buffer get(int index, byte[] dst, int offset, int length)
           
 Buffer get(int index, java.nio.ByteBuffer dst)
           
 Buffer get(int index, java.nio.ByteBuffer dst, int length)
           
 char getChar()
           
 char getChar(int index)
           
 Buffer getDelegate()
           
 double getDouble()
           
 double getDouble(int index)
           
 float getFloat()
           
 float getFloat(int index)
           
 int getInt()
           
 int getInt(int index)
           
 long getLong()
           
 long getLong(int index)
           
 short getShort()
           
 short getShort(int index)
           
 java.lang.String getString(Charset charset, int bufferLen)
           
 java.lang.String getString(int index, Charset charset, int bufferLen)
           
 short getUnsignedByte()
           
 short getUnsignedByte(int index)
           
 long getUnsignedInt()
           
 long getUnsignedInt(int index)
           
 int getUnsignedShort()
           
 int getUnsignedShort(int index)
           
 boolean hasRemaining()
           
 int indexOf(byte[] b)
           
 boolean isBigEndian()
           
 boolean isDirect()
           
 boolean isPermanent()
          Return this buffer is permanent.
 boolean isReadonly()
           
 boolean isReleased()
          Current buffer's content have been released.
 int limit()
           
 Buffer limit(int limit)
           
 Buffer mark()
           
 int position()
           
 Buffer position(int position)
           
 Buffer put(Buffer src)
           
 Buffer put(Buffer src, int length)
           
 Buffer put(byte b)
           
 Buffer put(byte[] src)
           
 Buffer put(byte[] src, int offset, int length)
           
 Buffer put(java.nio.ByteBuffer src)
           
 Buffer put(java.nio.ByteBuffer src, int length)
           
 Buffer put(int index, Buffer src)
           
 Buffer put(int index, Buffer src, int length)
           
 Buffer put(int index, byte b)
           
 Buffer put(int index, byte[] src)
           
 Buffer put(int index, byte[] src, int offset, int length)
           
 Buffer put(int index, java.nio.ByteBuffer src)
           
 Buffer put(int index, java.nio.ByteBuffer src, int length)
           
 Buffer putChar(char c)
           
 Buffer putChar(int index, char c)
           
 Buffer putDouble(double d)
           
 Buffer putDouble(int index, double d)
           
 Buffer putFloat(float f)
           
 Buffer putFloat(int index, float f)
           
 Buffer putInt(int i)
           
 Buffer putInt(int index, int i)
           
 Buffer putLong(int index, long l)
           
 Buffer putLong(long l)
           
 Buffer putShort(int index, short s)
           
 Buffer putShort(short s)
           
 Buffer putString(int index, java.lang.String s, Charset charset)
           
 Buffer putString(java.lang.String s, Charset charset)
           
 Buffer putUnsignedByte(int index, short s)
           
 Buffer putUnsignedByte(short s)
           
 Buffer putUnsignedInt(int index, long l)
           
 Buffer putUnsignedInt(long l)
           
 Buffer putUnsignedShort(int i)
           
 Buffer putUnsignedShort(int index, int i)
           
 int read(java.nio.channels.ReadableByteChannel channel)
          Reads a sequence of bytes from the channel.
 void release()
          Release this buffer's content if not permanent.
 int remaining()
           
 Buffer reset()
           
 Buffer rewind()
           
 Buffer setBigEndian(boolean b)
           
 void setPermanent(boolean b)
          Set current buffer is permanent.
 Buffer skip(int size)
          This method is a shorthand for: position(position() + size).
 Buffer slice()
           
 int write(java.nio.channels.WritableByteChannel channel)
          Writes a sequence of bytes to the channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

protected final Buffer delegate
Delegate buffer.

Constructor Detail

DelegateBuffer

public DelegateBuffer(Buffer delegate)
Method Detail

getDelegate

public Buffer getDelegate()

asByteBuffer

public java.nio.ByteBuffer asByteBuffer()
Description copied from interface: Buffer
Creates a view of this buffer as a byte buffer. The returned byte buffer's position/limit/capacity equals current position/limit/capacity. The returned ByteBuffer MAY share the content of the Buffer, depends on implementation.

Specified by:
asByteBuffer in interface Buffer
Returns:
the byte buffer

asReadOnlyBuffer

public Buffer asReadOnlyBuffer()
Specified by:
asReadOnlyBuffer in interface Buffer

capacity

public int capacity()
Specified by:
capacity in interface Buffer

clear

public Buffer clear()
Specified by:
clear in interface Buffer

compact

public Buffer compact()
Specified by:
compact in interface Buffer

dump

public java.lang.String dump()
Description copied from interface: Buffer
Dump current buffer to string. Help debug.

Specified by:
dump in interface Buffer
Returns:
string

duplicate

public Buffer duplicate()
Specified by:
duplicate in interface Buffer

flip

public Buffer flip()
Specified by:
flip in interface Buffer

get

public byte get()
Specified by:
get in interface Buffer

get

public Buffer get(Buffer dst,
                  int length)
Specified by:
get in interface Buffer

get

public Buffer get(Buffer dst)
Specified by:
get in interface Buffer

get

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

get

public Buffer get(byte[] dst)
Specified by:
get in interface Buffer

get

public Buffer get(java.nio.ByteBuffer dst,
                  int length)
Specified by:
get in interface Buffer

get

public Buffer get(java.nio.ByteBuffer dst)
Specified by:
get in interface Buffer

get

public Buffer get(int index,
                  Buffer dst,
                  int length)
Specified by:
get in interface Buffer

get

public Buffer get(int index,
                  Buffer dst)
Specified by:
get in interface Buffer

get

public Buffer get(int index,
                  byte[] dst,
                  int offset,
                  int length)
Specified by:
get in interface Buffer

get

public Buffer get(int index,
                  byte[] dst)
Specified by:
get in interface Buffer

get

public Buffer get(int index,
                  java.nio.ByteBuffer dst,
                  int length)
Specified by:
get in interface Buffer

get

public Buffer get(int index,
                  java.nio.ByteBuffer dst)
Specified by:
get in interface Buffer

get

public byte get(int index)
Specified by:
get in interface Buffer

getChar

public char getChar()
Specified by:
getChar in interface Buffer

getChar

public char getChar(int index)
Specified by:
getChar in interface Buffer

getDouble

public double getDouble()
Specified by:
getDouble in interface Buffer

getDouble

public double getDouble(int index)
Specified by:
getDouble in interface Buffer

getFloat

public float getFloat()
Specified by:
getFloat in interface Buffer

getFloat

public float getFloat(int index)
Specified by:
getFloat in interface Buffer

getInt

public int getInt()
Specified by:
getInt in interface Buffer

getInt

public int getInt(int index)
Specified by:
getInt in interface Buffer

getLong

public long getLong()
Specified by:
getLong in interface Buffer

getLong

public long getLong(int index)
Specified by:
getLong in interface Buffer

getShort

public short getShort()
Specified by:
getShort in interface Buffer

getShort

public short getShort(int index)
Specified by:
getShort in interface Buffer

getString

public java.lang.String getString(Charset charset,
                                  int bufferLen)
Specified by:
getString in interface Buffer

getString

public java.lang.String getString(int index,
                                  Charset charset,
                                  int bufferLen)
Specified by:
getString in interface Buffer

getUnsignedByte

public short getUnsignedByte()
Specified by:
getUnsignedByte in interface Buffer

getUnsignedByte

public short getUnsignedByte(int index)
Specified by:
getUnsignedByte in interface Buffer

getUnsignedInt

public long getUnsignedInt()
Specified by:
getUnsignedInt in interface Buffer

getUnsignedInt

public long getUnsignedInt(int index)
Specified by:
getUnsignedInt in interface Buffer

getUnsignedShort

public int getUnsignedShort()
Specified by:
getUnsignedShort in interface Buffer

getUnsignedShort

public int getUnsignedShort(int index)
Specified by:
getUnsignedShort in interface Buffer

hasRemaining

public boolean hasRemaining()
Specified by:
hasRemaining in interface Buffer

indexOf

public int indexOf(byte[] b)
Specified by:
indexOf in interface Buffer

isBigEndian

public boolean isBigEndian()
Specified by:
isBigEndian in interface Buffer

isDirect

public boolean isDirect()
Specified by:
isDirect in interface Buffer

isPermanent

public boolean isPermanent()
Description copied from interface: Buffer
Return this buffer is permanent. Permanent buffer can't be released.

Specified by:
isPermanent in interface Buffer
Returns:
is permanent

isReadonly

public boolean isReadonly()
Specified by:
isReadonly in interface Buffer

isReleased

public boolean isReleased()
Description copied from interface: Buffer
Current buffer's content have been released.

Specified by:
isReleased in interface Buffer
Returns:
released

limit

public int limit()
Specified by:
limit in interface Buffer

limit

public Buffer limit(int limit)
Specified by:
limit in interface Buffer

mark

public Buffer mark()
Specified by:
mark in interface Buffer

position

public int position()
Specified by:
position in interface Buffer

position

public Buffer position(int position)
Specified by:
position in interface Buffer

put

public Buffer put(Buffer src,
                  int length)
Specified by:
put in interface Buffer

put

public Buffer put(Buffer src)
Specified by:
put in interface Buffer

put

public Buffer put(byte b)
Specified by:
put in interface Buffer

put

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

put

public Buffer put(byte[] src)
Specified by:
put in interface Buffer

put

public Buffer put(java.nio.ByteBuffer src,
                  int length)
Specified by:
put in interface Buffer

put

public Buffer put(java.nio.ByteBuffer src)
Specified by:
put in interface Buffer

put

public Buffer put(int index,
                  Buffer src,
                  int length)
Specified by:
put in interface Buffer

put

public Buffer put(int index,
                  Buffer src)
Specified by:
put in interface Buffer

put

public Buffer put(int index,
                  byte b)
Specified by:
put in interface Buffer

put

public Buffer put(int index,
                  byte[] src,
                  int offset,
                  int length)
Specified by:
put in interface Buffer

put

public Buffer put(int index,
                  byte[] src)
Specified by:
put in interface Buffer

put

public Buffer put(int index,
                  java.nio.ByteBuffer src,
                  int length)
Specified by:
put in interface Buffer

put

public Buffer put(int index,
                  java.nio.ByteBuffer src)
Specified by:
put in interface Buffer

putChar

public Buffer putChar(char c)
Specified by:
putChar in interface Buffer

putChar

public Buffer putChar(int index,
                      char c)
Specified by:
putChar in interface Buffer

putDouble

public Buffer putDouble(double d)
Specified by:
putDouble in interface Buffer

putDouble

public Buffer putDouble(int index,
                        double d)
Specified by:
putDouble in interface Buffer

putFloat

public Buffer putFloat(float f)
Specified by:
putFloat in interface Buffer

putFloat

public Buffer putFloat(int index,
                       float f)
Specified by:
putFloat in interface Buffer

putInt

public Buffer putInt(int index,
                     int i)
Specified by:
putInt in interface Buffer

putInt

public Buffer putInt(int i)
Specified by:
putInt in interface Buffer

putLong

public Buffer putLong(int index,
                      long l)
Specified by:
putLong in interface Buffer

putLong

public Buffer putLong(long l)
Specified by:
putLong in interface Buffer

putShort

public Buffer putShort(int index,
                       short s)
Specified by:
putShort in interface Buffer

putShort

public Buffer putShort(short s)
Specified by:
putShort in interface Buffer

putString

public Buffer putString(int index,
                        java.lang.String s,
                        Charset charset)
Specified by:
putString in interface Buffer

putString

public Buffer putString(java.lang.String s,
                        Charset charset)
Specified by:
putString in interface Buffer

putUnsignedByte

public Buffer putUnsignedByte(int index,
                              short s)
Specified by:
putUnsignedByte in interface Buffer

putUnsignedByte

public Buffer putUnsignedByte(short s)
Specified by:
putUnsignedByte in interface Buffer

putUnsignedInt

public Buffer putUnsignedInt(int index,
                             long l)
Specified by:
putUnsignedInt in interface Buffer

putUnsignedInt

public Buffer putUnsignedInt(long l)
Specified by:
putUnsignedInt in interface Buffer

putUnsignedShort

public Buffer putUnsignedShort(int index,
                               int i)
Specified by:
putUnsignedShort in interface Buffer

putUnsignedShort

public Buffer putUnsignedShort(int i)
Specified by:
putUnsignedShort in interface Buffer

read

public int read(java.nio.channels.ReadableByteChannel channel)
         throws java.io.IOException
Description copied from interface: Buffer
Reads a sequence of bytes from the channel.

Specified by:
read in interface Buffer
Parameters:
channel - channel
Returns:
the number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream
Throws:
java.io.IOException - any io exception

release

public void release()
Description copied from interface: Buffer
Release this buffer's content if not permanent.

Specified by:
release in interface Buffer

remaining

public int remaining()
Specified by:
remaining in interface Buffer

reset

public Buffer reset()
Specified by:
reset in interface Buffer

rewind

public Buffer rewind()
Specified by:
rewind in interface Buffer

setBigEndian

public Buffer setBigEndian(boolean b)
Specified by:
setBigEndian in interface Buffer

setPermanent

public void setPermanent(boolean b)
Description copied from interface: Buffer
Set current buffer is permanent. Permanent buffer can't be released.

Specified by:
setPermanent in interface Buffer
Parameters:
b - permanent

skip

public Buffer skip(int size)
Description copied from interface: Buffer
This method is a shorthand for: position(position() + size).

Specified by:
skip in interface Buffer
Parameters:
size - skip size
Returns:
the byte buffer

slice

public Buffer slice()
Specified by:
slice in interface Buffer

write

public int write(java.nio.channels.WritableByteChannel channel)
          throws java.io.IOException
Description copied from interface: Buffer
Writes a sequence of bytes to the channel.

Specified by:
write in interface Buffer
Parameters:
channel - channel
Returns:
the number of bytes written, possibly zero
Throws:
java.io.IOException - any io exception