Package org.apache.pdfbox.pdmodel.common
Class PDMemoryStream
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.common.PDStream
-
- org.apache.pdfbox.pdmodel.common.PDMemoryStream
-
- All Implemented Interfaces:
COSObjectable
public class PDMemoryStream extends PDStream
A PDStream represents a stream in a PDF document. Streams are tied to a single PDF document.- Version:
- $Revision: 1.2 $
- Author:
- Ben Litchfield
-
-
Constructor Summary
Constructors Constructor Description PDMemoryStream(byte[] buffer)This will create a new PDStream object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCompression()If there are not compression filters on the current stream then this will add a compression filter, flate compression for example.java.io.InputStreamcreateInputStream()This will get a stream that can be read from.java.io.OutputStreamcreateOutputStream()This will get a stream that can be written to.byte[]getByteArray()This will copy the stream into a byte array.COSBasegetCOSObject()Convert this standard java object to a COS object.java.util.ListgetDecodeParams()Get the list of decode parameters.PDFileSpecificationgetFile()This will get the file specification for this stream.java.util.ListgetFileDecodeParams()Get the list of decode parameters.java.util.ListgetFileFilters()This will get the list of filters that are associated with this stream.java.util.ListgetFilters()This will get the list of filters that are associated with this stream.intgetLength()This will get the length of the filtered/compressed stream.PDMetadatagetMetadata()Get the metadata that is part of the document catalog.java.io.InputStreamgetPartiallyFilteredStream(java.util.List stopFilters)This will get a stream with some filters applied but not others.COSStreamgetStream()Get the cos stream associated with this object.voidsetDecodeParams(java.util.List decodeParams)This will set the list of decode params.voidsetFile(PDFileSpecification f)Set the file specification.voidsetFileDecodeParams(java.util.List decodeParams)This will set the list of decode params.voidsetFileFilters(java.util.List filters)This will set the filters that are part of this stream.voidsetFilters(java.util.List filters)This will set the filters that are part of this stream.voidsetMetadata(PDMetadata meta)Set the metadata for this object.-
Methods inherited from class org.apache.pdfbox.pdmodel.common.PDStream
createFromCOS, getDecodedStreamLength, getDecodeParms, getInputStreamAsString, setDecodedStreamLength, setDecodeParms
-
-
-
-
Method Detail
-
addCompression
public void addCompression()
If there are not compression filters on the current stream then this will add a compression filter, flate compression for example.- Overrides:
addCompressionin classPDStream
-
getCOSObject
public COSBase getCOSObject()
Convert this standard java object to a COS object.- Specified by:
getCOSObjectin interfaceCOSObjectable- Overrides:
getCOSObjectin classPDStream- Returns:
- The cos object that matches this Java object.
-
createOutputStream
public java.io.OutputStream createOutputStream() throws java.io.IOExceptionThis will get a stream that can be written to.- Overrides:
createOutputStreamin classPDStream- Returns:
- An output stream to write data to.
- Throws:
java.io.IOException- If an IO error occurs during writing.
-
createInputStream
public java.io.InputStream createInputStream() throws java.io.IOExceptionThis will get a stream that can be read from.- Overrides:
createInputStreamin classPDStream- Returns:
- An input stream that can be read from.
- Throws:
java.io.IOException- If an IO error occurs during reading.
-
getPartiallyFilteredStream
public java.io.InputStream getPartiallyFilteredStream(java.util.List stopFilters) throws java.io.IOExceptionThis 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- Overrides:
getPartiallyFilteredStreamin classPDStream- 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
public COSStream getStream()
Get the cos stream associated with this 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.
-
getFilters
public java.util.List getFilters()
This will get the list of filters that are associated with this stream. Or null if there are none.- Overrides:
getFiltersin classPDStream- Returns:
- A list of all encoding filters to apply to this stream.
-
setFilters
public void setFilters(java.util.List filters)
This will set the filters that are part of this stream.- Overrides:
setFiltersin classPDStream- Parameters:
filters- The filters that are part of this stream.
-
getDecodeParams
public java.util.List getDecodeParams() throws java.io.IOExceptionGet 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.
-
setDecodeParams
public void setDecodeParams(java.util.List decodeParams)
This will set the list of decode params.- Parameters:
decodeParams- The list of decode params.
-
getFile
public PDFileSpecification getFile()
This will get the file specification for this stream. This is only required for external files.
-
setFile
public void setFile(PDFileSpecification f)
Set the file specification.
-
getFileFilters
public java.util.List getFileFilters()
This will get the list of filters that are associated with this stream. Or null if there are none.- Overrides:
getFileFiltersin classPDStream- Returns:
- A list of all encoding filters to apply to this stream.
-
setFileFilters
public void setFileFilters(java.util.List filters)
This will set the filters that are part of this stream.- Overrides:
setFileFiltersin classPDStream- Parameters:
filters- The filters that are part of this stream.
-
getFileDecodeParams
public java.util.List getFileDecodeParams() throws java.io.IOExceptionGet the list of decode parameters. Each entry in the list will refer to an entry in the filters list.- Overrides:
getFileDecodeParamsin classPDStream- 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.- Overrides:
setFileDecodeParamsin classPDStream- Parameters:
decodeParams- The list of decode params.
-
getByteArray
public byte[] getByteArray() throws java.io.IOExceptionThis will copy the stream into a byte array.- Overrides:
getByteArrayin classPDStream- Returns:
- The byte array of the filteredStream
- Throws:
java.io.IOException- When getFilteredStream did not work
-
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.- Overrides:
getMetadatain classPDStream- Returns:
- The metadata for this object.
-
setMetadata
public void setMetadata(PDMetadata meta)
Set the metadata for this object. This can be null.- Overrides:
setMetadatain classPDStream- Parameters:
meta- The meta data for this object.
-
-