KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)InputStreamImageInputStreamSpi.java 1.19 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.InputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.util.Locale JavaDoc;
14 import javax.imageio.spi.ImageInputStreamSpi JavaDoc;
15 import javax.imageio.stream.ImageInputStream JavaDoc;
16 import javax.imageio.stream.FileCacheImageInputStream JavaDoc;
17 import javax.imageio.stream.MemoryCacheImageInputStream JavaDoc;
18
19 public class InputStreamImageInputStreamSpi extends ImageInputStreamSpi 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 inputClass = InputStream JavaDoc.class;
26
27     public InputStreamImageInputStreamSpi() {
28         super(vendorName, version, inputClass);
29     }
30
31     public String JavaDoc getDescription(Locale JavaDoc 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 JavaDoc createInputStreamInstance(Object JavaDoc input,
44                                                       boolean useCache,
45                                                       File JavaDoc cacheDir)
46         throws IOException JavaDoc {
47         if (input instanceof InputStream JavaDoc) {
48             InputStream JavaDoc is = (InputStream JavaDoc)input;
49
50             if (useCache) {
51                 return new FileCacheImageInputStream JavaDoc(is, cacheDir);
52             } else {
53                 return new MemoryCacheImageInputStream JavaDoc(is);
54             }
55         } else {
56             throw new IllegalArgumentException JavaDoc();
57         }
58     }
59 }
60
Popular Tags