1 7 8 package com.sun.imageio.spi; 9 10 import java.io.File ; 11 import java.io.RandomAccessFile ; 12 import java.util.Locale ; 13 import javax.imageio.spi.ImageInputStreamSpi ; 14 import javax.imageio.stream.ImageInputStream ; 15 import javax.imageio.stream.FileImageInputStream ; 16 17 public class RAFImageInputStreamSpi extends ImageInputStreamSpi { 18 19 private static final String vendorName = "Sun Microsystems, Inc."; 20 21 private static final String version = "1.0"; 22 23 private static final Class inputClass = RandomAccessFile .class; 24 25 public RAFImageInputStreamSpi() { 26 super(vendorName, version, inputClass); 27 } 28 29 public String getDescription(Locale locale) { 30 return "Service provider that instantiates a FileImageInputStream from a RandomAccessFile"; 31 } 32 33 public ImageInputStream createInputStreamInstance(Object input, 34 boolean useCache, 35 File cacheDir) { 36 if (input instanceof RandomAccessFile ) { 37 try { 38 return new FileImageInputStream ((RandomAccessFile )input); 39 } catch (Exception e) { 40 return null; 41 } 42 } else { 43 throw new IllegalArgumentException 44 ("input not a RandomAccessFile!"); 45 } 46 } 47 } 48 | Popular Tags |