1 7 8 package com.sun.imageio.spi; 9 10 import java.io.File ; 11 import java.io.InputStream ; 12 import java.io.IOException ; 13 import java.util.Locale ; 14 import javax.imageio.spi.ImageInputStreamSpi ; 15 import javax.imageio.stream.ImageInputStream ; 16 import javax.imageio.stream.FileCacheImageInputStream ; 17 import javax.imageio.stream.MemoryCacheImageInputStream ; 18 19 public class InputStreamImageInputStreamSpi extends ImageInputStreamSpi { 20 21 private static final String vendorName = "Sun Microsystems, Inc."; 22 23 private static final String version = "1.0"; 24 25 private static final Class inputClass = InputStream .class; 26 27 public InputStreamImageInputStreamSpi() { 28 super(vendorName, version, inputClass); 29 } 30 31 public String getDescription(Locale locale) { 32 return "Service provider that instantiates a FileCacheImageInputStream or MemoryCacheImageInputStream from an InputStream"; 33 } 34 35 public boolean canUseCacheFile() { 36 return true; 37 } 38 39 public boolean needsCacheFile() { 40 return false; 41 } 42 43 public ImageInputStream createInputStreamInstance(Object input, 44 boolean useCache, 45 File cacheDir) 46 throws IOException { 47 if (input instanceof InputStream ) { 48 InputStream is = (InputStream )input; 49 50 if (useCache) { 51 return new FileCacheImageInputStream (is, cacheDir); 52 } else { 53 return new MemoryCacheImageInputStream (is); 54 } 55 } else { 56 throw new IllegalArgumentException (); 57 } 58 } 59 } 60 | Popular Tags |