| 1 |
|
| 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 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 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 |
|
| 44 |
int tagID = read(); |
| 45 |
|
| 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 |
} |