Debian Codegraph @

freehep-graphicsio-cgm/src/main/java/org/freehep/graphicsio/cgm/CGMInputStream.java

raw symbols SCIP
1 // Copyright 2003, FreeHEP.
2 package org.freehep.graphicsio.cgm;
3
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 import org.freehep.util.io.ActionHeader;
8 import org.freehep.util.io.TagHeader;
9 import org.freehep.util.io.TaggedInputStream;
10
11 /**
12 * This class extends the TaggedInputStream with several methods to read
13 * TagHeaders. It is a dummy implementation at this time, and only used for
14 * tagID analysis.
15 *
16 * @author Mark Donszelmann
17 * @version $Id: freehep-graphicsio-cgm/src/main/java/org/freehep/graphicsio/cgm/CGMInputStream.java 278fac7cefaa 2005/12/05 04:00:43 duns $
18 */
19 public class CGMInputStream extends TaggedInputStream {
20
21 public static int DEFAULT_VERSION = 3;
22
23 public CGMInputStream(InputStream is) throws IOException {
24
25 this(is, DEFAULT_VERSION);
26 }
27
28 public CGMInputStream(InputStream is, int version) throws IOException {
29
30 this(is, new CGMTagSet(version));
31 }
32
33 public CGMInputStream(InputStream is, CGMTagSet tagSet) throws IOException {
34
35 // CGM is big-endian
36 super(is, tagSet, null, false);
37 }
38
39 protected TagHeader readTagHeader() throws IOException {
40 int dummy = (getLength() % 2 != 0) ? read() : 0;
41 if (dummy == -1)
42 return null;
43 // Read the tag.
44 int tagID = read();
45 // End of stream
46 if (tagID == -1)
47 return null;
48
49 tagID = (tagID << 8) | readUnsignedByte();
50
51 long length = tagID & 0x1F;
52 if (length >= 0x1f) {
53 length = readUnsignedShort();
54 }
55 tagID = tagID >> 5;
56 return new TagHeader(tagID, length);
57 }
58
59 protected ActionHeader readActionHeader() throws IOException {
60 return null;
61 }
62
63 public int getVersion() {
64 return DEFAULT_VERSION;
65 }
66 }