System information

Appendix D. JAVA Example Code
D-18
// the message type and transaction number may not be present.
// We will set them to 0 and then look for them
tran_no = 0;
message_type = 0;
storage_len = 0;
if(len >= 9)
{
message_type = buff[8];
tran_no = buff[9];
storage = new byte[len - 10];
for(int i = 10; i < len; ++i)
{
++storage_len;
storage[i - 10] = buff[i];
}
}
}
protected void reserve(int len)
{
// we need to check to make sure that the buffer has the
// capacity for the specified length. If it does not, we
// will re-allocate it so that it does.
if(storage == null)
storage = new byte[len];
else if(storage.length < len)
{
// If we don't have enough capacity. To prevent re-allocation
// each time, we will double the requested amount.
byte[] temp = new byte[len * 2];
for(int i = 0; i < storage.length; ++i)
temp[i] = storage[i];
storage = temp;
}
}
public void add_bytes(byte[] buff, int buff_len)
{
reserve(storage_len + buff.length);
for(int i = 0; i < buff_len; ++i)
storage[storage_len++] = buff[i];
}
public void add_byte(Byte val)
{
reserve(storage_len + 1);
storage[storage_len++] = val.byteValue();
}