KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * Copyright (c) 2004-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 org.pdfbox.cos.COSStream;
34
35 import org.pdfbox.pdmodel.PDDocument;
36
37
38
39 /**
40  * A PDStream represents a stream in a PDF document. Streams are tied to a single
41  * PDF document.
42  *
43  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
44  * @version $Revision: 1.3 $
45  */

46 public class PDObjectStream extends PDStream
47 {
48
49     /**
50      * Constructor.
51      *
52      * @param str The stream parameter.
53      */

54     public PDObjectStream( COSStream str )
55     {
56         super( str );
57     }
58     
59     /**
60      * This will create a new PDStream object.
61      *
62      * @param document The document that the stream will be part of.
63      * @return A new stream object.
64      */

65     public static PDObjectStream createStream( PDDocument document )
66     {
67         COSStream cosStream = new COSStream( document.getDocument().getScratchFile() );
68         PDObjectStream strm = new PDObjectStream( cosStream );
69         strm.getStream().setName( "Type", "ObjStm" );
70         return strm;
71     }
72     
73     /**
74      * Get the type of this object, should always return "ObjStm".
75      *
76      * @return The type of this object.
77      */

78     public String JavaDoc getType()
79     {
80         return getStream().getNameAsString( "Type" );
81     }
82     
83     /**
84      * Get the number of compressed object.
85      *
86      * @return The number of compressed objects.
87      */

88     public int getNumberOfObjects()
89     {
90         return getStream().getInt( "N", 0 );
91     }
92     
93     /**
94      * Set the number of objects.
95      *
96      * @param n The new number of objects.
97      */

98     public void setNumberOfObjects( int n )
99     {
100         getStream().setInt( "N", n );
101     }
102     
103     /**
104      * The byte offset (in the decoded stream) of the first compressed object.
105      *
106      * @return The byte offset to the first object.
107      */

108     public int getFirstByteOffset()
109     {
110         return getStream().getInt( "First", 0 );
111     }
112     
113     /**
114      * The byte offset (in the decoded stream) of the first compressed object.
115      *
116      * @param n The byte offset to the first object.
117      */

118     public void setFirstByteOffset( int n )
119     {
120         getStream().setInt( "First", n );
121     }
122     
123     /**
124      * A reference to an object stream, of which the current object stream is
125      * considered an extension.
126      *
127      * @return The object that this stream is an extension.
128      */

129     public PDObjectStream getExtends()
130     {
131         PDObjectStream retval = null;
132         COSStream stream = (COSStream)getStream().getDictionaryObject( "Extends" );
133         if( stream != null )
134         {
135             retval = new PDObjectStream( stream );
136         }
137         return retval;
138         
139     }
140     
141     /**
142      * A reference to an object stream, of which the current object stream is
143      * considered an extension.
144      *
145      * @param stream The object stream extension.
146      */

147     public void setExtends( PDObjectStream stream )
148     {
149         getStream().setItem( "Extends", stream );
150     }
151 }
Popular Tags