01: /*
02: * $RCSfile: RawTileDecoder.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.awt.Point;
14: import java.awt.RenderingHints;
15: import java.awt.image.Raster;
16: import java.io.InputStream;
17: import java.io.ObjectInputStream;
18: import java.io.IOException;
19: import javax.media.jai.JAI;
20: import javax.media.jai.ParameterListDescriptor;
21: import javax.media.jai.tilecodec.TileCodecParameterList;
22: import javax.media.jai.tilecodec.TileDecoderImpl;
23: import javax.media.jai.util.ImagingListener;
24: import com.sun.media.jai.util.ImageUtil;
25:
26: /**
27: * A concrete implementation of the <code>TileDecoderImpl</code> class
28: * for the raw tile codec.
29: */
30: public class RawTileDecoder extends TileDecoderImpl {
31: /**
32: * Constructs a <code>RawTileDecoder</code>.
33: * <code>RawTileDecoder</code> may throw a
34: * <code>IllegalArgumentException</code> if <code>param</code>'s
35: * <code>getParameterListDescriptor()</code> method does not return
36: * the same descriptor as that from the associated
37: * <code>TileCodecDescriptor</code>'s
38: * <code>getParameterListDescriptor</code> method for the "tileDecoder"
39: * registry mode.
40: *
41: * <p> If param is null, then the default parameter list for decoding
42: * as defined by the associated <code>TileCodecDescriptor</code>'s
43: * <code>getDefaultParameters()</code> method will be used for decoding.
44: *
45: * @param input The <code>InputStream</code> to decode data from.
46: * @param param The object containing the tile decoding parameters.
47: * @throws IllegalArgumentException if input is null.
48: * @throws IllegalArgumentException if param is not appropriate.
49: */
50: public RawTileDecoder(InputStream input,
51: TileCodecParameterList param) {
52: super ("raw", input, param);
53: }
54:
55: /**
56: * Returns a <code>Raster</code> that contains the decoded contents
57: * of the <code>InputStream</code> associated with this
58: * <code>TileDecoder</code>.
59: *
60: * <p>This method can perform the decoding correctly only when
61: * <code>includesLocationInfo()</code> returns true.
62: *
63: * @throws IOException if an I/O error occurs while reading from the
64: * associated InputStream.
65: * @throws IllegalArgumentException if the associated
66: * TileCodecDescriptor's includesLocationInfo() returns false.
67: */
68: public Raster decode() throws IOException {
69:
70: ObjectInputStream ois = new ObjectInputStream(inputStream);
71:
72: try {
73: Object object = ois.readObject();
74: return TileCodecUtils.deserializeRaster(object);
75: } catch (ClassNotFoundException e) {
76: ImagingListener listener = ImageUtil
77: .getImagingListener((RenderingHints) null);
78: listener.errorOccurred(JaiI18N.getString("ClassNotFound"),
79: e, this , false);
80: // e.printStackTrace();
81: return null;
82: } finally {
83: ois.close();
84: }
85: }
86:
87: public Raster decode(Point location) throws IOException {
88: return decode();
89: }
90: }
|