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