| 1 | import java.io.*; |
| 2 | |
| 3 | public class read_trace { |
| 4 | public static void main(String[] args) { |
| 5 | int tmp = 0; |
| 6 | |
| 7 | try { |
| 8 | FileInputStream file_input = new FileInputStream ("../trace.dat"); |
| 9 | DataInputStream data_input = new DataInputStream (file_input); |
| 10 | |
| 11 | int timestamp; |
| 12 | short id; |
| 13 | byte length; |
| 14 | |
| 15 | while(true) { |
| 16 | timestamp = data_input.readInt(); |
| 17 | id = data_input.readShort(); |
| 18 | length = data_input.readByte(); |
| 19 | |
| 20 | byte[] buf = new byte[length]; |
| 21 | data_input.readFully(buf, 0, length); |
| 22 | |
| 23 | |
| 24 | ByteArrayInputStream eargs = new ByteArrayInputStream(buf); |
| 25 | DataInputStream eargs_data = new DataInputStream (eargs); |
| 26 | |
| 27 | /* read arg 1 (short) */ |
| 28 | short arg1 = eargs_data.readShort(); |
| 29 | |
| 30 | /* read arg 2 (string) */ |
| 31 | eargs_data.mark(10000); |
| 32 | int strlen=0; |
| 33 | while(eargs_data.readByte() != 0) |
| 34 | strlen++; |
| 35 | eargs_data.reset(); |
| 36 | byte[] arg2 = new byte[strlen]; |
| 37 | eargs_data.readFully(arg2, 0, strlen); |
| 38 | |
| 39 | if(args.length>0 && args[0].equals("-p")) |
| 40 | System.out.printf("timestamp %d id %d args=(short=%d string=\"%s\") %n", timestamp, id, arg1, new String(arg2)); |
| 41 | } |
| 42 | |
| 43 | } |
| 44 | catch(IOException e) { |
| 45 | //System.out.println ("IO exception = " + e ); |
| 46 | //e.printStackTrace(); |
| 47 | } |
| 48 | |
| 49 | //file_input.close(); |
| 50 | } |
| 51 | } |