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