01: /*
02: * $RCSfile: GZIPTileDecoderFactory.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:56:57 $
10: * $State: Exp $
11: */package com.sun.media.jai.tilecodec;
12:
13: import java.io.InputStream;
14: import java.util.Vector;
15: import java.util.zip.GZIPInputStream;
16: import javax.media.jai.ParameterListDescriptorImpl;
17: import javax.media.jai.remote.NegotiableCapability;
18: import javax.media.jai.tilecodec.TileDecoder;
19: import javax.media.jai.tilecodec.TileDecoderFactory;
20: import javax.media.jai.tilecodec.TileCodecParameterList;
21:
22: /**
23: * A factory for creating <code>GZIPTileDecoder</code>s.
24: *
25: * <p> This class stipulates that the capabilities of the
26: * <code>TileDecoder</code> be specified by implementing the
27: * <code>getDecodingCapability()</code> method.
28: *
29: * @see javax.media.jai.remote.NegotiableCapability
30: */
31: public class GZIPTileDecoderFactory implements TileDecoderFactory {
32:
33: /**
34: * Creates a <code>GZIPTileDecoder</code> capable of decoding the encoded
35: * data from the given <code>InputStream</code> using the specified
36: * <code>TileCodecParameterList</code> containing the decoding
37: * parameters to be used.
38: *
39: * <p> This method can return null if the <code>TileDecoder</code> is not
40: * capable of producing output for the given set of parameters.
41: * For example, if a <code>TileDecoder</code> is only capable of dealing
42: * with a jpeg quality factor of 0.5, and the associated
43: * <code>TileCodecParameterList</code> specifies a quality factor of 0.75,
44: * null should be returned.
45: *
46: * <p>It is recommended that the data in the supplied
47: * <code>InputStream</code> not be used as a factor in determining
48: * whether this <code>InputStream</code> can be successfully decoded,
49: * unless the supplied <code>InputStream</code> is known to be rewindable
50: * (i.e. its <code>markSupported()</code> method returns true or it has
51: * additional functionality that allows backward seeking). It is required
52: * that <code>the</code> InputStream contain the same data on
53: * returning from this method as before this method was called.
54: * In other words, the <code>InputStream</code> should only be used as a
55: * discriminator if it can be rewound to its starting position
56: * before returning from this method. Note that wrapping the
57: * incoming <code>InputStream</code> in a <code>PushbackInputStream</code>
58: * and then rewinding the <code>PushbackInputStream</code> before returning
59: * does not rewind the wrapped <code>InputStream</code>.
60: *
61: * <p> If the supplied <code>TileCodecParameterList</code> is null,
62: * a default <code>TileCodecParameterList</code> from the
63: * <code>TileCodecDescriptor</code> will be used to create the decoder.
64: *
65: * <p> Exceptions thrown by the <code>TileDecoder</code> will be
66: * caught by this method and will not be propagated.
67: *
68: * @param input The <code>InputStream</code> containing the encoded data
69: * to decode.
70: * @param param The parameters to be be used in the decoding process.
71: * @throws IllegalArgumentException if input is null.
72: */
73: public TileDecoder createDecoder(InputStream input,
74: TileCodecParameterList param) {
75:
76: if (input == null)
77: throw new IllegalArgumentException(JaiI18N
78: .getString("TileDecoder0"));
79:
80: return new GZIPTileDecoder(input, param);
81: }
82:
83: /**
84: * Returns the capabilities of this <code>TileDecoder</code> as a
85: * <code>NegotiableCapability</code>.
86: */
87: public NegotiableCapability getDecodeCapability() {
88:
89: Vector generators = new Vector();
90: generators.add(GZIPTileDecoderFactory.class);
91:
92: return new NegotiableCapability("tileCodec", "gzip",
93: generators, new ParameterListDescriptorImpl(null, null,
94: null, null, null), false);
95: }
96: }
|