1 /* 2 * Copyright (c) 2000, 2004, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.imageio.plugins.jpeg; 27 28 import java.util.Locale; 29 import javax.imageio.spi.ImageReaderSpi; 30 import javax.imageio.stream.ImageInputStream; 31 import javax.imageio.spi.IIORegistry; 32 import javax.imageio.spi.ServiceRegistry; 33 import java.io.IOException; 34 import javax.imageio.ImageReader; 35 import javax.imageio.IIOException; 36 37 public class JPEGImageReaderSpi extends ImageReaderSpi { 38 39 private static String [] writerSpiNames = 40 {"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"}; 41 42 public JPEGImageReaderSpi() { 43 super(JPEG.vendor, 44 JPEG.version, 45 JPEG.names, 46 JPEG.suffixes, 47 JPEG.MIMETypes, 48 "com.sun.imageio.plugins.jpeg.JPEGImageReader", 49 new Class[] { ImageInputStream.class }, 50 writerSpiNames, 51 true, 52 JPEG.nativeStreamMetadataFormatName, 53 JPEG.nativeStreamMetadataFormatClassName, 54 null, null, 55 true, 56 JPEG.nativeImageMetadataFormatName, 57 JPEG.nativeImageMetadataFormatClassName, 58 null, null 59 ); 60 } 61 62 public String getDescription(Locale locale) { 63 return "Standard JPEG Image Reader"; 64 } 65 66 public boolean canDecodeInput(Object source) throws IOException { 67 if (!(source instanceof ImageInputStream)) { 68 return false; 69 } 70 ImageInputStream iis = (ImageInputStream) source; 71 iis.mark(); 72 // If the first two bytes are a JPEG SOI marker, it's probably 73 // a JPEG file. If they aren't, it definitely isn't a JPEG file. 74 int byte1 = iis.read(); 75 int byte2 = iis.read(); 76 iis.reset(); 77 if ((byte1 == 0xFF) && (byte2 == JPEG.SOI)) { 78 return true; 79 } 80 return false; 81 } 82 83 public ImageReader createReaderInstance(Object extension) 84 throws IIOException { 85 return new JPEGImageReader(this); 86 } 87 88 }