gcspy.comm
Class BufferedInput

java.lang.Object
  extended by gcspy.comm.BufferedInput

public class BufferedInput
extends java.lang.Object

Buffered input from a byte array The communication stream has the following wire format (b is a byte)

 byte           b
 ubyte          b
 short          bb
 ushort         bb
 false          0
 true           1
 int            bbbb
 string         byte...byte0
 len            int
 array          len item...item
 color          ubyte ubyte ubyte
 

Author:
Tony Printezis

Constructor Summary
BufferedInput(byte[] buffer, int len)
          Create a new buffer
 
Method Summary
 void close()
          Close the buffer
 boolean finished()
          Have we reached the end of the input buffer?
 int readArrayLen()
          Read the length of an array (which follows) from the buffer
 boolean readBoolean()
          Read the next boolean from the input buffer
 byte readByte()
          Return the next byte from the input buffer
 byte[] readByteArray()
          Read an array from the buffer.
 java.awt.Color readColor()
          Read a colour from the input buffer
 int readInt()
          Read the next int from the input buffer.
 int[] readIntArray()
          Read an array from the buffer.
 short readShort()
          Read the next short from the input buffer
 short[] readShortArray()
          Read an array from the buffer.
 java.lang.String readString()
          Read the next 0-terminated string from the buffer
 short readUByte()
          Read the nexct unsigned byte from the input buffer.
 short[] readUByteArray()
          Read an array from the buffer.
 int readUShort()
          Read the next short from the input buffer
 int[] readUShortArray()
          Read an array from the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedInput

public BufferedInput(byte[] buffer,
                     int len)
Create a new buffer

Parameters:
buffer - The byte array buffer
len - The buffer's length
Method Detail

finished

public boolean finished()
Have we reached the end of the input buffer?

Returns:
true if we have reached the end of the buffer

readBoolean

public boolean readBoolean()
Read the next boolean from the input buffer

Returns:
the next value as a boolean from the buffer

readByte

public byte readByte()
Return the next byte from the input buffer

Returns:
the next value as a byte from the buffer

readUByte

public short readUByte()
Read the nexct unsigned byte from the input buffer.

Returns:
the next value as an unsigned byte from the buffer

readShort

public short readShort()
Read the next short from the input buffer

Returns:
the next value as a short from the buffer

readUShort

public int readUShort()
Read the next short from the input buffer

Returns:
the next value as an unsigned short from the buffer

readInt

public int readInt()
Read the next int from the input buffer.

Returns:
the next value as an int from the buffer

readString

public java.lang.String readString()
Read the next 0-terminated string from the buffer

Returns:
the string

readArrayLen

public int readArrayLen()
Read the length of an array (which follows) from the buffer

Returns:
the array's length

readByteArray

public byte[] readByteArray()
Read an array from the buffer. The first item is the length of the array

Returns:
the next array of bytes read from the buffer

readUByteArray

public short[] readUByteArray()
Read an array from the buffer. The first item is the length of the array

Returns:
the next array of unsigned bytes read from the buffer

readShortArray

public short[] readShortArray()
Read an array from the buffer. The first item is the length of the array

Returns:
the next array of shorts read from the buffer

readUShortArray

public int[] readUShortArray()
Read an array from the buffer. The first item is the length of the array

Returns:
the next array of unsigned shorts read from the buffer

readIntArray

public int[] readIntArray()
Read an array from the buffer. The first item is the length of the array

Returns:
the next array of ints read from the buffer

readColor

public java.awt.Color readColor()
Read a colour from the input buffer

Returns:
the next colour from the buffer

close

public void close()
Close the buffer

Throws:
a - BufferedIOException if we haven't reached the end of the buffer