java.lang.Object
org.sejda.sambox.cos.COSBase
org.sejda.sambox.cos.COSDictionary
org.sejda.sambox.cos.COSStream
- All Implemented Interfaces:
Closeable,AutoCloseable,COSObjectable,Encryptable
This class represents a stream object in a PDF document.
- Author:
- Ben Litchfield
-
Field Summary
Fields inherited from class org.sejda.sambox.cos.COSDictionary
items -
Constructor Summary
ConstructorsConstructorDescriptionCOSStream(COSDictionary dictionary) COSStream(COSDictionary dictionary, org.sejda.io.SeekableSource seekableSource, long startingPosition, long length) Creates a stream with the given dictionary and where filtered data is a view of the givenSeekableSource. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(COSVisitor visitor) Visitor pattern for the COS model objectsbooleanAdds Flate decode filter to the current filters list if possiblevoidclose()Creates a new stream for which filtered byte should be written to.createFilteredStream(COSBase filters) Returns a new OutputStream for writing stream data, using and the given filters.This will create an output stream that can be written to.protected InputStreambooleanvoidencryptable(boolean encryptable) Sets if the object can be encryptedlongorg.sejda.io.SeekableSourcefinal InputStreamThis will return the filters to apply to the byte stream.longorg.sejda.io.SeekableSourcebooleanbooleanvoidindirectLength(boolean indirectLength) booleanisEmpty()voidsetEncryptor(Function<InputStream, InputStream> encryptor) Sets the function to be used to encrypt this stream.voidsetFilters(COSBase filters) set the filters to be applied to the stream.voidunDecode()offload decoded/unfiltered data leaving the COSStrem in its filtered state and reducing memory footprintMethods inherited from class org.sejda.sambox.cos.COSDictionary
addAll, asUnmodifiableDictionary, clear, containsKey, containsKey, duplicate, entrySet, getBoolean, getBoolean, getBoolean, getCOSArray, getCOSName, getCOSName, getDate, getDate, getDate, getDate, getDictionaryObject, getDictionaryObject, getDictionaryObject, getDictionaryObject, getDictionaryObject, getDictionaryObject, getEmbeddedDate, getEmbeddedDate, getEmbeddedDate, getEmbeddedDate, getEmbeddedInt, getEmbeddedInt, getEmbeddedInt, getEmbeddedInt, getEmbeddedString, getEmbeddedString, getEmbeddedString, getEmbeddedString, getFlag, getFloat, getFloat, getFloat, getFloat, getInt, getInt, getInt, getInt, getInt, getInt, getItem, getItem, getItem, getKeyForValue, getLong, getLong, getLong, getLong, getNameAsString, getNameAsString, getNameAsString, getNameAsString, getString, getString, getString, getString, getValues, keySet, merge, mergeWithoutOverwriting, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, putIfAbsent, removeItem, removeItems, setBoolean, setBoolean, setDate, setDate, setEmbeddedDate, setEmbeddedDate, setEmbeddedInt, setEmbeddedInt, setEmbeddedString, setEmbeddedString, setFlag, setFloat, setFloat, setInt, setInt, setItem, setItem, setItem, setItem, setLong, setLong, setName, setName, setString, setString, size, toStringMethods inherited from class org.sejda.sambox.cos.COSBase
getCOSObject, hasId, id, idIfAbsent
-
Constructor Details
-
COSStream
public COSStream() -
COSStream
- Parameters:
dictionary- The dictionary that is associated with this stream.
-
COSStream
public COSStream(COSDictionary dictionary, org.sejda.io.SeekableSource seekableSource, long startingPosition, long length) Creates a stream with the given dictionary and where filtered data is a view of the givenSeekableSource.- Parameters:
dictionary- The dictionary that is associated with this stream.seekableSource- the source where filtered data is read fromstartingPosition- starting position of the stream data in theSeekableSourcelength- the length of the stream data
-
-
Method Details
-
getFilteredStream
- Returns:
- the (encoded) stream with all of the filters applied.
- Throws:
IOException- when encoding/decoding causes an exception
-
doGetFilteredStream
- Throws:
IOException
-
getFilteredSource
- Returns:
- the (encoded)
SeekableSourcewith all of the filters applied. - Throws:
IOException- when encoding/decoding causes an exception
-
getFilteredLength
- Returns:
- the length of the encoded stream as long
- Throws:
IOException
-
getUnfilteredStream
- Returns:
- the (decoded) stream with all of the filters applied.
- Throws:
IOException- when encoding/decoding causes an exception
-
getUnfilteredSource
- Returns:
- the (decoded)
SeekableSourcewith all of the filters applied. - Throws:
IOException- when encoding/decoding causes an exception
-
getUnfilteredByteBuffer
- Returns:
- the (decoded) stream in the form of a read only
ByteBufferwith all of the filters applied. - Throws:
IOException- when encoding/decoding causes an exception
-
getUnfilteredLength
- Returns:
- the length of the decoded stream as long
- Throws:
IOException
-
getDecodeResult
- Returns:
- the repaired stream parameters dictionary
- Throws:
IOException- when encoding/decoding causes an exception
-
accept
Description copied from class:COSBaseVisitor pattern for the COS model objects- Overrides:
acceptin classCOSDictionary- Throws:
IOException
-
getFilters
This will return the filters to apply to the byte stream. The method will return - null if no filters are to be applied - a COSName if one filter is to be applied - a COSArray containing COSNames if multiple filters are to be applied- Returns:
- the COSBase object representing the filters
-
hasFilter
- Parameters:
filter-- Returns:
- true if the stream has the given filter in the filters list
-
setEncryptor
Sets the function to be used to encrypt this stream.- Parameters:
encryptor-
-
createFilteredStream
Creates a new stream for which filtered byte should be written to. You probably don't want this but want to use the createUnfilteredStream, which is used to write raw bytes to.- Returns:
- A stream that can be written to.
-
createFilteredStream
Returns a new OutputStream for writing stream data, using and the given filters.- Parameters:
filters- COSArray or COSName of filters to be used.- Returns:
- OutputStream for un-encoded stream data.
- Throws:
IOException- If the output stream could not be created.
-
setFilters
set the filters to be applied to the stream.- Parameters:
filters- The filters to set on this stream.- Throws:
IOException- If there is an error clearing the old filters.
-
addCompression
public boolean addCompression()Adds Flate decode filter to the current filters list if possible -
encryptable
public boolean encryptable()- Specified by:
encryptablein interfaceEncryptable- Returns:
- true if the can be encrypted
-
encryptable
public void encryptable(boolean encryptable) Description copied from interface:EncryptableSets if the object can be encrypted- Specified by:
encryptablein interfaceEncryptable
-
createUnfilteredStream
This will create an output stream that can be written to.- Returns:
- An output stream which raw data bytes should be written to.
- Throws:
IOException- If there is an error creating the stream.
-
isEmpty
- Throws:
IOException
-
asTextString
- Returns:
- the contents of the stream as a text string. Text string as defined in Chap 7.9 of PDF 32000-1:2008.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
unDecode
public void unDecode()offload decoded/unfiltered data leaving the COSStrem in its filtered state and reducing memory footprint -
indirectLength
public boolean indirectLength()- Returns:
- true if the writer should write this stream length as indirect
-
indirectLength
public void indirectLength(boolean indirectLength) - Parameters:
indirectLength- if the writer should write this stream length as indirect
-