Path: blob/master/test/jdk/javax/imageio/plugins/jpeg/JpegMultipleEOITest.java
41152 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 815267226* @summary When jpeg file has more than one set of EOI-SOI markers,27* test verifies whether we calculate EOI markers of all images28* properly skipping EOI markers present in application headers.29* @run main JpegMultipleEOITest30*/3132import java.io.File;33import java.io.IOException;34import java.util.Iterator;35import javax.imageio.ImageIO;36import javax.imageio.ImageReader;37import javax.imageio.stream.ImageInputStream;3839public class JpegMultipleEOITest {40public static void main (String[] args) throws IOException {41Iterator readers = ImageIO.getImageReadersByFormatName("JPEG");42ImageReader reader = null;43while(readers.hasNext()) {44reader = (ImageReader)readers.next();45if(reader.canReadRaster()) {46break;47}48}4950if (reader != null) {51String fileName = "JpegMultipleEOI.jpg";52String sep = System.getProperty("file.separator");53String dir = System.getProperty("test.src", ".");54String filePath = dir+sep+fileName;55System.out.println("Test file: " + filePath);56File imageFile = new File(filePath);57ImageInputStream stream = ImageIO.58createImageInputStream(imageFile);59reader.setInput(stream);60int pageNum = 1;61try {62// read width of image index 163reader.getWidth(pageNum + reader.getMinIndex());64} catch (IndexOutOfBoundsException e) {65/*66* do nothing, we are supposed to get IndexOutofBoundsException67* as number of image is 1 and we are trying to get width of68* second image. But we should not see IIOException with69* message "Not a JPEG file: starts with 0xff 0xe2"70*/71}72}73}74}757677