Top Description Fields Constructors Methods
org.apache.pdfbox.cos

public Class COSStream

extends COSDictionary
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .FilterOutputStream, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .List, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.filter.DecodeOptions, .Filter, .FilterFactory, org.apache.pdfbox.io.IOUtils, .RandomAccess, .RandomAccessInputStream, .RandomAccessOutputStream, .RandomAccessRead, .RandomAccessReadBuffer, .RandomAccessReadView, .RandomAccessStreamCache

This class represents a stream object in a PDF document.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private static final Log
private RandomAccess
private RandomAccessReadView
private RandomAccessStreamCache
Inherited from org.apache.pdfbox.cos.COSDictionary:
items

Constructor Summary

AccessConstructor and Description
public
COSStream()

Creates a new stream with an empty dictionary.

public
COSStream(RandomAccessStreamCache
Stream cache for writing stream data.
streamCache
)

Creates a new stream with an empty dictionary.

public
COSStream(RandomAccessStreamCache
Stream cache for writing stream data.
streamCache
,
RandomAccessReadView
source for the data to be read
randomAccessReadView
)

Creates a new stream with an empty dictionary.

Method Summary

Modifier and TypeMethod and Description
public void
accept(ICOSVisitor
The object to notify when visiting this object.
visitor
)

Overrides org.apache.pdfbox.cos.COSDictionary.accept.

visitor pattern double dispatch method.

private void
checkClosed()

Throws if the random access backing store has been closed.

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public COSInputStream

Returns:

InputStream containing decoded stream data.
createInputStream
()

Returns a new InputStream which reads the decoded stream data.

public COSInputStream
public OutputStream

Returns:

OutputStream for un-encoded stream data.
createOutputStream
()

Returns a new OutputStream for writing stream data, using the current filters.

public OutputStream

Returns:

OutputStream for un-encoded stream data.
createOutputStream
(COSBase
COSArray or COSName of filters to be used.
filters
)

Returns a new OutputStream for writing stream data, using and the given filters.

public InputStream

Returns:

InputStream containing raw, encoded PDF stream data.
createRawInputStream
()

Returns a new InputStream which reads the encoded PDF stream data.

public OutputStream

Returns:

OutputStream for raw PDF stream data.
createRawOutputStream
()

Returns a new OutputStream for writing encoded PDF data.

public RandomAccessRead

Returns:

RandomAccessRead containing decoded stream data.
createView
()

Returns a new RandomAccessRead which reads the decoded stream data.

private List<Filter>
getFilterList()

Returns the list of filters.

public COSBase

Returns:

the COSBase object representing the filters
getFilters
()

This will return the filters to apply to the byte stream.

public long

Returns:

length in bytes
getLength
()

Returns the length of the encoded stream.

private RandomAccessStreamCache
public boolean

Returns:

true if the stream contains any data
hasData
()

Indicates whether the stream contains any data or not.

public String

Returns:

the PDF string representation of the stream content
toTextString
()

Returns the contents of the stream as a PDF "text string".

Inherited from org.apache.pdfbox.cos.COSDictionary:
addAllasUnmodifiableDictionaryclearcontainsKeycontainsKeycontainsValueentrySetforEachgetBooleangetBooleangetBooleangetCOSArraygetCOSDictionarygetCOSDictionarygetCOSNamegetCOSNamegetCOSObjectgetCOSStreamgetDategetDategetDategetDategetDictionaryObjectgetDictionaryObjectgetDictionaryObjectgetEmbeddedDategetEmbeddedDategetEmbeddedIntgetEmbeddedIntgetEmbeddedStringgetEmbeddedStringgetFlaggetFloatgetFloatgetFloatgetFloatgetIndirectObjectKeysgetIndirectObjectKeysgetIntgetIntgetIntgetIntgetIntgetIntgetItemgetItemgetItemgetKeyForValuegetLonggetLonggetLonggetLonggetNameAsStringgetNameAsStringgetNameAsStringgetNameAsStringgetObjectFromPathgetStringgetStringgetStringgetStringgetUpdateStategetValueskeySetremoveItemsetBooleansetBooleansetDatesetDatesetEmbeddedDatesetEmbeddedIntsetEmbeddedStringsetFlagsetFloatsetFloatsetIntsetIntsetItemsetItemsetItemsetItemsetLongsetLongsetNamesetNamesetStringsetStringsizetoString

Field Detail

closeStreamCacheback to summary
private boolean closeStreamCache
isWritingback to summary
private boolean isWriting
LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.cos.COSDictionary.LOG.

randomAccessback to summary
private RandomAccess randomAccess
randomAccessReadViewback to summary
private RandomAccessReadView randomAccessReadView
streamCacheback to summary
private RandomAccessStreamCache streamCache

Constructor Detail

COSStreamback to summary
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.

COSStreamback to summary
public COSStream(RandomAccessStreamCache streamCache)

Creates a new stream with an empty dictionary. Data is stored in the given scratch file.

Parameters
streamCache:RandomAccessStreamCache

Stream cache for writing stream data.

COSStreamback to summary
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:RandomAccessStreamCache

Stream cache for writing stream data.

randomAccessReadView:RandomAccessReadView

source for the data to be read

Exceptions
IOException:
if the length of the random access view isn't available

Method Detail

acceptback to summary
public void accept(ICOSVisitor visitor) throws IOException

Overrides org.apache.pdfbox.cos.COSDictionary.accept.

Doc from org.apache.pdfbox.cos.COSDictionary.accept.

visitor pattern double dispatch method.

Parameters
visitor:ICOSVisitor

The object to notify when visiting this object.

Annotations
@Override
Exceptions
IOException:
If there is an error visiting this object.
checkClosedback to summary
private void checkClosed() throws IOException

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.

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException. Called by PDFBox when the PDDocument is closed, this closes the stream and removes the data. You will usually not need this.

Annotations
@Override
Exceptions
IOException:
if something went wrong when closing the stream
createInputStreamback to summary
public COSInputStream createInputStream() throws IOException

Returns a new InputStream which reads the decoded stream data.

Returns:COSInputStream

InputStream containing decoded stream data.

Exceptions
IOException:
If the stream could not be read.
createInputStreamback to summary
public COSInputStream createInputStream(DecodeOptions options) throws IOException
createOutputStreamback to summary
public OutputStream createOutputStream() throws IOException

Returns a new OutputStream for writing stream data, using the current filters.

Returns:OutputStream

OutputStream for un-encoded stream data.

Exceptions
IOException:
If the output stream could not be created.
createOutputStreamback to summary
public OutputStream createOutputStream(COSBase filters) throws IOException

Returns a new OutputStream for writing stream data, using and the given filters.

Parameters
filters:COSBase

COSArray or COSName of filters to be used.

Returns:OutputStream

OutputStream for un-encoded stream data.

Exceptions
IOException:
If the output stream could not be created.
createRawInputStreamback to summary
public InputStream createRawInputStream() throws IOException

Returns a new InputStream which reads the encoded PDF stream data. Experts only!

Returns:InputStream

InputStream containing raw, encoded PDF stream data.

Exceptions
IOException:
If the stream could not be read.
createRawOutputStreamback to summary
public OutputStream createRawOutputStream() throws IOException

Returns a new OutputStream for writing encoded PDF data. Experts only!

Returns:OutputStream

OutputStream for raw PDF stream data.

Exceptions
IOException:
If the output stream could not be created.
createViewback to summary
public RandomAccessRead createView() throws IOException

Returns a new RandomAccessRead which reads the decoded stream data.

Returns:RandomAccessRead

RandomAccessRead containing decoded stream data.

Exceptions
IOException:
If the stream could not be read.
getFilterListback to summary
private List<Filter> getFilterList() throws IOException

Returns the list of filters.

getFiltersback to summary
public COSBase 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:COSBase

the COSBase object representing the filters

getLengthback to summary
public long getLength()

Returns the length of the encoded stream.

Returns:long

length in bytes

getStreamCacheback to summary
private RandomAccessStreamCache getStreamCache() throws IOException
hasDataback to summary
public boolean hasData()

Indicates whether the stream contains any data or not.

Returns:boolean

true if the stream contains any data

toTextStringback to summary
public String toTextString()

Returns the contents of the stream as a PDF "text string".

Returns:String

the PDF string representation of the stream content