Class CosStream
- java.lang.Object
-
- com.adobe.internal.pdftoolkit.core.cos.CosObject
-
- com.adobe.internal.pdftoolkit.core.cos.CosContainer
-
- com.adobe.internal.pdftoolkit.core.cos.CosDictionary
-
- com.adobe.internal.pdftoolkit.core.cos.CosStream
-
- Direct Known Subclasses:
CosObjectStream
public class CosStream extends CosDictionary
Represents a COS stream as defined in section 3.2.7 of the PDF Reference Manual version 1.4. The stream data can be represented in encoded or decoded form. In a PDF file the stream data are encoded according to the value of the /Filters entry in the stream dictionary [if one exists]. For those rare occasions when an application processes encoded stream data (mostly when it copies the stream from one external location to another) the CosStream class contains getStreamEncoded(...) and newDataEncoded(...) methods. These methods deliver/accept data in the encoded form. When the data are placed in the CosStream object with newDataEncoded(...) methods, the write() method does not encode the stream data before writing them to the PDF file. The consumers of the CosStream class should not mix CosStream methods that deliver/accept the stream data in the decoded and encoded form for the same CosStream object.
-
-
Field Summary
-
Fields inherited from class com.adobe.internal.pdftoolkit.core.cos.CosObject
DIRECT, INDIRECT, t_Array, t_Boolean, t_Dictionary, t_KeyAbsent, t_Name, t_Null, t_Numeric, t_ObjectRef, t_Stream, t_String
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> boolean
copyStream(T destStm, boolean encoded)
Copy the stream data into the given OutputStream.boolean
equals(CosObject value)
This method follows three criteria to check: 1) both should be instance of CosStream.CosArray
getInputFiltersList()
This method returns the filter list with which this stream is encoded currently.long
getLength()
return the length of the CosStream.CosArray
getOutputFiltersList()
Returns filter list that shall be used when this stream is written.long
getStreamDataOffset()
Return stream data offset or -1 if object has never been written.InputByteStream
getStreamDecoded()
Obtains a slice of the underlying InputByteStream.java.io.InputStream
getStreamDecodedNoCopying()
Returns underlying stream asInputStream
.InputByteStream
getStreamEncoded()
Obtains a slice of the underlying InputByteStream.int
getType()
return the type of this CosObjectboolean
isEncoded()
Returns true if this stream is encoded else false.void
newDataDecoded(InputByteStream byteStream)
Set new unencrypted and decoded data for this CosStream.void
newDataEncoded(InputByteStream byteStream)
Set new unencrypted but already encoded data for this CosStream.CosObject
put(ASName key, CosObject cosObject)
This method is overridden from CosDictionary in order to catch any changes that might affect the ability to decode the stream bodyCosObject
remove(ASName key)
Removes the key mapping from the dictionary.void
setOutputFiltersList(CosArray filters)
This method sets the filter list which are used while writing this stream.java.lang.String
toString()
-
Methods inherited from class com.adobe.internal.pdftoolkit.core.cos.CosDictionary
clear, containsKey, copy, get, getBoolean, getCosArray, getCosDictionary, getCosStream, getCosString, getDouble, getInheritable, getInt, getKeyForValue, getKeys, getLong, getName, getStream, getString, getType, getValue, getValuesIterator, isEmpty, isInvalidDict, keyIterator, keySet, put, put, put, put, put, put, put, put, put, put, put, put, put, setEncryptionState, setRepairedValue, size, values
-
Methods inherited from class com.adobe.internal.pdftoolkit.core.cos.CosContainer
findObjPos, markNotDirty
-
Methods inherited from class com.adobe.internal.pdftoolkit.core.cos.CosObject
booleanValue, doubleValue, equals, getDocument, getObjEOF, getObjGen, getObjNum, getObjPos, getObjRevision, getStreamManager, hexStringValue, intValue, isCompressed, isDirty, isIndirect, longValue, nameValue, numberValue, stringValue, textValue
-
-
-
-
Method Detail
-
put
public CosObject put(ASName key, CosObject cosObject) throws PDFCosParseException, PDFIOException, PDFSecurityException
This method is overridden from CosDictionary in order to catch any changes that might affect the ability to decode the stream body- Overrides:
put
in classCosDictionary
- Parameters:
key
- Key for the entrycosObject
- CosObject value for the entry- Returns:
- CosObject value added to the dictionary.
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
-
remove
public CosObject remove(ASName key) throws PDFCosParseException, PDFIOException, PDFSecurityException
Description copied from class:CosDictionary
Removes the key mapping from the dictionary.- Overrides:
remove
in classCosDictionary
- Parameters:
key
- Key mapping to remove- Returns:
- If an object was already present in the dictionary using the specified key, that object is returned. Otherwise, null is returned.
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
-
getType
public int getType()
return the type of this CosObject- Overrides:
getType
in classCosDictionary
- Returns:
- one of the t_Mumble static final int values defined above
-
getLength
public long getLength() throws PDFCosParseException, PDFIOException, PDFSecurityException
return the length of the CosStream.
-
getStreamDecoded
public InputByteStream getStreamDecoded() throws PDFCosParseException, PDFIOException, PDFSecurityException
Obtains a slice of the underlying InputByteStream. The caller is responsible for closing this InputByteStream when they are finished with it.- Returns:
- InputByteStream for reading the COS stream's data. The stream is passed through any registered filters.
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
-
getStreamDecodedNoCopying
public java.io.InputStream getStreamDecodedNoCopying() throws PDFCosParseException, PDFIOException, PDFSecurityException
Returns underlying stream asInputStream
. If the stream is encrypted, then a copy of decrypted stream is returned. In case of filters, filter stream is returned instead of copying it. The caller is responsible for closing this InputStream when they are finished with it.- Returns:
InputStream
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
-
getStreamEncoded
public InputByteStream getStreamEncoded() throws PDFCosParseException, PDFIOException, PDFSecurityException
Obtains a slice of the underlying InputByteStream. The caller is responsible for closing this InputByteStream when they are finished with it.- Returns:
- ByteStream for reading the COS stream's data without passing them through any registered filters.
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
-
copyStream
public <T> boolean copyStream(T destStm, boolean encoded) throws PDFCosParseException, PDFIOException, PDFSecurityException
Copy the stream data into the given OutputStream. This is intended for use in exporting data for use outside of the PDF Toolkit.- Parameters:
destStm
- the destination for the stream dataencoded
- copy the data as encoded if true; decoded if false- Returns:
- true if data was copied into the destination; false otherwise
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
-
newDataDecoded
public void newDataDecoded(InputByteStream byteStream) throws PDFCosParseException, PDFIOException, PDFSecurityException
Set new unencrypted and decoded data for this CosStream. This method takes the InputByteStream from the caller. After this method returns the InputByteStream belongs to this CosStream and should NOT be used by the caller ever again. If the caller needs to continue to use the InputByteStream then it should make a slice from the InputByteStream before calling this method.- Parameters:
byteStream
- the new data stream to give to this object- Throws:
PDFSecurityException
PDFIOException
PDFCosParseException
-
newDataEncoded
public void newDataEncoded(InputByteStream byteStream) throws PDFCosParseException, PDFIOException, PDFSecurityException
Set new unencrypted but already encoded data for this CosStream. This method takes the InputByteStream from the caller. After this method returns the InputByteStream belongs to this CosStream and should NOT be used by the caller ever again. If the caller needs to continue to use the InputByteStream then it should make a slice from the InputByteStream before calling this method.- Parameters:
byteStream
- the new data stream to give to this object- Throws:
PDFSecurityException
PDFIOException
PDFCosParseException
-
setOutputFiltersList
public void setOutputFiltersList(CosArray filters) throws PDFCosParseException, PDFIOException, java.io.IOException, PDFSecurityException
This method sets the filter list which are used while writing this stream.- Parameters:
filters
-- Throws:
PDFCosParseException
java.io.IOException
PDFSecurityException
PDFIOException
-
getOutputFiltersList
public CosArray getOutputFiltersList()
Returns filter list that shall be used when this stream is written.
-
getInputFiltersList
public CosArray getInputFiltersList() throws PDFCosParseException, PDFIOException, PDFSecurityException
This method returns the filter list with which this stream is encoded currently.
-
getStreamDataOffset
public long getStreamDataOffset()
Return stream data offset or -1 if object has never been written.
-
equals
public boolean equals(CosObject value)
This method follows three criteria to check: 1) both should be instance of CosStream. 2) SHA-1 compressed byte Stream of one should be equal to other one. 3) their dictionary should be equal. Returns false if they are not on same document. This maintains a continuously growing list of indirect CosObject pairs, which have already been compared, to get rid of infinite recursion. This method can take some time if called on large Cos Objects.- Overrides:
equals
in classCosDictionary
- Parameters:
value
-- Returns:
- boolean
-
isEncoded
public boolean isEncoded() throws PDFCosParseException, PDFIOException, PDFSecurityException, java.io.IOException
Returns true if this stream is encoded else false.- Returns:
- boolean
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
java.io.IOException
-
-