KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > spi > OutputStreamImageOutputStreamSpi


1 /*
2  * @(#)OutputStreamImageOutputStreamSpi.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.spi;
9
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.OutputStream JavaDoc;
13 import java.util.Locale JavaDoc;
14 import javax.imageio.spi.ImageOutputStreamSpi JavaDoc;
15 import javax.imageio.stream.ImageOutputStream JavaDoc;
16 import javax.imageio.stream.FileCacheImageOutputStream JavaDoc;
17 import javax.imageio.stream.MemoryCacheImageOutputStream JavaDoc;
18
19 public class OutputStreamImageOutputStreamSpi extends ImageOutputStreamSpi JavaDoc {
20
21     private static final String JavaDoc vendorName = "Sun Microsystems, Inc.";
22
23     private static final String JavaDoc version = "1.0";
24
25     private static final Class JavaDoc outputClass = OutputStream JavaDoc.class;
26
27     public OutputStreamImageOutputStreamSpi() {
28         super(vendorName, version, outputClass);
29     }
30
31     public String JavaDoc getDescription(Locale JavaDoc 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 JavaDoc createOutputStreamInstance(Object JavaDoc output,
44                                                         boolean useCache,
45                                                         File JavaDoc cacheDir)
46         throws IOException JavaDoc {
47         if (output instanceof OutputStream JavaDoc) {
48             OutputStream JavaDoc os = (OutputStream JavaDoc)output;
49             if (useCache) {
50                 return new FileCacheImageOutputStream JavaDoc(os, cacheDir);
51             } else {
52                 return new MemoryCacheImageOutputStream JavaDoc(os);
53             }
54         } else {
55             throw new IllegalArgumentException JavaDoc();
56         }
57     }
58 }
59
Popular Tags