34 35 import org.w3c.dom.Node; 36 import org.w3c.dom.NamedNodeMap; 37 38 /** 39 * All metadata is stored in MarkerSegments. Marker segments 40 * that we know about are stored in subclasses of this 41 * basic class, which used for unrecognized APPn marker 42 * segments. XXX break out UnknownMarkerSegment as a subclass 43 * and make this abstract, avoiding unused data field. 44 */ 45 class MarkerSegment implements Cloneable { 46 protected static final int LENGTH_SIZE = 2; // length is 2 bytes 47 int tag; // See JPEG.java 48 int length; /* Sometimes needed by subclasses; doesn't include 49 itself. Meaningful only if constructed from a stream */ 50 byte [] data = null; // Raw segment data, used for unrecognized segments 51 boolean unknown = false; // Set to true if the tag is not recognized 52 53 /** 54 * Constructor for creating <code>MarkerSegment</code>s by reading 55 * from an <code>ImageInputStream</code>. 56 */ 57 MarkerSegment(JPEGBuffer buffer) throws IOException { 58 59 buffer.loadBuf(3); // tag plus length 60 tag = buffer.buf[buffer.bufPtr++] & 0xff; 61 length = (buffer.buf[buffer.bufPtr++] & 0xff) << 8; 62 length |= buffer.buf[buffer.bufPtr++] & 0xff; 63 length -= 2; // JPEG length includes itself, we don't 64 65 if (length < 0) { 66 throw new IIOException("Invalid segment length: " + length); 67 } 68 buffer.bufAvail -= 3; 69 // Now that we know the true length, ensure that we've got it, 70 // or at least a bufferful if length is too big. 71 buffer.loadBuf(length); 72 } 73 74 /** 75 * Constructor used when creating segments other than by | 34 35 import org.w3c.dom.Node; 36 import org.w3c.dom.NamedNodeMap; 37 38 /** 39 * All metadata is stored in MarkerSegments. Marker segments 40 * that we know about are stored in subclasses of this 41 * basic class, which used for unrecognized APPn marker 42 * segments. XXX break out UnknownMarkerSegment as a subclass 43 * and make this abstract, avoiding unused data field. 44 */ 45 class MarkerSegment implements Cloneable { 46 protected static final int LENGTH_SIZE = 2; // length is 2 bytes 47 int tag; // See JPEG.java 48 int length; /* Sometimes needed by subclasses; doesn't include 49 itself. Meaningful only if constructed from a stream */ 50 byte [] data = null; // Raw segment data, used for unrecognized segments 51 boolean unknown = false; // Set to true if the tag is not recognized 52 53 /** 54 * Constructor for creating {@code MarkerSegment}s by reading 55 * from an {@code ImageInputStream}. 56 */ 57 MarkerSegment(JPEGBuffer buffer) throws IOException { 58 59 buffer.loadBuf(3); // tag plus length 60 tag = buffer.buf[buffer.bufPtr++] & 0xff; 61 length = (buffer.buf[buffer.bufPtr++] & 0xff) << 8; 62 length |= buffer.buf[buffer.bufPtr++] & 0xff; 63 length -= 2; // JPEG length includes itself, we don't 64 65 if (length < 0) { 66 throw new IIOException("Invalid segment length: " + length); 67 } 68 buffer.bufAvail -= 3; 69 // Now that we know the true length, ensure that we've got it, 70 // or at least a bufferful if length is too big. 71 buffer.loadBuf(length); 72 } 73 74 /** 75 * Constructor used when creating segments other than by |