001: /**
002: * Copyright (c) 2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.pdmodel.common;
031:
032: import java.io.ByteArrayInputStream;
033: import java.io.IOException;
034: import java.io.InputStream;
035: import java.io.OutputStream;
036:
037: import java.util.List;
038:
039: import org.pdfbox.cos.COSBase;
040: import org.pdfbox.cos.COSStream;
041:
042: import org.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
043:
044: /**
045: * A PDStream represents a stream in a PDF document. Streams are tied to a single
046: * PDF document.
047: *
048: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
049: * @version $Revision: 1.2 $
050: */
051: public class PDMemoryStream extends PDStream {
052: private byte[] data;
053:
054: /**
055: * This will create a new PDStream object.
056: *
057: * @param buffer The data for this in memory stream.
058: */
059: public PDMemoryStream(byte[] buffer) {
060: data = buffer;
061: }
062:
063: /**
064: * If there are not compression filters on the current stream then this
065: * will add a compression filter, flate compression for example.
066: */
067: public void addCompression() {
068: //no compression to add
069: }
070:
071: /**
072: * Convert this standard java object to a COS object.
073: *
074: * @return The cos object that matches this Java object.
075: */
076: public COSBase getCOSObject() {
077: throw new UnsupportedOperationException(
078: "not supported for memory stream");
079: }
080:
081: /**
082: * This will get a stream that can be written to.
083: *
084: * @return An output stream to write data to.
085: *
086: * @throws IOException If an IO error occurs during writing.
087: */
088: public OutputStream createOutputStream() throws IOException {
089: throw new UnsupportedOperationException(
090: "not supported for memory stream");
091: }
092:
093: /**
094: * This will get a stream that can be read from.
095: *
096: * @return An input stream that can be read from.
097: *
098: * @throws IOException If an IO error occurs during reading.
099: */
100: public InputStream createInputStream() throws IOException {
101: return new ByteArrayInputStream(data);
102: }
103:
104: /**
105: * This will get a stream with some filters applied but not others. This is useful
106: * when doing images, ie filters = [flate,dct], we want to remove flate but leave dct
107: *
108: * @param stopFilters A list of filters to stop decoding at.
109: * @return A stream with decoded data.
110: * @throws IOException If there is an error processing the stream.
111: */
112: public InputStream getPartiallyFilteredStream(List stopFilters)
113: throws IOException {
114: return createInputStream();
115: }
116:
117: /**
118: * Get the cos stream associated with this object.
119: *
120: * @return The cos object that matches this Java object.
121: */
122: public COSStream getStream() {
123: throw new UnsupportedOperationException(
124: "not supported for memory stream");
125: }
126:
127: /**
128: * This will get the length of the filtered/compressed stream. This is readonly in the
129: * PD Model and will be managed by this class.
130: *
131: * @return The length of the filtered stream.
132: */
133: public int getLength() {
134: return data.length;
135: }
136:
137: /**
138: * This will get the list of filters that are associated with this stream. Or
139: * null if there are none.
140: * @return A list of all encoding filters to apply to this stream.
141: */
142: public List getFilters() {
143: return null;
144: }
145:
146: /**
147: * This will set the filters that are part of this stream.
148: *
149: * @param filters The filters that are part of this stream.
150: */
151: public void setFilters(List filters) {
152: throw new UnsupportedOperationException(
153: "not supported for memory stream");
154: }
155:
156: /**
157: * Get the list of decode parameters. Each entry in the list will refer to
158: * an entry in the filters list.
159: *
160: * @return The list of decode parameters.
161: *
162: * @throws IOException if there is an error retrieving the parameters.
163: */
164: public List getDecodeParams() throws IOException {
165: return null;
166: }
167:
168: /**
169: * This will set the list of decode params.
170: *
171: * @param decodeParams The list of decode params.
172: */
173: public void setDecodeParams(List decodeParams) {
174: //do nothing
175: }
176:
177: /**
178: * This will get the file specification for this stream. This is only
179: * required for external files.
180: *
181: * @return The file specification.
182: */
183: public PDFileSpecification getFile() {
184: return null;
185: }
186:
187: /**
188: * Set the file specification.
189: * @param f The file specification.
190: */
191: public void setFile(PDFileSpecification f) {
192: //do nothing.
193: }
194:
195: /**
196: * This will get the list of filters that are associated with this stream. Or
197: * null if there are none.
198: * @return A list of all encoding filters to apply to this stream.
199: */
200: public List getFileFilters() {
201: return null;
202: }
203:
204: /**
205: * This will set the filters that are part of this stream.
206: *
207: * @param filters The filters that are part of this stream.
208: */
209: public void setFileFilters(List filters) {
210: //do nothing.
211: }
212:
213: /**
214: * Get the list of decode parameters. Each entry in the list will refer to
215: * an entry in the filters list.
216: *
217: * @return The list of decode parameters.
218: *
219: * @throws IOException if there is an error retrieving the parameters.
220: */
221: public List getFileDecodeParams() throws IOException {
222: return null;
223: }
224:
225: /**
226: * This will set the list of decode params.
227: *
228: * @param decodeParams The list of decode params.
229: */
230: public void setFileDecodeParams(List decodeParams) {
231: //do nothing
232: }
233:
234: /**
235: * This will copy the stream into a byte array.
236: *
237: * @return The byte array of the filteredStream
238: * @throws IOException When getFilteredStream did not work
239: */
240: public byte[] getByteArray() throws IOException {
241: return data;
242: }
243:
244: /**
245: * Get the metadata that is part of the document catalog. This will
246: * return null if there is no meta data for this object.
247: *
248: * @return The metadata for this object.
249: */
250: public PDMetadata getMetadata() {
251: return null;
252: }
253:
254: /**
255: * Set the metadata for this object. This can be null.
256: *
257: * @param meta The meta data for this object.
258: */
259: public void setMetadata(PDMetadata meta) {
260: //do nothing
261: }
262: }
|