Path: blob/master/test/jdk/javax/imageio/NullInputOutput.java
41145 views
/*1* Copyright (c) 2003, 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 4892682 489269826* @summary Tests that the appropriate IllegalStateException is thrown if27* ImageReader.read() or ImageWriter.write() is called without having28* first set the input/output stream29*/3031import java.awt.image.BufferedImage;32import java.util.Iterator;3334import javax.imageio.ImageReader;35import javax.imageio.ImageWriter;36import javax.imageio.spi.IIORegistry;37import javax.imageio.spi.ImageReaderSpi;38import javax.imageio.spi.ImageWriterSpi;3940public class NullInputOutput {4142public static void main(String[] args) throws Exception {43IIORegistry registry = IIORegistry.getDefaultInstance();4445// test ImageReader.read() for all available ImageReaders46Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class,47false);48while (readerspis.hasNext()) {49ImageReaderSpi readerspi = (ImageReaderSpi)readerspis.next();50ImageReader reader = readerspi.createReaderInstance();51try {52reader.read(0);53} catch (IllegalStateException ise) {54// caught exception, everything's okay55}56}5758// test ImageWriter.write() for all available ImageWriters59BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);60Iterator writerspis = registry.getServiceProviders(ImageWriterSpi.class,61false);62while (writerspis.hasNext()) {63ImageWriterSpi writerspi = (ImageWriterSpi)writerspis.next();64ImageWriter writer = writerspi.createWriterInstance();65try {66writer.write(bi);67} catch (IllegalStateException ise) {68// caught exception, everything's okay69}70}71}72}737475