Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.common

public Class PDStream

extends Object
implements COSObjectable
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.common.COSObjectable
Known Direct Subclasses
org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile, org.apache.pdfbox.pdmodel.common.PDMetadata, org.apache.pdfbox.pdmodel.common.PDObjectStream
Imports
java.io.IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collections, .List, .Map, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSDocument, .COSInputStream, .COSName, .COSNull, .COSStream, org.apache.pdfbox.filter.DecodeOptions, .Filter, .FilterFactory, org.apache.pdfbox.io.IOUtils, .RandomAccessInputStream, .RandomAccessRead, org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification

A PDStream represents a stream in a PDF document. Streams are tied to a single PDF document.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private static final Log
private final COSStream

Constructor Summary

AccessConstructor and Description
public
PDStream(PDDocument
The document that the stream will be part of.
document
)

Creates a new empty PDStream object.

public
PDStream(COSDocument
The document that the stream will be part of.
document
)

Creates a new empty PDStream object.

public
PDStream(COSStream
The stream parameter.
str
)

Creates a PDStream which wraps the given COSStream.

public
PDStream(PDDocument
The document that will hold the stream.
doc
,
InputStream
The stream parameter.
input
)

Constructor.

public
PDStream(PDDocument
The document that will hold the stream.
doc
,
InputStream
The stream parameter.
input
,
COSName
Filter to apply to the stream.
filter
)

Constructor.

public
PDStream(PDDocument
The document that will hold the stream.
doc
,
InputStream
The stream parameter.
input
,
COSArray
Filters to apply to the stream.
filters
)

Constructor.

private
PDStream(PDDocument doc, InputStream input, COSBase filters)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public COSInputStream

Returns:

An input stream that can be read from.
createInputStream
()

This will get a stream that can be read from.

public COSInputStream
public InputStream

Returns:

A stream with decoded data.
createInputStream
(List<String>
A list of filters to stop decoding at.
stopFilters
)

This will get a stream with some filters applied but not others.

public OutputStream

Returns:

An output stream to write data to.
createOutputStream
()

This will get a stream that can be written to.

public OutputStream

Returns:

An output stream to write data to.
createOutputStream
(COSName
the filter to be used.
filter
)

This will get a stream that can be written to, with the given filter.

public COSStream

Returns:

The cos object that matches this Java object.
getCOSObject
()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Get the cos stream associated with this object.

public int

Returns:

the decoded stream length
getDecodedStreamLength
()

Get the decoded stream length.

public List<Object>

Returns:

The list of decode parameters.
getDecodeParms
()

Get the list of decode parameters.

public PDFileSpecification

Returns:

The file specification.
getFile
()

This will get the file specification for this stream.

public List<Object>

Returns:

The list of decode parameters.
getFileDecodeParams
()

Get the list of decode parameters.

public List<String>

Returns:

A list of all encoding filters to apply to this stream.
getFileFilters
()

This will get the list of filters that are associated with this stream.

public List<COSName>

Returns:

A (possibly empty) list of all encoding filters to apply to this stream, never null.
getFilters
()

This will get the list of filters that are associated with this stream.

public int

Returns:

The length of the filtered stream.
getLength
()

This will get the length of the filtered/compressed stream.

public PDMetadata

Returns:

The metadata for this object.
getMetadata
()

Get the metadata that is part of the document catalog.

private List<Object>
public void
setDecodedStreamLength(int
the decoded stream length
decodedStreamLength
)

Set the decoded stream length.

public void
setDecodeParms(List<?>
The list of decode parameters.
decodeParams
)

This will set the list of decode parameters.

public void
setFile(PDFileSpecification
The file specification.
f
)

Set the file specification.

public void
setFileDecodeParams(List<?>
The list of decode params.
decodeParams
)

This will set the list of decode params.

public void
setFileFilters(List<String>
The filters that are part of this stream.
filters
)

This will set the filters that are part of this stream.

public void
setFilters(List<COSName>
The filters that are part of this stream.
filters
)

This will set the filters that are part of this stream.

public void
setMetadata(PDMetadata
The meta data for this object.
meta
)

Set the metadata for this object.

public byte[]

Returns:

The byte array of the filteredStream.
toByteArray
()

This will copy the stream into a byte array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Log LOG
streamback to summary
private final COSStream stream

Constructor Detail

PDStreamback to summary
public PDStream(PDDocument document)

Creates a new empty PDStream object.

Parameters
document:PDDocument

The document that the stream will be part of.

PDStreamback to summary
public PDStream(COSDocument document)

Creates a new empty PDStream object.

Parameters
document:COSDocument

The document that the stream will be part of.

PDStreamback to summary
public PDStream(COSStream str)

Creates a PDStream which wraps the given COSStream.

Parameters
str:COSStream

The stream parameter.

PDStreamback to summary
public PDStream(PDDocument doc, InputStream input) throws IOException

Constructor. Reads all data from the input stream and embeds it into the document. This method closes the InputStream.

Parameters
doc:PDDocument

The document that will hold the stream.

input:InputStream

The stream parameter.

Exceptions
IOException:
If there is an error creating the stream in the document.
PDStreamback to summary
public PDStream(PDDocument doc, InputStream input, COSName filter) throws IOException

Constructor. Reads all data from the input stream and embeds it into the document with the given filter applied. This method closes the InputStream.

Parameters
doc:PDDocument

The document that will hold the stream.

input:InputStream

The stream parameter.

filter:COSName

Filter to apply to the stream.

Exceptions
IOException:
If there is an error creating the stream in the document.
PDStreamback to summary
public PDStream(PDDocument doc, InputStream input, COSArray filters) throws IOException

Constructor. Reads all data from the input stream and embeds it into the document with the given filters applied. This method closes the InputStream.

Parameters
doc:PDDocument

The document that will hold the stream.

input:InputStream

The stream parameter.

filters:COSArray

Filters to apply to the stream.

Exceptions
IOException:
If there is an error creating the stream in the document.
PDStreamback to summary
private PDStream(PDDocument doc, InputStream input, COSBase filters) throws IOException

Constructor. Reads all data from the input stream and embeds it into the document with the given filters applied, if any. This method closes the InputStream.

Method Detail

createInputStreamback to summary
public COSInputStream createInputStream() throws IOException

This will get a stream that can be read from.

Returns:COSInputStream

An input stream that can be read from.

Exceptions
IOException:
If an IO error occurs during reading.
createInputStreamback to summary
public COSInputStream createInputStream(DecodeOptions options) throws IOException
createInputStreamback to summary
public InputStream createInputStream(List<String> stopFilters) throws IOException

This will get a stream with some filters applied but not others. This is useful when doing images, ie filters = [flate,dct], we want to remove flate but leave dct

Parameters
stopFilters:List<String>

A list of filters to stop decoding at.

Returns:InputStream

A stream with decoded data.

Exceptions
IOException:
If there is an error processing the stream.
createOutputStreamback to summary
public OutputStream createOutputStream() throws IOException

This will get a stream that can be written to.

Returns:OutputStream

An output stream to write data to.

Exceptions
IOException:
If an IO error occurs during writing.
createOutputStreamback to summary
public OutputStream createOutputStream(COSName filter) throws IOException

This will get a stream that can be written to, with the given filter.

Parameters
filter:COSName

the filter to be used.

Returns:OutputStream

An output stream to write data to.

Exceptions
IOException:
If an IO error occurs during writing.
getCOSObjectback to summary
public COSStream getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Get the cos stream associated with this object.

Returns:COSStream

The cos object that matches this Java object.

Annotations
@Override
getDecodedStreamLengthback to summary
public int getDecodedStreamLength()

Get the decoded stream length.

Returns:int

the decoded stream length

getDecodeParmsback to summary
public List<Object> getDecodeParms() throws IOException

Get the list of decode parameters. Each entry in the list will refer to an entry in the filters list.

Returns:List<Object>

The list of decode parameters.

Exceptions
IOException:
if there is an error retrieving the parameters.
getFileback to summary
public PDFileSpecification getFile() throws IOException

This will get the file specification for this stream. This is only required for external files.

Returns:PDFileSpecification

The file specification.

Exceptions
IOException:
If there is an error creating the file spec.
getFileDecodeParamsback to summary
public List<Object> getFileDecodeParams() throws IOException

Get the list of decode parameters. Each entry in the list will refer to an entry in the filters list.

Returns:List<Object>

The list of decode parameters.

Exceptions
IOException:
if there is an error retrieving the parameters.
getFileFiltersback to summary
public List<String> getFileFilters()

This will get the list of filters that are associated with this stream. The list is empty if there are none.

Returns:List<String>

A list of all encoding filters to apply to this stream.

getFiltersback to summary
public List<COSName> getFilters()

This will get the list of filters that are associated with this stream.

Returns:List<COSName>

A (possibly empty) list of all encoding filters to apply to this stream, never null.

getLengthback to summary
public int getLength()

This will get the length of the filtered/compressed stream. This is readonly in the PD Model and will be managed by this class.

Returns:int

The length of the filtered stream.

getMetadataback to summary
public PDMetadata getMetadata()

Get the metadata that is part of the document catalog. This will return null if there is no meta data for this object.

Returns:PDMetadata

The metadata for this object.

Exceptions
IllegalStateException:
if the value of the metadata entry is different from a stream or null
internalGetDecodeParamsback to summary
private List<Object> internalGetDecodeParams(COSName name1, COSName name2) throws IOException
setDecodedStreamLengthback to summary
public void setDecodedStreamLength(int decodedStreamLength)

Set the decoded stream length.

Parameters
decodedStreamLength:int

the decoded stream length

setDecodeParmsback to summary
public void setDecodeParms(List<?> decodeParams)

This will set the list of decode parameters.

Parameters
decodeParams:List<?>

The list of decode parameters.

setFileback to summary
public void setFile(PDFileSpecification f)

Set the file specification.

Parameters
f:PDFileSpecification

The file specification.

setFileDecodeParamsback to summary
public void setFileDecodeParams(List<?> decodeParams)

This will set the list of decode params.

Parameters
decodeParams:List<?>

The list of decode params.

setFileFiltersback to summary
public void setFileFilters(List<String> filters)

This will set the filters that are part of this stream.

Parameters
filters:List<String>

The filters that are part of this stream.

setFiltersback to summary
public void setFilters(List<COSName> filters)

This will set the filters that are part of this stream.

Parameters
filters:List<COSName>

The filters that are part of this stream.

setMetadataback to summary
public void setMetadata(PDMetadata meta)

Set the metadata for this object. This can be null.

Parameters
meta:PDMetadata

The meta data for this object.

toByteArrayback to summary
public byte[] toByteArray() throws IOException

This will copy the stream into a byte array.

Returns:byte[]

The byte array of the filteredStream.

Exceptions
IOException:
if an I/O error occurs.