KickJava   Java API By Example, From Geeks To Geeks.

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


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