System information

Appendix D. JAVA Example Code
D-23
columns = new Vector();
while(field_type != 0)
{
ColumnDef column = new ColumnDef(column_no,field_type,msg);
System.out.println("Read " + table_name + "." +
column.column_name);
columns.addElement(column);
field_type = msg.read_byte();
++column_no;
}
// the final thing that we need is to calculate the signature
// of the table definition. To do this we will obtain a copy
// of the bytes from the message and calculate the signature
// on those bytes
byte[] table_contents = msg.get_fragment(
table_start_pos,
msg.get_read_index() - 1);
def_sig =
calcSigFor(table_contents,table_contents.length,(char)0xAAAA);
}
public int print_records(Packet msg) throws Exception
{
// this method assumes that the message pointer is positioned
// just past the table no parameter in the data collection response.
// It will get the beginning record number and number of records
// and will then print out the table meta-data along with field
// values.
int begin_record_no = msg.read_int();
short records_count = msg.read_short();
long record_stamp = 0;
int rtn = begin_record_no;
if((records_count & 0x8000) != 0)
throw new Exception("Partial records are not supported");
for(short i = 0; i < records_count; ++i)
{
// if this is an event table or if this is the first record,
// we need to read the record stamp.
if(i == 0 || interval == 0)
record_stamp = (msg.read_int() * nsecPerSec);
else
record_stamp += interval;
// print out the record data
++rtn;
System.out.println("Data for table " + table_name);
System.out.println(" Record: " + (begin_record_no + i));
System.out.println(" Time: " +
getTimeStamp(record_stamp).getTime());
// we now need to process the scalar values one at a time
for(int j = 0; j < columns.size(); ++j)
{
ColumnDef column = (ColumnDef)columns.elementAt(j);
for(int k = 0; k < column.piece_size; ++k)
{
System.out.print(" " + column.column_name);
if(column.piece_size > 1)
System.out.print("(" + (column.begin_index + k) +
")");
System.out.print(": ");