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> booleancopyStream(T destStm, boolean encoded)Copy the stream data into the given OutputStream.booleanequals(CosObject value)This method follows three criteria to check: 1) both should be instance of CosStream.CosArraygetInputFiltersList()This method returns the filter list with which this stream is encoded currently.longgetLength()return the length of the CosStream.CosArraygetOutputFiltersList()Returns filter list that shall be used when this stream is written.longgetStreamDataOffset()Return stream data offset or -1 if object has never been written.InputByteStreamgetStreamDecoded()Obtains a slice of the underlying InputByteStream.java.io.InputStreamgetStreamDecodedNoCopying()Returns underlying stream asInputStream.InputByteStreamgetStreamEncoded()Obtains a slice of the underlying InputByteStream.intgetType()return the type of this CosObjectbooleanisEncoded()Returns true if this stream is encoded else false.voidnewDataDecoded(InputByteStream byteStream)Set new unencrypted and decoded data for this CosStream.voidnewDataEncoded(InputByteStream byteStream)Set new unencrypted but already encoded data for this CosStream.CosObjectput(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 bodyCosObjectremove(ASName key)Removes the key mapping from the dictionary.voidsetOutputFiltersList(CosArray filters)This method sets the filter list which are used while writing this stream.java.lang.StringtoString()-
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:
putin classCosDictionary- Parameters:
key- Key for the entrycosObject- CosObject value for the entry- Returns:
- CosObject value added to the dictionary.
- Throws:
PDFCosParseExceptionPDFIOExceptionPDFSecurityException
-
remove
public CosObject remove(ASName key) throws PDFCosParseException, PDFIOException, PDFSecurityException
Description copied from class:CosDictionaryRemoves the key mapping from the dictionary.- Overrides:
removein 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:
PDFCosParseExceptionPDFIOExceptionPDFSecurityException
-
getType
public int getType()
return the type of this CosObject- Overrides:
getTypein classCosDictionary- Returns:
- one of the t_Mumble static final int values defined above
-
getLength
public long getLength() throws PDFCosParseException, PDFIOException, PDFSecurityExceptionreturn 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:
PDFCosParseExceptionPDFIOExceptionPDFSecurityException
-
getStreamDecodedNoCopying
public java.io.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:
PDFCosParseExceptionPDFIOExceptionPDFSecurityException
-
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:
PDFCosParseExceptionPDFIOExceptionPDFSecurityException
-
copyStream
public <T> boolean copyStream(T destStm, boolean encoded) throws PDFCosParseException, PDFIOException, PDFSecurityExceptionCopy 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:
PDFCosParseExceptionPDFIOExceptionPDFSecurityException
-
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:
PDFSecurityExceptionPDFIOExceptionPDFCosParseException
-
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:
PDFSecurityExceptionPDFIOExceptionPDFCosParseException
-
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:
PDFCosParseExceptionjava.io.IOExceptionPDFSecurityExceptionPDFIOException
-
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:
equalsin classCosDictionary- Parameters:
value-- Returns:
- boolean
-
isEncoded
public boolean isEncoded() throws PDFCosParseException, PDFIOException, PDFSecurityException, java.io.IOExceptionReturns true if this stream is encoded else false.- Returns:
- boolean
- Throws:
PDFCosParseExceptionPDFIOExceptionPDFSecurityExceptionjava.io.IOException
-
-