monrovia.protocol
Class ByteConverter

java.lang.Object
  |
  +--monrovia.protocol.ByteConverter

public class ByteConverter
extends java.lang.Object

ByteConverter converts to and from byteArrays


Constructor Summary
ByteConverter(byte[] pData)
          Constructs a new byteconverter with the specified array
ByteConverter(byte[][] pData)
          Construct a byte array from bitmaps
ByteConverter(Command[] pData)
          Construct a byte array from commands
ByteConverter(int pDataSize)
          Constructor allocates an empty array with specified size
ByteConverter(int[][] pData)
          Construct a byte array from a map
ByteConverter(Stat[] pData)
          Construct a byte array from stats
ByteConverter(java.lang.String[] pData)
           
 
Method Summary
static int bitmapSize(byte[][] pData)
          calculates the size of the bitmaps each bitmap: 16 * 16, 8bit color
 int bytesToInt(int pOffset)
          Convert bytes at offset to an int
 short bytesToShort(int pOffset)
          Convert bytes at offset to a short
 java.lang.String bytesToString(int pOffset)
          Convert a byte array at offset to a string
 java.lang.String bytesToString(int pOffset, int pLength)
          Convert a byte array from offset to offset + length to a string
static int commandSize(Command[] pData)
          calculates the size of the commands each command: 4 id,16 name,1 type
static int commandSize(java.lang.String[] pData)
           
 byte getByte(int pOffset)
          returns a byte at offset
 Command getCommand(int pOffset)
          getCommand gets a single command from offset
 Command[] getCommandArray()
          getCommandArray gets the commands from the bytearray and returns them as an array of commands
 java.util.Hashtable getCommands()
          getCommands gets the commands from the bytearray and returns them in a hashtable
 byte[] getData()
          returns the underlying byte array
 short[][] getShortMap()
          returns the map (array of array of shorts) from the bytearray
 int getSize()
          returns the size of the underlying byte array
 void intToBytes(int pInt, int pOffset)
          Convert an int to bytes at offset
static int mapSize(int[][] pData)
          calculates the size fo a map required for transport 2 x dimension, 2 y dimension, bitmapids
 void setByte(byte pByte, int pOffset)
          sets a byte at offset
 void setBytes(byte[] pBytes, int pOffset)
          sets bytes with length at offset
 void shortToBytes(short pShort, int pOffset)
          Convert a short to bytes at offset
static int statSize(Stat[] pData)
          calculates the size of the stats each stat: 16 name, 1 type, 16 value
 void stringToBytes(java.lang.String pString, int pOffset)
          Convert a string to bytes at offset
 void stringToBytes(java.lang.String pString, int pOffset, int pLength)
          Convert a string to bytes at offset with max length
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteConverter

public ByteConverter(int pDataSize)
Constructor allocates an empty array with specified size
Parameters:
pDataSize - size of the array to be allocated

ByteConverter

public ByteConverter(byte[] pData)
Constructs a new byteconverter with the specified array
Parameters:
pData - a byte[] to work with

ByteConverter

public ByteConverter(int[][] pData)
Construct a byte array from a map
Parameters:
pData - a map of type int[][]

ByteConverter

public ByteConverter(byte[][] pData)
Construct a byte array from bitmaps
Parameters:
pData - a bitmaparray

ByteConverter

public ByteConverter(Command[] pData)
Construct a byte array from commands
Parameters:
pData - an array of commands

ByteConverter

public ByteConverter(java.lang.String[] pData)

ByteConverter

public ByteConverter(Stat[] pData)
Construct a byte array from stats
Parameters:
pData - an array of Stats
Method Detail

getShortMap

public short[][] getShortMap()
returns the map (array of array of shorts) from the bytearray
Returns:
a map

getCommandArray

public Command[] getCommandArray()
getCommandArray gets the commands from the bytearray and returns them as an array of commands
Returns:
the array of commands

getCommands

public java.util.Hashtable getCommands()
getCommands gets the commands from the bytearray and returns them in a hashtable
Returns:
the hashtable of commands

getCommand

public Command getCommand(int pOffset)
getCommand gets a single command from offset
Parameters:
pOffset - from where to extract the command
Returns:
the command

getData

public byte[] getData()
returns the underlying byte array
Returns:
the byte array

getSize

public int getSize()
returns the size of the underlying byte array
Returns:
size in bytes

bytesToInt

public int bytesToInt(int pOffset)
Convert bytes at offset to an int
Parameters:
pOffset - the position where the int is
Returns:
the int at pOffset

bytesToShort

public short bytesToShort(int pOffset)
Convert bytes at offset to a short
Parameters:
pOffset - the position where the short is
Returns:
the short at pOffset

getByte

public byte getByte(int pOffset)
returns a byte at offset
Parameters:
pOffset - the position where the byte is
Returns:
the byte at pOffset

intToBytes

public void intToBytes(int pInt,
                       int pOffset)
Convert an int to bytes at offset
Parameters:
pInt - the int that is copied into the array
pOffset - the position where pInt should go

shortToBytes

public void shortToBytes(short pShort,
                         int pOffset)
Convert a short to bytes at offset
Parameters:
pShort - the short that is copied into the array
pOffset - the position where the pShort should go

setByte

public void setByte(byte pByte,
                    int pOffset)
sets a byte at offset
Parameters:
pByte - sets a byte
pOffset - the position of the byte

setBytes

public void setBytes(byte[] pBytes,
                     int pOffset)
sets bytes with length at offset
Parameters:
pBytes - the bytes to be set
pOffset - the offset in the target array

stringToBytes

public void stringToBytes(java.lang.String pString,
                          int pOffset)
Convert a string to bytes at offset
Parameters:
pString - the string to be set
the - position where its going

stringToBytes

public void stringToBytes(java.lang.String pString,
                          int pOffset,
                          int pLength)
Convert a string to bytes at offset with max length
Parameters:
pString - the string ot be set into the array
the - position in the array
length - (how much of the string should go at max)

bytesToString

public java.lang.String bytesToString(int pOffset)
Convert a byte array at offset to a string
Parameters:
pOffset - the starting position
Returns:
the string from pOffset to the end of the array

bytesToString

public java.lang.String bytesToString(int pOffset,
                                      int pLength)
Convert a byte array from offset to offset + length to a string
Parameters:
pOffset - the staring position
pLength - how much will be copied
Returns:
the string from pOffset to pOffset+pLength

mapSize

public static int mapSize(int[][] pData)
calculates the size fo a map required for transport 2 x dimension, 2 y dimension, bitmapids
Parameters:
pData - the array of int arrays where the map lies
Returns:
the size

bitmapSize

public static int bitmapSize(byte[][] pData)
calculates the size of the bitmaps each bitmap: 16 * 16, 8bit color
Parameters:
pData - the array of bitmaps
Returns:
the size

commandSize

public static int commandSize(Command[] pData)
calculates the size of the commands each command: 4 id,16 name,1 type
Parameters:
pData - the array of commands containing the commands
Returns:
the size

commandSize

public static int commandSize(java.lang.String[] pData)

statSize

public static int statSize(Stat[] pData)
calculates the size of the stats each stat: 16 name, 1 type, 16 value
Parameters:
pData - the array of stats
Returns:
the size