1 /* 2 * Copyright (c) 2001, 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 4450319 27 * @summary Checks that ImageReader.readAll(int, ImageReadParam) makes use of 28 * the ImageReadParam object 29 */ 30 31 import java.awt.image.BufferedImage; 32 import java.io.ByteArrayInputStream; 33 import java.io.IOException; 34 import java.util.Iterator; 35 import java.util.Vector; 36 37 import javax.imageio.IIOImage; 38 import javax.imageio.ImageReadParam; 39 import javax.imageio.ImageReader; 40 import javax.imageio.ImageTypeSpecifier; 41 import javax.imageio.metadata.IIOMetadata; 42 import javax.imageio.spi.ImageReaderSpi; 43 import javax.imageio.stream.MemoryCacheImageInputStream; 44 45 public class ImageReaderReadAll { 46 47 private final static byte[] ba = {}; 48 main(String argv[])49 public static void main(String argv[]) { 50 ImageReader ireader; 51 ImageReadParam irp; 52 IIOImage image; 53 BufferedImage bi; 54 BufferedImage bi_1; 55 BufferedImage bi_2; 56 57 ireader = new DummyImageReaderImpl(null); 58 MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream 59 (new ByteArrayInputStream(ba)); 60 ireader.setInput(mciis); 61 62 irp = new ImageReadParam(); 63 irp.setDestination(new BufferedImage(10, 10, 64 BufferedImage.TYPE_3BYTE_BGR)); 65 try { 66 image = ireader.readAll(0, irp); 67 bi_1 = ireader.read(0, irp); 68 bi_2 = ireader.read(0); 69 } catch (java.io.IOException ee) { 70 throw new RuntimeException("Unexpected exception: " + ee); 71 } 72 73 bi = (BufferedImage)image.getRenderedImage(); 74 if (bi.getType() != bi_1.getType()) { 75 throw new RuntimeException("Images have different type!"); 76 } 77 } 78 79 80 public static class DummyImageReaderImpl extends ImageReader { 81 DummyImageReaderImpl(ImageReaderSpi originatingProvider)82 public DummyImageReaderImpl(ImageReaderSpi originatingProvider) { 83 super(originatingProvider); 84 } 85 read(int imageIndex, ImageReadParam param)86 public BufferedImage read(int imageIndex, ImageReadParam param) 87 throws IOException { 88 if (input == null) 89 throw new IllegalStateException(); 90 if (imageIndex >= 1 || imageIndex < 0) 91 throw new IndexOutOfBoundsException(); 92 if (seekForwardOnly) { 93 if (imageIndex < minIndex) 94 throw new IndexOutOfBoundsException(); 95 minIndex = imageIndex; 96 } 97 98 return getDestination(param, getImageTypes(imageIndex), 10, 15); 99 } 100 getImageTypes(int imageIndex)101 public Iterator getImageTypes(int imageIndex) throws IOException { 102 if (input == null) 103 throw new IllegalStateException(); 104 if (imageIndex >= 1 || imageIndex < 0) 105 throw new IndexOutOfBoundsException(); 106 107 Vector imageTypes = new Vector(); 108 imageTypes.add(ImageTypeSpecifier.createFromBufferedImageType 109 (BufferedImage.TYPE_BYTE_GRAY )); 110 return imageTypes.iterator(); 111 } 112 getNumImages(boolean allowSearch)113 public int getNumImages(boolean allowSearch) throws IOException {return 1;} getWidth(int imageIndex)114 public int getWidth(int imageIndex) throws IOException {return 1;} getHeight(int imageIndex)115 public int getHeight(int imageIndex) throws IOException {return 1;} getStreamMetadata()116 public IIOMetadata getStreamMetadata() throws IOException {return null;} getImageMetadata(int imageIndex)117 public IIOMetadata getImageMetadata(int imageIndex) 118 throws IOException {return null;} 119 } 120 } 121