hla.rti1516.jlc
Class ByteWrapper

java.lang.Object
  extended by hla.rti1516.jlc.ByteWrapper

public class ByteWrapper
extends Object

Utility class for managing data in byte arrays.


Constructor Summary
ByteWrapper(byte[] buffer)
          Constructs a ByteWrapper backed by the specified byte array.
ByteWrapper(byte[] buffer, int offset)
          Constructs a ByteWrapper backed by the specified byte array.
ByteWrapper(int length)
          Construct a ByteWrapper backed by a byte array with the specified length.
 
Method Summary
 void advance(int n)
          Advances the current position by n.
 void align(int alignment)
          Advances the current position until the specified alignment is achieved.
 byte[] array()
          Returns the backing array.
 int get()
          Reads the next byte of the ByteWrapper.
 void get(byte[] dest)
          Reads dest.length bytes from the ByteWrapper into dest.
 int getInt()
          Reads the next four byte of the ByteWrapper as a hi-endian 32-bit integer.
 int getPos()
          Returns the current position.
 void put(byte[] src)
          Puts a byte array in the wrapped byte array and advances the current posisiton by the size of the byte array.
 void put(int b)
          Puts a byte in the wrapped byte array and advances the current position by 1.
 void putInt(int value)
          Writes value to the ByteWrapper as a hi-endian 32-bit integer.
 void reset()
          Resets current position to the start of the ByteWrapper.
 ByteWrapper slice()
          Creates a ByteWrapper backed by the same byte array using the current position as its offset.
 ByteWrapper slice(int length)
          Creates a ByteWrapper backed by the same byte array using the current position as its offset, and the specified length to mark the limit.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteWrapper

public ByteWrapper(int length)
Construct a ByteWrapper backed by a byte array with the specified length.

Parameters:
length -

ByteWrapper

public ByteWrapper(byte[] buffer)
Constructs a ByteWrapper backed by the specified byte array. (Changes to the Byte Wrapper will write through to the specified byte array.)

Parameters:
buffer -

ByteWrapper

public ByteWrapper(byte[] buffer,
                   int offset)
Constructs a ByteWrapper backed by the specified byte array. (Changes to the Byte Wrapper will write through to the specified byte array.) The current position will be at the offset. Limit will be at buffer.length.

Parameters:
buffer -
offset -
Method Detail

reset

public void reset()
Resets current position to the start of the ByteWrapper.


getInt

public final int getInt()
Reads the next four byte of the ByteWrapper as a hi-endian 32-bit integer. The ByteWrapper's current position is increased by 4.

Returns:
decoded value

get

public final int get()
Reads the next byte of the ByteWrapper. The ByteWrapper's current position is increased by 1.

Returns:
decoded value

get

public final void get(byte[] dest)
Reads dest.length bytes from the ByteWrapper into dest. The ByteWrapper's current position is increased by dest.length.

Parameters:
dest -

putInt

public final void putInt(int value)
Writes value to the ByteWrapper as a hi-endian 32-bit integer. The ByteWrapper's current position is increased by 4.

Parameters:
value -

put

public final void put(int b)
Puts a byte in the wrapped byte array and advances the current position by 1.

Parameters:
b - Byte to put.

put

public final void put(byte[] src)
Puts a byte array in the wrapped byte array and advances the current posisiton by the size of the byte array.

Parameters:
src - Byte array to put.

array

public final byte[] array()
Returns the backing array.


getPos

public final int getPos()
Returns the current position.


advance

public final void advance(int n)
Advances the current position by n.

Parameters:
n -

align

public final void align(int alignment)
Advances the current position until the specified alignment is achieved.

Parameters:
alignment -

slice

public final ByteWrapper slice()
Creates a ByteWrapper backed by the same byte array using the current position as its offset.


slice

public final ByteWrapper slice(int length)
Creates a ByteWrapper backed by the same byte array using the current position as its offset, and the specified length to mark the limit.


toString

public String toString()
Overrides:
toString in class Object