Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/AllowSearch.java
38833 views
/*1* Copyright (c) 2001, 2017, 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 4420318 818334126* @summary Checks that an IllegalStateException is thrown by getNumImages(true)27* when seekForwardOnly is true28*/2930import java.io.File;31import java.io.IOException;32import java.nio.file.Files;3334import javax.imageio.ImageIO;35import javax.imageio.ImageReader;36import javax.imageio.stream.ImageInputStream;3738import com.sun.imageio.plugins.gif.GIFImageReader;39import com.sun.imageio.plugins.jpeg.JPEGImageReader;40import com.sun.imageio.plugins.png.PNGImageReader;4142public class AllowSearch {43private static void test(ImageReader reader, String format)44throws IOException {45boolean gotISE = false;46File f = null;47ImageInputStream stream = null;48try {49f = File.createTempFile("imageio", ".tmp");50stream = ImageIO.createImageInputStream(f);51reader.setInput(stream, true);5253try {54int numImages = reader.getNumImages(true);55} catch (IOException ioe) {56gotISE = false;57} catch (IllegalStateException ise) {58gotISE = true;59}60} finally {61if (stream != null) {62stream.close();63}6465reader.dispose();6667if (f != null) {68Files.delete(f.toPath());69}70}7172if (!gotISE) {73throw new RuntimeException("Failed to get desired exception for " +74format + " reader!");75}76}7778public static void main(String[] args) throws IOException {79ImageReader gifReader = new GIFImageReader(null);80ImageReader jpegReader = new JPEGImageReader(null);81ImageReader pngReader = new PNGImageReader(null);8283test(gifReader, "GIF");84test(jpegReader, "JPEG");85test(pngReader, "PNG");86}87}888990