gcspy.comm
Class BufferedOutput

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

public class BufferedOutput
extends java.lang.Object

Buffered output to 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
BufferedOutput(byte[] buffer)
          Create a new output buffer
 
Method Summary
 void close()
          Close the buffer
 int getLen()
          Get the current length of the buffer
 void writeArrayLen(int len)
          Write an array's length into the buffer
 void writeBoolean(boolean b)
          Write a boolean into the buffer
 void writeByte(byte v)
          Write a byte into the buffer
 void writeByteArray(byte[] v)
          Write a array of bytes into the buffer, preceded by its length
 void writeByteArray(byte[] v, int len)
          Write a prefix of array of bytes into the buffer, preceded by its length
 void writeColor(java.awt.Color c)
          Write a colour into the buffer
 void writeEmptyArray()
          Write a zero-length array into the buffer
 void writeInt(int v)
          Write an int into the buffer
 void writeIntArray(int[] v)
          Write a array of ints into the buffer, preceded by its length
 void writeIntArray(int[] v, int len)
          Write a prefix of array of ins into the buffer, preceded by its length
 void writeShort(int v)
          Write a short into the buffer
 void writeShortArray(short[] v)
          Write a array of shorts into the buffer, preceded by its length
 void writeShortArray(short[] v, int len)
          Write a prefix of array of shorts into the buffer, preceded by its length
 void writeString(java.lang.String v)
          Write a string into the buffer, terminated by 0.
 void writeUByte(short v)
          Write an unsigned into the buffer
 void writeUByteArray(short[] v)
          Write a array of unsigned bytes into the buffer, preceded by its length
 void writeUByteArray(short[] v, int len)
          Write a prefix of array of unsigned bytes into the buffer, preceded by its length
 void writeUShort(int v)
          Write an unsigned short into the buffer
 void writeUShortArray(int[] v)
          Write a array of unsigned shorts into the buffer, preceded by its length
 void writeUShortArray(int[] v, int len)
          Write a prefix of array of unsigned shorts into the buffer, preceded by its length
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedOutput

public BufferedOutput(byte[] buffer)
Create a new output buffer

Parameters:
buffer - the buffer
Method Detail

getLen

public int getLen()
Get the current length of the buffer

Returns:
the current length (position) of the buffer

writeBoolean

public void writeBoolean(boolean b)
Write a boolean into the buffer

Parameters:
b - The value to write

writeByte

public void writeByte(byte v)
Write a byte into the buffer

Parameters:
v - The value to write

writeUByte

public void writeUByte(short v)
Write an unsigned into the buffer

Parameters:
v - The value to write

writeShort

public void writeShort(int v)
Write a short into the buffer

Parameters:
v - The value to write

writeUShort

public void writeUShort(int v)
Write an unsigned short into the buffer

Parameters:
v - The value to write

writeInt

public void writeInt(int v)
Write an int into the buffer

Parameters:
v - The value to write

writeString

public void writeString(java.lang.String v)
Write a string into the buffer, terminated by 0.

Parameters:
v - The string to write

writeArrayLen

public void writeArrayLen(int len)
Write an array's length into the buffer

Parameters:
len - the length to write

writeByteArray

public void writeByteArray(byte[] v)
Write a array of bytes into the buffer, preceded by its length

Parameters:
v - the array to write

writeByteArray

public void writeByteArray(byte[] v,
                           int len)
Write a prefix of array of bytes into the buffer, preceded by its length

Parameters:
v - the array
len - the number of bytes to write

writeUByteArray

public void writeUByteArray(short[] v)
Write a array of unsigned bytes into the buffer, preceded by its length

Parameters:
v - the array to write

writeUByteArray

public void writeUByteArray(short[] v,
                            int len)
Write a prefix of array of unsigned bytes into the buffer, preceded by its length

Parameters:
v - the array
len - the number of bytes to write

writeShortArray

public void writeShortArray(short[] v)
Write a array of shorts into the buffer, preceded by its length

Parameters:
v - the array to write

writeShortArray

public void writeShortArray(short[] v,
                            int len)
Write a prefix of array of shorts into the buffer, preceded by its length

Parameters:
v - the array
len - the number of bytes to write

writeUShortArray

public void writeUShortArray(int[] v)
Write a array of unsigned shorts into the buffer, preceded by its length

Parameters:
v - the array to write

writeUShortArray

public void writeUShortArray(int[] v,
                             int len)
Write a prefix of array of unsigned shorts into the buffer, preceded by its length

Parameters:
v - the array
len - the number of bytes to write

writeIntArray

public void writeIntArray(int[] v)
Write a array of ints into the buffer, preceded by its length

Parameters:
v - the array to write

writeIntArray

public void writeIntArray(int[] v,
                          int len)
Write a prefix of array of ins into the buffer, preceded by its length

Parameters:
v - the array
len - the number of bytes to write

writeEmptyArray

public void writeEmptyArray()
Write a zero-length array into the buffer


writeColor

public void writeColor(java.awt.Color c)
Write a colour into the buffer

Parameters:
c - The colour to write

close

public void close()
Close the buffer