1 /* 2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 4892682 4892698 27 * @summary Tests that the appropriate IllegalStateException is thrown if 28 * ImageReader.read() or ImageWriter.write() is called without having 29 * first set the input/output stream 30 */ 31 32 import java.awt.image.BufferedImage; 33 import java.util.Iterator; 34 35 import javax.imageio.ImageReader; 36 import javax.imageio.ImageWriter; 37 import javax.imageio.spi.IIORegistry; 38 import javax.imageio.spi.ImageReaderSpi; 39 import javax.imageio.spi.ImageWriterSpi; 40 41 public class NullInputOutput { 42 main(String[] args)43 public static void main(String[] args) throws Exception { 44 IIORegistry registry = IIORegistry.getDefaultInstance(); 45 46 // test ImageReader.read() for all available ImageReaders 47 Iterator readerspis = registry.getServiceProviders(ImageReaderSpi.class, 48 false); 49 while (readerspis.hasNext()) { 50 ImageReaderSpi readerspi = (ImageReaderSpi)readerspis.next(); 51 ImageReader reader = readerspi.createReaderInstance(); 52 try { 53 reader.read(0); 54 } catch (IllegalStateException ise) { 55 // caught exception, everything's okay 56 } 57 } 58 59 // test ImageWriter.write() for all available ImageWriters 60 BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); 61 Iterator writerspis = registry.getServiceProviders(ImageWriterSpi.class, 62 false); 63 while (writerspis.hasNext()) { 64 ImageWriterSpi writerspi = (ImageWriterSpi)writerspis.next(); 65 ImageWriter writer = writerspi.createWriterInstance(); 66 try { 67 writer.write(bi); 68 } catch (IllegalStateException ise) { 69 // caught exception, everything's okay 70 } 71 } 72 } 73 } 74