1 /** 2 * Copyright (c) 2015, 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 package simptest; 25 26 import java.awt.image.BufferedImage; 27 import java.io.ByteArrayInputStream; 28 import java.io.IOException; 29 import java.util.Iterator; 30 import javax.imageio.ImageIO; 31 import javax.imageio.ImageReader; 32 import javax.imageio.metadata.IIOMetadata; 33 import javax.imageio.metadata.IIOMetadataFormat; 34 import javax.imageio.spi.ImageReaderSpi; 35 import javax.imageio.stream.ImageInputStream; 36 import javax.imageio.stream.MemoryCacheImageInputStream; 37 38 public class TestSIMPPlugin { 39 40 static byte[] simpData = { (byte)'S', (byte)'I', (byte)'M', (byte)'P', 41 1, 1, 0, 0, 0}; 42 43 public static void main(String args[]) throws Exception { 44 Iterator<ImageReader> readers = ImageIO.getImageReadersBySuffix("simp"); 45 ImageReader simpReader = null; 46 if (readers.hasNext()) { 47 simpReader = readers.next(); 48 System.out.println("reader="+simpReader); 49 } 50 if (simpReader == null) { 51 throw new RuntimeException("Reader not found."); 52 } 53 54 ImageReaderSpi spi = simpReader.getOriginatingProvider(); 55 IIOMetadataFormat spiFmt = 56 spi.getImageMetadataFormat("simp_metadata_1.0"); 57 System.out.println("fmt from SPI=" + spiFmt); 58 59 ByteArrayInputStream bais = new ByteArrayInputStream(simpData); 60 ImageInputStream iis = new MemoryCacheImageInputStream(bais); 61 simpReader.setInput(iis); 62 BufferedImage bi = simpReader.read(0); 63 System.out.println(bi); 64 IIOMetadata metadata = simpReader.getImageMetadata(0); 65 System.out.println("Image metadata="+metadata); 66 IIOMetadataFormat format = 67 metadata.getMetadataFormat("simp_metadata_1.0"); 68 System.out.println("Image metadata format="+format); 69 if (format == null) { 70 throw new RuntimeException("MetadataFormat not found."); 71 } 72 } 73 }