001: /**
002: * Copyright (c) 2004-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 org.pdfbox.cos.COSStream;
033:
034: import org.pdfbox.pdmodel.PDDocument;
035:
036: /**
037: * A PDStream represents a stream in a PDF document. Streams are tied to a single
038: * PDF document.
039: *
040: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
041: * @version $Revision: 1.3 $
042: */
043: public class PDObjectStream extends PDStream {
044:
045: /**
046: * Constructor.
047: *
048: * @param str The stream parameter.
049: */
050: public PDObjectStream(COSStream str) {
051: super (str);
052: }
053:
054: /**
055: * This will create a new PDStream object.
056: *
057: * @param document The document that the stream will be part of.
058: * @return A new stream object.
059: */
060: public static PDObjectStream createStream(PDDocument document) {
061: COSStream cosStream = new COSStream(document.getDocument()
062: .getScratchFile());
063: PDObjectStream strm = new PDObjectStream(cosStream);
064: strm.getStream().setName("Type", "ObjStm");
065: return strm;
066: }
067:
068: /**
069: * Get the type of this object, should always return "ObjStm".
070: *
071: * @return The type of this object.
072: */
073: public String getType() {
074: return getStream().getNameAsString("Type");
075: }
076:
077: /**
078: * Get the number of compressed object.
079: *
080: * @return The number of compressed objects.
081: */
082: public int getNumberOfObjects() {
083: return getStream().getInt("N", 0);
084: }
085:
086: /**
087: * Set the number of objects.
088: *
089: * @param n The new number of objects.
090: */
091: public void setNumberOfObjects(int n) {
092: getStream().setInt("N", n);
093: }
094:
095: /**
096: * The byte offset (in the decoded stream) of the first compressed object.
097: *
098: * @return The byte offset to the first object.
099: */
100: public int getFirstByteOffset() {
101: return getStream().getInt("First", 0);
102: }
103:
104: /**
105: * The byte offset (in the decoded stream) of the first compressed object.
106: *
107: * @param n The byte offset to the first object.
108: */
109: public void setFirstByteOffset(int n) {
110: getStream().setInt("First", n);
111: }
112:
113: /**
114: * A reference to an object stream, of which the current object stream is
115: * considered an extension.
116: *
117: * @return The object that this stream is an extension.
118: */
119: public PDObjectStream getExtends() {
120: PDObjectStream retval = null;
121: COSStream stream = (COSStream) getStream().getDictionaryObject(
122: "Extends");
123: if (stream != null) {
124: retval = new PDObjectStream(stream);
125: }
126: return retval;
127:
128: }
129:
130: /**
131: * A reference to an object stream, of which the current object stream is
132: * considered an extension.
133: *
134: * @param stream The object stream extension.
135: */
136: public void setExtends(PDObjectStream stream) {
137: getStream().setItem("Extends", stream);
138: }
139: }
|