KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > gif > GIFImageReaderSpi


1 /*
2  * @(#)GIFImageReaderSpi.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.plugins.gif;
9
10 import java.io.IOException JavaDoc;
11 import java.util.Locale JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import javax.imageio.ImageReader JavaDoc;
14 import javax.imageio.metadata.IIOMetadataFormat JavaDoc;
15 import javax.imageio.metadata.IIOMetadataFormatImpl JavaDoc;
16 import javax.imageio.spi.ImageReaderSpi JavaDoc;
17 import javax.imageio.stream.ImageInputStream JavaDoc;
18
19 /**
20  * @version 0.5
21  */

22 public class GIFImageReaderSpi extends ImageReaderSpi JavaDoc {
23
24     private static final String JavaDoc vendorName = "Sun Microsystems, Inc.";
25
26     private static final String JavaDoc version = "1.0";
27
28     private static final String JavaDoc[] names = { "gif" };
29
30     private static final String JavaDoc[] suffixes = { "gif" };
31
32     private static final String JavaDoc[] MIMETypes = { "image/gif" };
33
34     private static final String JavaDoc readerClassName =
35         "com.sun.imageio.plugins.gif.GIFImageReader";
36
37     private static final String JavaDoc[] writerSpiNames = null;
38
39     public GIFImageReaderSpi() {
40         super(vendorName,
41               version,
42               names,
43               suffixes,
44               MIMETypes,
45               readerClassName,
46               STANDARD_INPUT_TYPE,
47               writerSpiNames,
48               true,
49               GIFStreamMetadata.nativeMetadataFormatName,
50               "com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
51               null, null,
52               true,
53               GIFImageMetadata.nativeMetadataFormatName,
54               "com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
55               null, null
56               );
57     }
58
59     public String JavaDoc getDescription(Locale JavaDoc locale) {
60         return "Standard GIF image reader";
61     }
62
63     public boolean canDecodeInput(Object JavaDoc input) throws IOException JavaDoc {
64         if (!(input instanceof ImageInputStream JavaDoc)) {
65             return false;
66         }
67         
68         ImageInputStream JavaDoc stream = (ImageInputStream JavaDoc)input;
69         byte[] b = new byte[6];
70         stream.mark();
71         stream.readFully(b);
72         stream.reset();
73
74         return b[0] == 'G' && b[1] == 'I' && b[2] == 'F' && b[3] == '8' &&
75             (b[4] == '7' || b[4] == '9') && b[5] == 'a';
76     }
77
78     public ImageReader JavaDoc createReaderInstance(Object JavaDoc extension) {
79         return new GIFImageReader(this);
80     }
81
82 }
83
Popular Tags