KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pdfbox > pdmodel > common > PDMemoryStream


1 /**
2  * Copyright (c) 2005, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package org.pdfbox.pdmodel.common;
32
33 import java.io.ByteArrayInputStream JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.io.InputStream JavaDoc;
36 import java.io.OutputStream JavaDoc;
37
38 import java.util.List JavaDoc;
39
40 import org.pdfbox.cos.COSBase;
41 import org.pdfbox.cos.COSStream;
42
43 import org.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
44
45 /**
46  * A PDStream represents a stream in a PDF document. Streams are tied to a single
47  * PDF document.
48  *
49  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
50  * @version $Revision: 1.2 $
51  */

52 public class PDMemoryStream extends PDStream
53 {
54     private byte[] data;
55     
56     /**
57      * This will create a new PDStream object.
58      *
59      * @param buffer The data for this in memory stream.
60      */

61     public PDMemoryStream( byte[] buffer )
62     {
63         data = buffer;
64     }
65     
66
67     
68     /**
69      * If there are not compression filters on the current stream then this
70      * will add a compression filter, flate compression for example.
71      */

72     public void addCompression()
73     {
74         //no compression to add
75
}
76
77
78
79     /**
80      * Convert this standard java object to a COS object.
81      *
82      * @return The cos object that matches this Java object.
83      */

84     public COSBase getCOSObject()
85     {
86         throw new UnsupportedOperationException JavaDoc( "not supported for memory stream" );
87     }
88     
89     /**
90      * This will get a stream that can be written to.
91      *
92      * @return An output stream to write data to.
93      *
94      * @throws IOException If an IO error occurs during writing.
95      */

96     public OutputStream JavaDoc createOutputStream() throws IOException JavaDoc
97     {
98         throw new UnsupportedOperationException JavaDoc( "not supported for memory stream" );
99     }
100     
101     /**
102      * This will get a stream that can be read from.
103      *
104      * @return An input stream that can be read from.
105      *
106      * @throws IOException If an IO error occurs during reading.
107      */

108     public InputStream JavaDoc createInputStream() throws IOException JavaDoc
109     {
110         return new ByteArrayInputStream JavaDoc( data );
111     }
112     
113     /**
114      * This will get a stream with some filters applied but not others. This is useful
115      * when doing images, ie filters = [flate,dct], we want to remove flate but leave dct
116      *
117      * @param stopFilters A list of filters to stop decoding at.
118      * @return A stream with decoded data.
119      * @throws IOException If there is an error processing the stream.
120      */

121     public InputStream JavaDoc getPartiallyFilteredStream( List JavaDoc stopFilters ) throws IOException JavaDoc
122     {
123         return createInputStream();
124     }
125     
126     /**
127      * Get the cos stream associated with this object.
128      *
129      * @return The cos object that matches this Java object.
130      */

131     public COSStream getStream()
132     {
133         throw new UnsupportedOperationException JavaDoc( "not supported for memory stream" );
134     }
135     
136     /**
137      * This will get the length of the filtered/compressed stream. This is readonly in the
138      * PD Model and will be managed by this class.
139      *
140      * @return The length of the filtered stream.
141      */

142     public int getLength()
143     {
144         return data.length;
145     }
146     
147     /**
148      * This will get the list of filters that are associated with this stream. Or
149      * null if there are none.
150      * @return A list of all encoding filters to apply to this stream.
151      */

152     public List JavaDoc getFilters()
153     {
154         return null;
155     }
156     
157     /**
158      * This will set the filters that are part of this stream.
159      *
160      * @param filters The filters that are part of this stream.
161      */

162     public void setFilters( List JavaDoc filters )
163     {
164         throw new UnsupportedOperationException JavaDoc( "not supported for memory stream" );
165     }
166     
167     /**
168      * Get the list of decode parameters. Each entry in the list will refer to
169      * an entry in the filters list.
170      *
171      * @return The list of decode parameters.
172      *
173      * @throws IOException if there is an error retrieving the parameters.
174      */

175     public List JavaDoc getDecodeParams() throws IOException JavaDoc
176     {
177         return null;
178     }
179     
180     /**
181      * This will set the list of decode params.
182      *
183      * @param decodeParams The list of decode params.
184      */

185     public void setDecodeParams( List JavaDoc decodeParams )
186     {
187         //do nothing
188
}
189     
190     /**
191      * This will get the file specification for this stream. This is only
192      * required for external files.
193      *
194      * @return The file specification.
195      */

196     public PDFileSpecification getFile()
197     {
198         return null;
199     }
200     
201     /**
202      * Set the file specification.
203      * @param f The file specification.
204      */

205     public void setFile( PDFileSpecification f )
206     {
207         //do nothing.
208
}
209     
210     /**
211      * This will get the list of filters that are associated with this stream. Or
212      * null if there are none.
213      * @return A list of all encoding filters to apply to this stream.
214      */

215     public List JavaDoc getFileFilters()
216     {
217         return null;
218     }
219     
220     /**
221      * This will set the filters that are part of this stream.
222      *
223      * @param filters The filters that are part of this stream.
224      */

225     public void setFileFilters( List JavaDoc filters )
226     {
227         //do nothing.
228
}
229     
230     /**
231      * Get the list of decode parameters. Each entry in the list will refer to
232      * an entry in the filters list.
233      *
234      * @return The list of decode parameters.
235      *
236      * @throws IOException if there is an error retrieving the parameters.
237      */

238     public List JavaDoc getFileDecodeParams() throws IOException JavaDoc
239     {
240         return null;
241     }
242     
243     /**
244      * This will set the list of decode params.
245      *
246      * @param decodeParams The list of decode params.
247      */

248     public void setFileDecodeParams( List JavaDoc decodeParams )
249     {
250         //do nothing
251
}
252     
253     /**
254      * This will copy the stream into a byte array.
255      *
256      * @return The byte array of the filteredStream
257      * @throws IOException When getFilteredStream did not work
258      */

259     public byte[] getByteArray() throws IOException JavaDoc
260     {
261         return data;
262     }
263     
264     /**
265      * Get the metadata that is part of the document catalog. This will
266      * return null if there is no meta data for this object.
267      *
268      * @return The metadata for this object.
269      */

270     public PDMetadata getMetadata()
271     {
272         return null;
273     }
274     
275     /**
276      * Set the metadata for this object. This can be null.
277      *
278      * @param meta The meta data for this object.
279      */

280     public void setMetadata( PDMetadata meta )
281     {
282         //do nothing
283
}
284 }
Popular Tags