net.sf.cindy
Interface Buffer

All Known Implementing Classes:
AbstractBuffer, ByteArrayBuffer, ByteBufferBuffer, DelegateBuffer, LinkedBuffer

public interface Buffer

A replacement for java.nio.ByteBuffer.

Advantage:

Buffers are not safe for use by multiple concurrent threads. If a buffer is to be used by more than one thread then access to the buffer should be controlled by appropriate synchronization.

Version:
$id$
Author:
Roger Chen

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

Method Detail

asByteBuffer

java.nio.ByteBuffer asByteBuffer()
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.

Returns:
the byte buffer

isPermanent

boolean isPermanent()
Return this buffer is permanent. Permanent buffer can't be released.

Returns:
is permanent

setPermanent

void setPermanent(boolean b)
Set current buffer is permanent. Permanent buffer can't be released.

Parameters:
b - permanent

release

void release()
Release this buffer's content if not permanent.


isReleased

boolean isReleased()
Current buffer's content have been released.

Returns:
released

write

int write(java.nio.channels.WritableByteChannel channel)
          throws java.io.IOException
Writes a sequence of bytes to the channel.

Parameters:
channel - channel
Returns:
the number of bytes written, possibly zero
Throws:
java.io.IOException - any io exception

read

int read(java.nio.channels.ReadableByteChannel channel)
         throws java.io.IOException
Reads a sequence of bytes from the channel.

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

skip

Buffer skip(int size)
This method is a shorthand for: position(position() + size).

Parameters:
size - skip size
Returns:
the byte buffer

dump

java.lang.String dump()
Dump current buffer to string. Help debug.

Returns:
string

capacity

int capacity()

position

int position()

position

Buffer position(int position)

limit

int limit()

limit

Buffer limit(int limit)

mark

Buffer mark()

reset

Buffer reset()

clear

Buffer clear()

flip

Buffer flip()

rewind

Buffer rewind()

remaining

int remaining()

hasRemaining

boolean hasRemaining()

isReadonly

boolean isReadonly()

isBigEndian

boolean isBigEndian()

setBigEndian

Buffer setBigEndian(boolean b)

isDirect

boolean isDirect()

compact

Buffer compact()

slice

Buffer slice()

duplicate

Buffer duplicate()

asReadOnlyBuffer

Buffer asReadOnlyBuffer()

get

byte get()

get

byte get(int index)

get

Buffer get(byte[] dst)

get

Buffer get(int index,
           byte[] dst)

get

Buffer get(byte[] dst,
           int offset,
           int length)

get

Buffer get(int index,
           byte[] dst,
           int offset,
           int length)

get

Buffer get(java.nio.ByteBuffer dst)

get

Buffer get(java.nio.ByteBuffer dst,
           int length)

get

Buffer get(int index,
           java.nio.ByteBuffer dst)

get

Buffer get(int index,
           java.nio.ByteBuffer dst,
           int length)

get

Buffer get(Buffer dst)

get

Buffer get(Buffer dst,
           int length)

get

Buffer get(int index,
           Buffer dst)

get

Buffer get(int index,
           Buffer dst,
           int length)

put

Buffer put(byte b)

put

Buffer put(int index,
           byte b)

put

Buffer put(java.nio.ByteBuffer src)

put

Buffer put(java.nio.ByteBuffer src,
           int length)

put

Buffer put(int index,
           java.nio.ByteBuffer src)

put

Buffer put(int index,
           java.nio.ByteBuffer src,
           int length)

put

Buffer put(Buffer src)

put

Buffer put(Buffer src,
           int length)

put

Buffer put(int index,
           Buffer src)

put

Buffer put(int index,
           Buffer src,
           int length)

put

Buffer put(byte[] src)

put

Buffer put(byte[] src,
           int offset,
           int length)

put

Buffer put(int index,
           byte[] src)

put

Buffer put(int index,
           byte[] src,
           int offset,
           int length)

getChar

char getChar()

putChar

Buffer putChar(char c)

getChar

char getChar(int index)

putChar

Buffer putChar(int index,
               char c)

getShort

short getShort()

putShort

Buffer putShort(short s)

getShort

short getShort(int index)

putShort

Buffer putShort(int index,
                short s)

getInt

int getInt()

putInt

Buffer putInt(int i)

getInt

int getInt(int index)

putInt

Buffer putInt(int index,
              int i)

getLong

long getLong()

putLong

Buffer putLong(long l)

getLong

long getLong(int index)

putLong

Buffer putLong(int index,
               long l)

getFloat

float getFloat()

putFloat

Buffer putFloat(float f)

getFloat

float getFloat(int index)

putFloat

Buffer putFloat(int index,
                float f)

getDouble

double getDouble()

putDouble

Buffer putDouble(double d)

getDouble

double getDouble(int index)

putDouble

Buffer putDouble(int index,
                 double d)

getUnsignedByte

short getUnsignedByte()

getUnsignedByte

short getUnsignedByte(int index)

putUnsignedByte

Buffer putUnsignedByte(short s)

putUnsignedByte

Buffer putUnsignedByte(int index,
                       short s)

getUnsignedShort

int getUnsignedShort()

getUnsignedShort

int getUnsignedShort(int index)

putUnsignedShort

Buffer putUnsignedShort(int i)

putUnsignedShort

Buffer putUnsignedShort(int index,
                        int i)

getUnsignedInt

long getUnsignedInt()

getUnsignedInt

long getUnsignedInt(int index)

putUnsignedInt

Buffer putUnsignedInt(long l)

putUnsignedInt

Buffer putUnsignedInt(int index,
                      long l)

getString

java.lang.String getString(Charset charset,
                           int bufferLen)

putString

Buffer putString(java.lang.String s,
                 Charset charset)

getString

java.lang.String getString(int index,
                           Charset charset,
                           int bufferLen)

putString

Buffer putString(int index,
                 java.lang.String s,
                 Charset charset)

indexOf

int indexOf(byte[] b)