1 7 8 package com.sun.imageio.spi; 9 10 import java.io.File ; 11 import java.io.IOException ; 12 import java.io.OutputStream ; 13 import java.util.Locale ; 14 import javax.imageio.spi.ImageOutputStreamSpi ; 15 import javax.imageio.stream.ImageOutputStream ; 16 import javax.imageio.stream.FileCacheImageOutputStream ; 17 import javax.imageio.stream.MemoryCacheImageOutputStream ; 18 19 public class OutputStreamImageOutputStreamSpi extends ImageOutputStreamSpi { 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 outputClass = OutputStream .class; 26 27 public OutputStreamImageOutputStreamSpi() { 28 super(vendorName, version, outputClass); 29 } 30 31 public String getDescription(Locale locale) { 32 return "Service provider that instantiates an OutputStreamImageOutputStream from an OutputStream"; 33 } 34 35 public boolean canUseCacheFile() { 36 return true; 37 } 38 39 public boolean needsCacheFile() { 40 return false; 41 } 42 43 public ImageOutputStream createOutputStreamInstance(Object output, 44 boolean useCache, 45 File cacheDir) 46 throws IOException { 47 if (output instanceof OutputStream ) { 48 OutputStream os = (OutputStream )output; 49 if (useCache) { 50 return new FileCacheImageOutputStream (os, cacheDir); 51 } else { 52 return new MemoryCacheImageOutputStream (os); 53 } 54 } else { 55 throw new IllegalArgumentException (); 56 } 57 } 58 } 59 | Popular Tags |