ist.palcom.base
Class ByteBuffer

java.lang.Object
  extended by ist.palcom.base.Object
      extended by ist.palcom.base.ByteBuffer
Direct Known Subclasses:
ByteArrayBuffer, MemoryByteBuffer

public class ByteBuffer
extends Object

ByteBuffer supplies a stream-like interface to manipulating byte-data. This class is an abstract superclass that has two implementations: ByteArrayBuffer and MemoryByteBuffer, that uses a ByteArray and Memory object as storage respectively.


Constructor Summary
ByteBuffer()
           
 
Method Summary
 int at(int pos)
          Returns element at specified position relative offset in this ByteBuffer.
 void clear()
          Makes this ByteBuffer ready for a new sequence of channel-read or relative put operations: It sets the limit to the capacity and the position to zero.
 void flip()
          Makes this ByteBuffer ready for a new sequence of channel-write or relative get operations: It sets the limit to the current position and then sets the position to zero.
 int get()
          Returns the next byte value at current position, and increment position.
 int getInt()
          Reads an int value (4 bytes) from current position; increments position.
 int getIntAt(int pos)
          Reads an int value (4 bytes) from specified position-relative offset.
 int getShort()
          Reads a short value (2 bytes) from current position.
 int getShortAt(int pos)
          Reads a short value (2 bytes) from specified position-relative offset.
 boolean hasRemaining()
          Tests if this buffer as remaining data.
 void init()
          Initializes this ByteBuffer.
 boolean isLittleEndian()
          Returns true if data in this ByteBuffer is stored in little endian format.
 int length()
          Returns the number of bytes in this ByteBuffer
 limit limit()
          Return the limit, which is the number of bytes that can be accessed in this ByteBuffer.
 void limit(int lim)
          Sets the limit for how much data can be written or read in this ByteBuffer.
 in position()
          Returns the position of the read/write marker in this ByteBuffer.
 void position(int pos)
          Sets the position of the read/write marker to the specified value.
 void put(int value)
          Puts value at current position; increment position.
 void putInt(int val)
          Writes an int value (4 bytes) to current position; increments position.
 void putInt(int val, int pos)
          Writes an int value (4 bytes) to specified position-relative offset.
 void putShort(int val)
          Writes a short value (2 bytes) a current position, increments position.
 void putShort(int val, int pos)
          Writes a short value (2 bytes) a specified position-relative offset.
 int remaining()
          Returns the number of bytes remaining in this ByteBuffer.
 void rewind()
          Makes this ByteBuffer ready for re-reading the data that it already contains: It leaves the limit unchanged and sets the position to zero.
 void setLittleEndian(boolean aBool)
          Changes the little-endianness of this ByteBuffer to specified boolean value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBuffer

public ByteBuffer()
Method Detail

flip

public void flip()
Makes this ByteBuffer ready for a new sequence of channel-write or relative get operations: It sets the limit to the current position and then sets the position to zero.


putInt

public void putInt(int val)
Writes an int value (4 bytes) to current position; increments position.

Parameters:
val - int int value.

putShort

public void putShort(int val,
                     int pos)
Writes a short value (2 bytes) a specified position-relative offset.

Parameters:
val - int short value
pos - int offset from position.

length

public int length()
Returns the number of bytes in this ByteBuffer

Returns:
int number of bytes.

limit

public void limit(int lim)
Sets the limit for how much data can be written or read in this ByteBuffer.

Parameters:
lim - int limit of data in this ByteBuffer.

position

public in position()
Returns the position of the read/write marker in this ByteBuffer.

Returns:
in position of read/write marker.

init

public void init()
Initializes this ByteBuffer.


putInt

public void putInt(int val,
                   int pos)
Writes an int value (4 bytes) to specified position-relative offset.

Parameters:
val - int int value.
pos - int offset from current position.

setLittleEndian

public void setLittleEndian(boolean aBool)
Changes the little-endianness of this ByteBuffer to specified boolean value.

Parameters:
aBool - boolean new value of the little-endianness property.

hasRemaining

public boolean hasRemaining()
Tests if this buffer as remaining data.

Returns:
boolean true if data remains, false otherwise.

remaining

public int remaining()
Returns the number of bytes remaining in this ByteBuffer.

Returns:
int number of bytes remaining.

isLittleEndian

public boolean isLittleEndian()
Returns true if data in this ByteBuffer is stored in little endian format.

Returns:
boolean true if little endian, false otherwise

at

public int at(int pos)
Returns element at specified position relative offset in this ByteBuffer.

Parameters:
pos - int offset from position to get value from.
Returns:
int byte value at specified relative position.

clear

public void clear()
Makes this ByteBuffer ready for a new sequence of channel-read or relative put operations: It sets the limit to the capacity and the position to zero.


get

public int get()
Returns the next byte value at current position, and increment position.

Returns:
int next byte value.

putShort

public void putShort(int val)
Writes a short value (2 bytes) a current position, increments position.

Parameters:
val - int short value

getShort

public int getShort()
Reads a short value (2 bytes) from current position. Increments position.

Returns:
int short value.

rewind

public void rewind()
Makes this ByteBuffer ready for re-reading the data that it already contains: It leaves the limit unchanged and sets the position to zero.


getInt

public int getInt()
Reads an int value (4 bytes) from current position; increments position.

Returns:
int int value.

limit

public limit limit()
Return the limit, which is the number of bytes that can be accessed in this ByteBuffer.

Returns:
limit of data in this ByteBuffer.

getShortAt

public int getShortAt(int pos)
Reads a short value (2 bytes) from specified position-relative offset.

Parameters:
pos - int offset from current position.
Returns:
int short value.

put

public void put(int value)
Puts value at current position; increment position.

Parameters:
value - int byte value to store.

position

public void position(int pos)
Sets the position of the read/write marker to the specified value.

Parameters:
pos - int new position of the read/write marker.

getIntAt

public int getIntAt(int pos)
Reads an int value (4 bytes) from specified position-relative offset.

Parameters:
pos - int offset from current position.
Returns:
int int value.