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
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
Modifier and TypeMethodDescription<T> boolean
copyStream
(T destStm, boolean encoded) Copy the stream data into the given OutputStream.boolean
This method follows three criteria to check: 1) both should be instance of CosStream.This method returns the filter list with which this stream is encoded currently.long
return the length of the CosStream.Returns filter list that shall be used when this stream is written.long
Return stream data offset or -1 if object has never been written.Obtains a slice of the underlying InputByteStream.Returns underlying stream asInputStream
.Obtains a slice of the underlying InputByteStream.int
getType()
return the type of this CosObjectboolean
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.This method is overridden from CosDictionary in order to catch any changes that might affect the ability to decode the stream bodyRemoves the key mapping from the dictionary.void
setOutputFiltersList
(CosArray filters) This method sets the filter list which are used while writing this stream.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 Details
-
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
return the length of the CosStream. -
getStreamDecoded
public InputByteStream getStreamDecoded() throws PDFCosParseException, PDFIOException, PDFSecurityExceptionObtains 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 InputStream getStreamDecodedNoCopying() throws PDFCosParseException, PDFIOException, PDFSecurityExceptionReturns 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, PDFSecurityExceptionObtains 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, IOException, PDFSecurityException This method sets the filter list which are used while writing this stream.- Parameters:
filters
-- Throws:
PDFCosParseException
IOException
PDFSecurityException
PDFIOException
-
getOutputFiltersList
Returns filter list that shall be used when this stream is written. -
getInputFiltersList
public CosArray getInputFiltersList() throws PDFCosParseException, PDFIOException, PDFSecurityExceptionThis method returns the filter list with which this stream is encoded currently. -
toString
-
getStreamDataOffset
public long getStreamDataOffset()Return stream data offset or -1 if object has never been written. -
equals
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, IOExceptionReturns true if this stream is encoded else false.- Returns:
- boolean
- Throws:
PDFCosParseException
PDFIOException
PDFSecurityException
IOException
-