1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.archive.queue;
25
26 import java.io.ByteArrayInputStream;
27 import java.io.EOFException;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.ObjectInputStream;
32 import java.io.SequenceInputStream;
33
34 import org.archive.util.ArchiveUtils;
35 import org.archive.util.Reporter;
36
37 /***
38 * Command-line tool that displays serialized object streams in a
39 * line-oriented format.
40 *
41 * @author gojomo
42 */
43 public class QueueCat {
44 public static void main(String[] args)
45 throws IOException, ClassNotFoundException {
46 InputStream inStream;
47 if (args.length == 0) {
48 inStream = System.in;
49 } else {
50 inStream = new FileInputStream(args[0]);
51 }
52
53
54
55 byte[] serialStart = { (byte)0xac, (byte)0xed, (byte)0x00, (byte)0x05 };
56 byte[] actualStart = new byte[4];
57 byte[] pseudoStart;
58 inStream.read(actualStart);
59 if (ArchiveUtils.byteArrayEquals(serialStart,actualStart)) {
60 pseudoStart = serialStart;
61 } else {
62
63 pseudoStart = new byte[8];
64 System.arraycopy(serialStart,0,pseudoStart,0,4);
65 System.arraycopy(actualStart,0,pseudoStart,4,4);
66 }
67 inStream = new SequenceInputStream(
68 new ByteArrayInputStream(pseudoStart),
69 inStream);
70
71 ObjectInputStream oin = new ObjectInputStream(inStream);
72
73 Object o;
74 while(true) {
75 try {
76 o=oin.readObject();
77 } catch (EOFException e) {
78 return;
79 }
80 if(o instanceof Reporter) {
81 System.out.println(((Reporter)o).singleLineReport());
82 } else {
83
84 System.out.println(o.toString());
85 }
86 }
87 }
88 }