f65716cf |
1 | import java.io.*; |
2 | |
3 | public class read_trace { |
4 | public static void main(String[] args) { |
5 | int tmp = 0; |
7d1dd76a |
6 | boolean print = false; |
7 | String filename = ""; |
8 | |
9 | for(String s : args) { |
10 | if(s.equals("-p")) { |
11 | print = true; |
12 | } |
13 | else { |
14 | filename = s; |
15 | } |
16 | } |
17 | |
18 | if(filename.equals("")) { |
19 | System.out.println("error: no filename specified"); |
20 | return; |
21 | } |
f65716cf |
22 | |
23 | try { |
7d1dd76a |
24 | FileInputStream file_input = new FileInputStream (filename); |
4ef69136 |
25 | BufferedInputStream buffered_input = new BufferedInputStream(file_input); |
26 | DataInputStream data_input = new DataInputStream (buffered_input); |
f65716cf |
27 | |
28 | int timestamp; |
29 | short id; |
30 | byte length; |
31 | |
32 | while(true) { |
33 | timestamp = data_input.readInt(); |
34 | id = data_input.readShort(); |
35 | length = data_input.readByte(); |
36 | |
37 | byte[] buf = new byte[length]; |
38 | data_input.readFully(buf, 0, length); |
39 | |
40 | |
41 | ByteArrayInputStream eargs = new ByteArrayInputStream(buf); |
42 | DataInputStream eargs_data = new DataInputStream (eargs); |
43 | |
44 | /* read arg 1 (short) */ |
45 | short arg1 = eargs_data.readShort(); |
46 | |
47 | /* read arg 2 (string) */ |
48 | eargs_data.mark(10000); |
49 | int strlen=0; |
50 | while(eargs_data.readByte() != 0) |
51 | strlen++; |
52 | eargs_data.reset(); |
53 | byte[] arg2 = new byte[strlen]; |
54 | eargs_data.readFully(arg2, 0, strlen); |
55 | |
ce68a724 |
56 | if(args.length>0 && args[0].equals("-p")) |
57 | System.out.printf("timestamp %d id %d args=(short=%d string=\"%s\") %n", timestamp, id, arg1, new String(arg2)); |
f65716cf |
58 | } |
59 | |
60 | } |
61 | catch(IOException e) { |
62 | //System.out.println ("IO exception = " + e ); |
63 | //e.printStackTrace(); |
64 | } |
65 | |
66 | //file_input.close(); |
f65716cf |
67 | } |
68 | } |