Package org.apache.pdfbox.cos
Class COSStream
java.lang.Object
org.apache.pdfbox.cos.COSBase
org.apache.pdfbox.cos.COSDictionary
org.apache.pdfbox.cos.COSStream
- All Implemented Interfaces:
Closeable,AutoCloseable,COSUpdateInfo,COSObjectable
This class represents a stream object in a PDF document.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate static final org.apache.commons.logging.Logprivate RandomAccessprivate RandomAccessReadViewprivate RandomAccessStreamCacheFields inherited from class org.apache.pdfbox.cos.COSDictionary
items -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new stream with an empty dictionary.COSStream(RandomAccessStreamCache streamCache) Creates a new stream with an empty dictionary.COSStream(RandomAccessStreamCache streamCache, RandomAccessReadView randomAccessReadView) Creates a new stream with an empty dictionary. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(ICOSVisitor visitor) visitor pattern double dispatch method.private voidThrows if the random access backing store has been closed.voidclose()Called by PDFBox when the PDDocument is closed, this closes the stream and removes the data.Returns a new InputStream which reads the decoded stream data.createInputStream(DecodeOptions options) Returns a new OutputStream for writing stream data, using the current filters.createOutputStream(COSBase filters) Returns a new OutputStream for writing stream data, using and the given filters.Returns a new InputStream which reads the encoded PDF stream data.Returns a new OutputStream for writing encoded PDF data.Returns a new RandomAccessRead which reads the decoded stream data.Returns the list of filters.This will return the filters to apply to the byte stream.longReturns the length of the encoded stream.private RandomAccessStreamCachebooleanhasData()Indicates whether the stream contains any data or not.Returns the contents of the stream as a PDF "text string".Methods inherited from class org.apache.pdfbox.cos.COSDictionary
addAll, asUnmodifiableDictionary, clear, containsKey, containsKey, containsValue, entrySet, forEach, getBoolean, getBoolean, getBoolean, getCOSArray, getCOSDictionary, getCOSDictionary, getCOSName, getCOSName, getCOSObject, getCOSStream, getDate, getDate, getDate, getDate, getDictionaryObject, getDictionaryObject, getDictionaryObject, getEmbeddedDate, getEmbeddedDate, getEmbeddedInt, getEmbeddedInt, getEmbeddedString, getEmbeddedString, getFlag, getFloat, getFloat, getFloat, getFloat, getIndirectObjectKeys, getIndirectObjectKeys, getInt, getInt, getInt, getInt, getInt, getInt, getItem, getItem, getItem, getKeyForValue, getLong, getLong, getLong, getLong, getNameAsString, getNameAsString, getNameAsString, getNameAsString, getObjectFromPath, getString, getString, getString, getString, getUpdateState, getValues, keySet, removeItem, setBoolean, setBoolean, setDate, setDate, setEmbeddedDate, setEmbeddedInt, setEmbeddedString, setFlag, setFloat, setFloat, setInt, setInt, setItem, setItem, setItem, setItem, setLong, setLong, setName, setName, setString, setString, size, toStringMethods inherited from class org.apache.pdfbox.cos.COSBase
getCOSObject, getKey, isDirect, setDirect, setKeyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.pdfbox.pdmodel.common.COSObjectable
getCOSObjectMethods inherited from interface org.apache.pdfbox.cos.COSUpdateInfo
isNeedToBeUpdated, setNeedToBeUpdated, toIncrement
-
Field Details
-
randomAccess
-
streamCache
-
closeStreamCache
private boolean closeStreamCache -
isWriting
private boolean isWriting -
randomAccessReadView
-
LOG
private static final org.apache.commons.logging.Log LOG
-
-
Constructor Details
-
COSStream
public COSStream()Creates a new stream with an empty dictionary.Try to avoid using this constructor because it creates a new scratch file in memory. Instead, use
document.getDocument().createCOSStream()which will use the existing scratch file (in memory or in temp file) of the document. -
COSStream
Creates a new stream with an empty dictionary. Data is stored in the given scratch file.- Parameters:
streamCache- Stream cache for writing stream data.
-
COSStream
public COSStream(RandomAccessStreamCache streamCache, RandomAccessReadView randomAccessReadView) throws IOException Creates a new stream with an empty dictionary. Data is read from the given random accessview. Written data is stored in the given scratch file.- Parameters:
streamCache- Stream cache for writing stream data.randomAccessReadView- source for the data to be read- Throws:
IOException- if the length of the random access view isn't available
-
-
Method Details
-
checkClosed
Throws if the random access backing store has been closed. Helpful for catching cases where a user tries to use a COSStream which has outlived its COSDocument.- Throws:
IOException
-
getStreamCache
- Throws:
IOException
-
createRawInputStream
Returns a new InputStream which reads the encoded PDF stream data. Experts only!- Returns:
- InputStream containing raw, encoded PDF stream data.
- Throws:
IOException- If the stream could not be read.
-
createInputStream
Returns a new InputStream which reads the decoded stream data.- Returns:
- InputStream containing decoded stream data.
- Throws:
IOException- If the stream could not be read.
-
createInputStream
- Throws:
IOException
-
createView
Returns a new RandomAccessRead which reads the decoded stream data.- Returns:
- RandomAccessRead containing decoded stream data.
- Throws:
IOException- If the stream could not be read.
-
createOutputStream
Returns a new OutputStream for writing stream data, using the current filters.- Returns:
- OutputStream for un-encoded stream data.
- Throws:
IOException- If the output stream could not be created.
-
createOutputStream
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.
-
createRawOutputStream
Returns a new OutputStream for writing encoded PDF data. Experts only!- Returns:
- OutputStream for raw PDF stream data.
- Throws:
IOException- If the output stream could not be created.
-
getFilterList
Returns the list of filters.- Throws:
IOException
-
getLength
public long getLength()Returns the length of the encoded stream.- Returns:
- length in bytes
-
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
-
toTextString
Returns the contents of the stream as a PDF "text string".- Returns:
- the PDF string representation of the stream content
-
accept
Description copied from class:COSDictionaryvisitor pattern double dispatch method.- Overrides:
acceptin classCOSDictionary- Parameters:
visitor- The object to notify when visiting this object.- Throws:
IOException- If there is an error visiting this object.
-
close
Called by PDFBox when the PDDocument is closed, this closes the stream and removes the data. You will usually not need this.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if something went wrong when closing the stream
-
hasData
public boolean hasData()Indicates whether the stream contains any data or not.- Returns:
- true if the stream contains any data
-