Package org.apache.pdfbox.pdmodel.common
Class PDStream
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.common.PDStream
-
- All Implemented Interfaces:
COSObjectable
- Direct Known Subclasses:
PDEmbeddedFile
,PDMetadata
,PDObjectStream
public class PDStream extends java.lang.Object implements COSObjectable
A PDStream represents a stream in a PDF document. Streams are tied to a single PDF document.
-
-
Constructor Summary
Constructors Modifier Constructor Description PDStream(COSDocument document)
Creates a new empty PDStream object.PDStream(COSStream str)
Creates a PDStream which wraps the given COSStream.PDStream(PDDocument document)
Creates a new empty PDStream object.PDStream(PDDocument doc, java.io.InputStream input)
Constructor.PDStream(PDDocument doc, java.io.InputStream input, COSArray filters)
Constructor.private
PDStream(PDDocument doc, java.io.InputStream input, COSBase filters)
Constructor.PDStream(PDDocument doc, java.io.InputStream input, COSName filter)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCompression()
Deprecated.This method is inefficient.COSInputStream
createInputStream()
This will get a stream that can be read from.java.io.InputStream
createInputStream(java.util.List<java.lang.String> stopFilters)
This will get a stream with some filters applied but not others.COSInputStream
createInputStream(DecodeOptions options)
java.io.OutputStream
createOutputStream()
This will get a stream that can be written to.java.io.OutputStream
createOutputStream(COSName filter)
This will get a stream that can be written to, with the given filter.COSStream
getCOSObject()
Get the cos stream associated with this object.int
getDecodedStreamLength()
Get the decoded stream length.java.util.List<java.lang.Object>
getDecodeParms()
Get the list of decode parameters.PDFileSpecification
getFile()
This will get the file specification for this stream.java.util.List<java.lang.Object>
getFileDecodeParams()
Get the list of decode parameters.java.util.List<java.lang.String>
getFileFilters()
This will get the list of filters that are associated with this stream.java.util.List<COSName>
getFilters()
This will get the list of filters that are associated with this stream.int
getLength()
This will get the length of the filtered/compressed stream.PDMetadata
getMetadata()
Get the metadata that is part of the document catalog.COSStream
getStream()
Deprecated.usegetCOSObject()
void
setDecodedStreamLength(int decodedStreamLength)
Set the decoded stream length.void
setDecodeParms(java.util.List<?> decodeParams)
This will set the list of decode parameterss.void
setFile(PDFileSpecification f)
Set the file specification.void
setFileDecodeParams(java.util.List<?> decodeParams)
This will set the list of decode params.void
setFileFilters(java.util.List<java.lang.String> filters)
This will set the filters that are part of this stream.void
setFilters(java.util.List<COSName> filters)
This will set the filters that are part of this stream.void
setMetadata(PDMetadata meta)
Set the metadata for this object.byte[]
toByteArray()
This will copy the stream into a byte array.
-
-
-
Field Detail
-
stream
private final COSStream stream
-
-
Constructor Detail
-
PDStream
public PDStream(PDDocument document)
Creates a new empty PDStream object.- Parameters:
document
- The document that the stream will be part of.
-
PDStream
public PDStream(COSDocument document)
Creates a new empty PDStream object.- Parameters:
document
- The document that the stream will be part of.
-
PDStream
public PDStream(COSStream str)
Creates a PDStream which wraps the given COSStream.- Parameters:
str
- The stream parameter.
-
PDStream
public PDStream(PDDocument doc, java.io.InputStream input) throws java.io.IOException
Constructor. Reads all data from the input stream and embeds it into the document. This method closes the InputStream.- Parameters:
doc
- The document that will hold the stream.input
- The stream parameter.- Throws:
java.io.IOException
- If there is an error creating the stream in the document.
-
PDStream
public PDStream(PDDocument doc, java.io.InputStream input, COSName filter) throws java.io.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
- The document that will hold the stream.input
- The stream parameter.filter
- Filter to apply to the stream.- Throws:
java.io.IOException
- If there is an error creating the stream in the document.
-
PDStream
public PDStream(PDDocument doc, java.io.InputStream input, COSArray filters) throws java.io.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
- The document that will hold the stream.input
- The stream parameter.filters
- Filters to apply to the stream.- Throws:
java.io.IOException
- If there is an error creating the stream in the document.
-
PDStream
private PDStream(PDDocument doc, java.io.InputStream input, COSBase filters) throws java.io.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.- Throws:
java.io.IOException
-
-
Method Detail
-
addCompression
@Deprecated public void addCompression()
Deprecated.This method is inefficient. To copying an existing InputStream, usePDStream(PDDocument, InputStream, COSName)
instead, with COSName.FLATE_DECODE as the final argument. Otherwise, to write new compressed data, usecreateOutputStream(COSName)
, with COSName.FLATE_DECODE as the argument.If there are not compression filters on the current stream then this will add a compression filter, flate compression for example.
-
getCOSObject
public COSStream getCOSObject()
Get the cos stream associated with this object.- Specified by:
getCOSObject
in interfaceCOSObjectable
- Returns:
- The cos object that matches this Java object.
-
createOutputStream
public java.io.OutputStream createOutputStream() throws java.io.IOException
This will get a stream that can be written to.- Returns:
- An output stream to write data to.
- Throws:
java.io.IOException
- If an IO error occurs during writing.
-
createOutputStream
public java.io.OutputStream createOutputStream(COSName filter) throws java.io.IOException
This will get a stream that can be written to, with the given filter.- Parameters:
filter
- the filter to be used.- Returns:
- An output stream to write data to.
- Throws:
java.io.IOException
- If an IO error occurs during writing.
-
createInputStream
public COSInputStream createInputStream() throws java.io.IOException
This will get a stream that can be read from.- Returns:
- An input stream that can be read from.
- Throws:
java.io.IOException
- If an IO error occurs during reading.
-
createInputStream
public COSInputStream createInputStream(DecodeOptions options) throws java.io.IOException
- Throws:
java.io.IOException
-
createInputStream
public java.io.InputStream createInputStream(java.util.List<java.lang.String> stopFilters) throws java.io.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
- A list of filters to stop decoding at.- Returns:
- A stream with decoded data.
- Throws:
java.io.IOException
- If there is an error processing the stream.
-
getStream
@Deprecated public COSStream getStream()
Deprecated.usegetCOSObject()
Get the cos stream associated with this object.- Returns:
- The cos object that matches this Java object.
-
getLength
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:
- The length of the filtered stream.
-
getFilters
public java.util.List<COSName> getFilters()
This will get the list of filters that are associated with this stream. Or null if there are none.- Returns:
- A list of all encoding filters to apply to this stream.
-
setFilters
public void setFilters(java.util.List<COSName> filters)
This will set the filters that are part of this stream.- Parameters:
filters
- The filters that are part of this stream.
-
getDecodeParms
public java.util.List<java.lang.Object> getDecodeParms() throws java.io.IOException
Get the list of decode parameters. Each entry in the list will refer to an entry in the filters list.- Returns:
- The list of decode parameters.
- Throws:
java.io.IOException
- if there is an error retrieving the parameters.
-
setDecodeParms
public void setDecodeParms(java.util.List<?> decodeParams)
This will set the list of decode parameterss.- Parameters:
decodeParams
- The list of decode parameterss.
-
getFile
public PDFileSpecification getFile() throws java.io.IOException
This will get the file specification for this stream. This is only required for external files.- Returns:
- The file specification.
- Throws:
java.io.IOException
- If there is an error creating the file spec.
-
setFile
public void setFile(PDFileSpecification f)
Set the file specification.- Parameters:
f
- The file specification.
-
getFileFilters
public java.util.List<java.lang.String> getFileFilters()
This will get the list of filters that are associated with this stream. Or null if there are none.- Returns:
- A list of all encoding filters to apply to this stream.
-
setFileFilters
public void setFileFilters(java.util.List<java.lang.String> filters)
This will set the filters that are part of this stream.- Parameters:
filters
- The filters that are part of this stream.
-
getFileDecodeParams
public java.util.List<java.lang.Object> getFileDecodeParams() throws java.io.IOException
Get the list of decode parameters. Each entry in the list will refer to an entry in the filters list.- Returns:
- The list of decode parameters.
- Throws:
java.io.IOException
- if there is an error retrieving the parameters.
-
setFileDecodeParams
public void setFileDecodeParams(java.util.List<?> decodeParams)
This will set the list of decode params.- Parameters:
decodeParams
- The list of decode params.
-
toByteArray
public byte[] toByteArray() throws java.io.IOException
This will copy the stream into a byte array.- Returns:
- The byte array of the filteredStream.
- Throws:
java.io.IOException
- if an I/O error occurs.
-
getMetadata
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:
- The metadata for this object.
- Throws:
java.lang.IllegalStateException
- if the value of the metadata entry is different from a stream or null
-
setMetadata
public void setMetadata(PDMetadata meta)
Set the metadata for this object. This can be null.- Parameters:
meta
- The meta data for this object.
-
getDecodedStreamLength
public int getDecodedStreamLength()
Get the decoded stream length.- Returns:
- the decoded stream length
-
setDecodedStreamLength
public void setDecodedStreamLength(int decodedStreamLength)
Set the decoded stream length.- Parameters:
decodedStreamLength
- the decoded stream length
-
-