src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java
changeset 48643 2ea3667af41d
parent 47216 71c04702a3d5
child 50489 580159eeac07
equal deleted inserted replaced
48642:219585efb03c 48643:2ea3667af41d
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   372         } else { // Not tables only, so add original pos to the list
   372         } else { // Not tables only, so add original pos to the list
   373             imagePositions.add(savePos);
   373             imagePositions.add(savePos);
   374             // And set current image since we've read it now
   374             // And set current image since we've read it now
   375             currentImage = 0;
   375             currentImage = 0;
   376         }
   376         }
   377         if (seekForwardOnly) {
   377         // If the image positions list is empty as in the case of a tables-only
       
   378         // stream, then attempting to access the element at index
       
   379         // imagePositions.size() - 1 will cause an IndexOutOfBoundsException.
       
   380         if (seekForwardOnly && !imagePositions.isEmpty()) {
   378             Long pos = imagePositions.get(imagePositions.size()-1);
   381             Long pos = imagePositions.get(imagePositions.size()-1);
   379             iis.flushBefore(pos.longValue());
   382             iis.flushBefore(pos.longValue());
   380         }
   383         }
   381         tablesOnlyChecked = true;
   384         tablesOnlyChecked = true;
   382     }
   385     }
   489         if (imageIndex < minIndex) {
   492         if (imageIndex < minIndex) {
   490             throw new IndexOutOfBoundsException();
   493             throw new IndexOutOfBoundsException();
   491         }
   494         }
   492         if (!tablesOnlyChecked) {
   495         if (!tablesOnlyChecked) {
   493             checkTablesOnly();
   496             checkTablesOnly();
       
   497         }
       
   498         // If the image positions list is empty as in the case of a tables-only
       
   499         // stream, then no image data can be read.
       
   500         if (imagePositions.isEmpty()) {
       
   501             throw new IIOException("No image data present to read");
   494         }
   502         }
   495         if (imageIndex < imagePositions.size()) {
   503         if (imageIndex < imagePositions.size()) {
   496             iis.seek(imagePositions.get(imageIndex).longValue());
   504             iis.seek(imagePositions.get(imageIndex).longValue());
   497         } else {
   505         } else {
   498             // read to start of image, saving positions
   506             // read to start of image, saving positions