System information

Appendix D. JAVA Example Code
D-19
public void add_short(Short val)
{
byte[] temp = new byte[2];
temp[0] = (byte)((val & 0xFF00) >> 8);
temp[1] = (byte)(val & 0x00FF);
add_bytes(temp,temp.length);
}
public void add_int(Integer val)
{
byte[] temp = new byte[4];
temp[0] = (byte)((val & 0xFF000000) >> 24);
temp[1] = (byte)((val & 0x00FF0000) >> 16);
temp[2] = (byte)((val & 0x0000FF00) >> 8);
temp[3] = (byte)(val & 0x000000FF);
add_bytes(temp,temp.length);
}
public void add_string(String val)
{
byte[] temp = val.getBytes();
add_bytes(temp,temp.length);
if(val.charAt(val.length()-1) != '\0')
add_byte((byte)0);
}
public void add_float(Float val)
{
add_int(Float.floatToIntBits(val.floatValue()));
}
public byte[] read_bytes(int len) throws Exception
{
if(read_index + len > storage_len)
throw new Exception("Attempt to read past end");
byte[] rtn = new byte[len];
for(int i = 0; i < len; ++i)
rtn[i] = storage[read_index++];
return rtn;
}
public byte read_byte() throws Exception
{
byte[] temp = read_bytes(1);
return temp[0];
}
public short read_short() throws Exception
{
byte[] temp = read_bytes(2);
short rtn = (short)(
((short)temp[0] & 0xff) << 8 |
((short)temp[1] & 0xff));
return rtn;
}