350 System.out.println("tables-only image found");
351 long pos = iis.getStreamPosition();
352 System.out.println("pos after return from native is " + pos);
353 }
354 // This reads the tables-only image twice, once from C
355 // and once from Java, but only if ignoreMetadata is false
356 if (ignoreMetadata == false) {
357 iis.seek(savePos);
358 haveSeeked = true;
359 streamMetadata = new JPEGMetadata(true, false,
360 iis, this);
361 long pos = iis.getStreamPosition();
362 if (debug) {
363 System.out.println
364 ("pos after constructing stream metadata is " + pos);
365 }
366 }
367 // Now we are at the first image if there are any, so add it
368 // to the list
369 if (hasNextImage()) {
370 imagePositions.add(new Long(iis.getStreamPosition()));
371 }
372 } else { // Not tables only, so add original pos to the list
373 imagePositions.add(new Long(savePos));
374 // And set current image since we've read it now
375 currentImage = 0;
376 }
377 if (seekForwardOnly) {
378 Long pos = imagePositions.get(imagePositions.size()-1);
379 iis.flushBefore(pos.longValue());
380 }
381 tablesOnlyChecked = true;
382 }
383
384 public int getNumImages(boolean allowSearch) throws IOException {
385 setThreadLock();
386 try { // locked thread
387 cbLock.check();
388
389 return getNumImagesOnThread(allowSearch);
390 } finally {
391 clearThreadLock();
392 }
393 }
481 if (!tablesOnlyChecked) {
482 checkTablesOnly();
483 }
484 if (imageIndex < imagePositions.size()) {
485 iis.seek(imagePositions.get(imageIndex).longValue());
486 } else {
487 // read to start of image, saving positions
488 // First seek to the last position we already have, and skip the
489 // entire image
490 Long pos = imagePositions.get(imagePositions.size()-1);
491 iis.seek(pos.longValue());
492 skipImage();
493 // Now add all intervening positions, skipping images
494 for (int index = imagePositions.size();
495 index <= imageIndex;
496 index++) {
497 // Is there an image?
498 if (!hasNextImage()) {
499 throw new IndexOutOfBoundsException();
500 }
501 pos = new Long(iis.getStreamPosition());
502 imagePositions.add(pos);
503 if (seekForwardOnly) {
504 iis.flushBefore(pos.longValue());
505 }
506 if (index < imageIndex) {
507 skipImage();
508 } // Otherwise we are where we want to be
509 }
510 }
511
512 if (seekForwardOnly) {
513 minIndex = imageIndex;
514 }
515
516 haveSeeked = true; // No way is native buffer still valid
517 }
518
519 /**
520 * Skip over a complete image in the stream, leaving the stream
521 * positioned such that the next byte to be read is the first
|
350 System.out.println("tables-only image found");
351 long pos = iis.getStreamPosition();
352 System.out.println("pos after return from native is " + pos);
353 }
354 // This reads the tables-only image twice, once from C
355 // and once from Java, but only if ignoreMetadata is false
356 if (ignoreMetadata == false) {
357 iis.seek(savePos);
358 haveSeeked = true;
359 streamMetadata = new JPEGMetadata(true, false,
360 iis, this);
361 long pos = iis.getStreamPosition();
362 if (debug) {
363 System.out.println
364 ("pos after constructing stream metadata is " + pos);
365 }
366 }
367 // Now we are at the first image if there are any, so add it
368 // to the list
369 if (hasNextImage()) {
370 imagePositions.add(iis.getStreamPosition());
371 }
372 } else { // Not tables only, so add original pos to the list
373 imagePositions.add(savePos);
374 // And set current image since we've read it now
375 currentImage = 0;
376 }
377 if (seekForwardOnly) {
378 Long pos = imagePositions.get(imagePositions.size()-1);
379 iis.flushBefore(pos.longValue());
380 }
381 tablesOnlyChecked = true;
382 }
383
384 public int getNumImages(boolean allowSearch) throws IOException {
385 setThreadLock();
386 try { // locked thread
387 cbLock.check();
388
389 return getNumImagesOnThread(allowSearch);
390 } finally {
391 clearThreadLock();
392 }
393 }
481 if (!tablesOnlyChecked) {
482 checkTablesOnly();
483 }
484 if (imageIndex < imagePositions.size()) {
485 iis.seek(imagePositions.get(imageIndex).longValue());
486 } else {
487 // read to start of image, saving positions
488 // First seek to the last position we already have, and skip the
489 // entire image
490 Long pos = imagePositions.get(imagePositions.size()-1);
491 iis.seek(pos.longValue());
492 skipImage();
493 // Now add all intervening positions, skipping images
494 for (int index = imagePositions.size();
495 index <= imageIndex;
496 index++) {
497 // Is there an image?
498 if (!hasNextImage()) {
499 throw new IndexOutOfBoundsException();
500 }
501 pos = iis.getStreamPosition();
502 imagePositions.add(pos);
503 if (seekForwardOnly) {
504 iis.flushBefore(pos.longValue());
505 }
506 if (index < imageIndex) {
507 skipImage();
508 } // Otherwise we are where we want to be
509 }
510 }
511
512 if (seekForwardOnly) {
513 minIndex = imageIndex;
514 }
515
516 haveSeeked = true; // No way is native buffer still valid
517 }
518
519 /**
520 * Skip over a complete image in the stream, leaving the stream
521 * positioned such that the next byte to be read is the first
|