599 }
600
601 private int locateImage(int imageIndex) throws IIOException {
602 readHeader();
603
604 try {
605 // Find closest known index
606 int index = Math.min(imageIndex, imageStartPosition.size() - 1);
607
608 // Seek to that position
609 Long l = imageStartPosition.get(index);
610 stream.seek(l.longValue());
611
612 // Skip images until at desired index or last image found
613 while (index < imageIndex) {
614 if (!skipImage()) {
615 --index;
616 return index;
617 }
618
619 Long l1 = new Long(stream.getStreamPosition());
620 imageStartPosition.add(l1);
621 ++index;
622 }
623 } catch (IOException e) {
624 throw new IIOException("Couldn't seek!", e);
625 }
626
627 if (currIndex != imageIndex) {
628 imageMetadata = null;
629 }
630 currIndex = imageIndex;
631 return imageIndex;
632 }
633
634 // Read blocks of 1-255 bytes, stop at a 0-length block
635 private byte[] concatenateBlocks() throws IOException {
636 byte[] data = new byte[0];
637 while (true) {
638 int length = stream.readUnsignedByte();
639 if (length == 0) {
|
599 }
600
601 private int locateImage(int imageIndex) throws IIOException {
602 readHeader();
603
604 try {
605 // Find closest known index
606 int index = Math.min(imageIndex, imageStartPosition.size() - 1);
607
608 // Seek to that position
609 Long l = imageStartPosition.get(index);
610 stream.seek(l.longValue());
611
612 // Skip images until at desired index or last image found
613 while (index < imageIndex) {
614 if (!skipImage()) {
615 --index;
616 return index;
617 }
618
619 Long l1 = stream.getStreamPosition();
620 imageStartPosition.add(l1);
621 ++index;
622 }
623 } catch (IOException e) {
624 throw new IIOException("Couldn't seek!", e);
625 }
626
627 if (currIndex != imageIndex) {
628 imageMetadata = null;
629 }
630 currIndex = imageIndex;
631 return imageIndex;
632 }
633
634 // Read blocks of 1-255 bytes, stop at a 0-length block
635 private byte[] concatenateBlocks() throws IOException {
636 byte[] data = new byte[0];
637 while (true) {
638 int length = stream.readUnsignedByte();
639 if (length == 0) {
|