utils
Class OctetBuffer

java.lang.Object
  extended by utils.OctetBuffer

public class OctetBuffer
extends java.lang.Object

Encapsulates binary payload that can be manipulated on the octet (byte) level.


Field Summary
private  int position
          Position index
private  int sliceOffset
          Offset into backing store to enable slicing
private  byte[] store
          The octet storage
 
Constructor Summary
OctetBuffer()
           
 
Method Summary
static OctetBuffer allocate(int size)
          Allocates buffer
 byte get()
          Gets primitive 'byte' from the slice offset in the store
 void get(byte[] array)
          Gets byte[] array from the slice offset in the store
 char getChar()
          Gets primitive 'char' from the slice offset in the store
 char getChar(int offset)
          Gets primitive 'char' from the slice offset in the store
 int getFreeSpace()
          Returns remaining space
 int getInt()
          Gets primitive 'int' from the slice offset in the store
 int getPosition()
          Gets current position
 short getShort()
          Gets primitive 'short' from the slice offset in the store
 short getShort(int offset)
          Gets primitive 'short' from the offset in the store
 byte[] getStore()
          Returns internal byte[] store
 int getStoreSize()
          Returns internal byte[] store
 boolean hasFreeSpace()
          Returns true if there is free space in the store
 void put(byte value)
          Puts primitive 'byte' from the slice offset in the store
 void put(byte[] array)
          Puts byte[] array at the slice offset in the store
 void putChar(char value)
          Puts primitive 'char' at the slice offset in the store
 void putChar(int offset, char value)
          Puts primitive 'char' at the slice offset in the store
 void putInt(int value)
          Puts primitive 'int' at the slice offset in the store
 void putShort(int offset, short value)
          Puts primitive 'short' at the slice offset in the store
 void putShort(short value)
          Puts primitive 'short' at the slice offset in the store
 OctetBuffer slice()
          Slices buffer
static int toInt(byte b)
          Converts a 'byte' to an 'int'.
static OctetBuffer wrap(byte[] bs)
          Wraps existing byte[] array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

private byte[] store
The octet storage


position

private int position
Position index


sliceOffset

private int sliceOffset
Offset into backing store to enable slicing

Constructor Detail

OctetBuffer

public OctetBuffer()
Method Detail

allocate

public static OctetBuffer allocate(int size)
Allocates buffer


wrap

public static OctetBuffer wrap(byte[] bs)
Wraps existing byte[] array


slice

public OctetBuffer slice()
Slices buffer


getStore

public byte[] getStore()
Returns internal byte[] store


getStoreSize

public int getStoreSize()
Returns internal byte[] store


getPosition

public int getPosition()
Gets current position


getFreeSpace

public int getFreeSpace()
Returns remaining space


hasFreeSpace

public boolean hasFreeSpace()
Returns true if there is free space in the store


getShort

public short getShort()
Gets primitive 'short' from the slice offset in the store


getShort

public short getShort(int offset)
Gets primitive 'short' from the offset in the store


putShort

public void putShort(short value)
Puts primitive 'short' at the slice offset in the store


putShort

public void putShort(int offset,
                     short value)
Puts primitive 'short' at the slice offset in the store


getInt

public int getInt()
Gets primitive 'int' from the slice offset in the store


putInt

public void putInt(int value)
Puts primitive 'int' at the slice offset in the store


get

public byte get()
Gets primitive 'byte' from the slice offset in the store


put

public void put(byte value)
Puts primitive 'byte' from the slice offset in the store


put

public void put(byte[] array)
Puts byte[] array at the slice offset in the store


get

public void get(byte[] array)
Gets byte[] array from the slice offset in the store


putChar

public void putChar(char value)
Puts primitive 'char' at the slice offset in the store


putChar

public void putChar(int offset,
                    char value)
Puts primitive 'char' at the slice offset in the store


getChar

public char getChar()
Gets primitive 'char' from the slice offset in the store


getChar

public char getChar(int offset)
Gets primitive 'char' from the slice offset in the store


toInt

public static int toInt(byte b)
Converts a 'byte' to an 'int'.