net.sf.cindy.buffer
Class AbstractBuffer

java.lang.Object
  extended by net.sf.cindy.buffer.AbstractBuffer
All Implemented Interfaces:
Buffer
Direct Known Subclasses:
ByteArrayBuffer, ByteBufferBuffer, LinkedBuffer

public abstract class AbstractBuffer
extends java.lang.Object
implements Buffer

Abstract buffer.

Version:
$id$
Author:
Roger Chen

Field Summary
protected static int WRITE_PACKET_SIZE
           
 
Constructor Summary
protected AbstractBuffer(int offset, int capacity)
           
 
Method Summary
protected abstract  byte _get(int index)
          Get byte without check.
protected abstract  void _put(int index, byte b)
          Put byte without check.
protected abstract  void _release()
           
 Buffer asReadOnlyBuffer()
           
 int capacity()
           
protected  Buffer capacity(int newCapacity)
           
protected static void checkBounds(int off, int len, int size)
           
protected  void checkReadonly()
           
protected  void checkReleased()
           
 Buffer clear()
           
 java.lang.String dump()
          Dump current buffer to string.
 boolean equals(java.lang.Object obj)
           
 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)
           
 double getDouble()
           
 double getDouble(int index)
           
 float getFloat()
           
 float getFloat(int index)
           
protected  int getIndex(int len)
           
protected  int getIndex(int i, int len)
           
 int getInt()
           
 int getInt(int index)
           
 long getLong()
           
 long getLong(int index)
           
protected  int getMark()
           
 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 isPermanent()
          Return this buffer is permanent.
 boolean isReadonly()
           
 boolean isReleased()
          Current buffer's content have been released.
 int limit()
           
 Buffer limit(int newLimit)
           
 Buffer mark()
           
protected  Buffer mark(int mark)
           
 int position()
           
 Buffer position(int newPosition)
           
 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)
           
protected  int putIndex(int len)
           
protected  int putIndex(int i, int len)
           
 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 bigEndian)
           
 void setPermanent(boolean b)
          Set current buffer is permanent.
protected  Buffer setReadonly(boolean readonly)
           
 Buffer skip(int size)
          This method is a shorthand for: position(position() + size).
 java.lang.String toString()
           
 int write(java.nio.channels.WritableByteChannel channel)
          Writes a sequence of bytes to the channel.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.cindy.Buffer
asByteBuffer, compact, duplicate, isDirect, slice
 

Field Detail

WRITE_PACKET_SIZE

protected static final int WRITE_PACKET_SIZE
Constructor Detail

AbstractBuffer

protected AbstractBuffer(int offset,
                         int capacity)
Method Detail

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

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

isReleased

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

Specified by:
isReleased in interface Buffer
Returns:
released

release

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

Specified by:
release in interface Buffer

_release

protected abstract void _release()

isReadonly

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

setReadonly

protected Buffer setReadonly(boolean readonly)

isBigEndian

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

setBigEndian

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

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

capacity

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

capacity

protected Buffer capacity(int newCapacity)

limit

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

limit

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

position

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

position

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

mark

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

mark

protected Buffer mark(int mark)

getMark

protected int getMark()

getIndex

protected final int getIndex(int i,
                             int len)

getIndex

protected final int getIndex(int len)

putIndex

protected final int putIndex(int i,
                             int len)

putIndex

protected final int putIndex(int len)

checkBounds

protected static final void checkBounds(int off,
                                        int len,
                                        int size)

checkReadonly

protected final void checkReadonly()

checkReleased

protected final void checkReleased()

reset

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

clear

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

flip

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

rewind

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

remaining

public int remaining()
Specified by:
remaining 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

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

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

asReadOnlyBuffer

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

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

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

_put

protected abstract void _put(int index,
                             byte b)
Put byte without check.

Parameters:
index - index
b - byte

_get

protected abstract byte _get(int index)
Get byte without check.

Parameters:
index - index
Returns:
byte

get

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

get

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

get

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

get

public Buffer get(int index,
                  byte[] 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(int index,
                  byte[] dst,
                  int offset,
                  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,
                  java.nio.ByteBuffer 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(int index,
                  java.nio.ByteBuffer 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(int index,
                  Buffer dst)
Specified by:
get in interface Buffer

get

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

get

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

put

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

put

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

put

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

put

public Buffer put(int index,
                  byte[] src)
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(int index,
                  byte[] src,
                  int offset,
                  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,
                  java.nio.ByteBuffer 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(int index,
                  java.nio.ByteBuffer 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(int index,
                  Buffer src)
Specified by:
put in interface Buffer

put

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

put

public Buffer put(int index,
                  Buffer src,
                  int length)
Specified by:
put 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

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

getShort

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

getShort

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

putShort

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

putShort

public Buffer putShort(int index,
                       short s)
Specified by:
putShort 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

putInt

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

putInt

public Buffer putInt(int index,
                     int i)
Specified by:
putInt 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

putLong

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

putLong

public Buffer putLong(int index,
                      long l)
Specified by:
putLong 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

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

getDouble

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

getDouble

public double getDouble(int index)
Specified by:
getDouble 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

getUnsignedByte

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

getUnsignedByte

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

putUnsignedByte

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

putUnsignedByte

public Buffer putUnsignedByte(int index,
                              short s)
Specified by:
putUnsignedByte 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

putUnsignedShort

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

putUnsignedShort

public Buffer putUnsignedShort(int index,
                               int i)
Specified by:
putUnsignedShort 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

putUnsignedInt

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

putUnsignedInt

public Buffer putUnsignedInt(int index,
                             long l)
Specified by:
putUnsignedInt 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

putString

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

putString

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