Package com.itextpdf.kernel.pdf
Class PdfStream
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObject
-
- com.itextpdf.kernel.pdf.PdfDictionary
-
- com.itextpdf.kernel.pdf.PdfStream
-
- Direct Known Subclasses:
PdfObjectStream
public class PdfStream extends PdfDictionary
Representation of a stream as described in the PDF Specification.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
compressionLevel
private java.io.InputStream
inputStream
private int
length
private long
offset
protected PdfOutputStream
outputStream
-
Fields inherited from class com.itextpdf.kernel.pdf.PdfObject
ARRAY, BOOLEAN, DICTIONARY, FLUSHED, FORBID_RELEASE, FREE, INDIRECT_REFERENCE, indirectReference, LITERAL, MODIFIED, MUST_BE_FLUSHED, MUST_BE_INDIRECT, NAME, NULL, NUMBER, ORIGINAL_OBJECT_STREAM, READ_ONLY, READING, STREAM, STRING, UNENCRYPTED
-
-
Constructor Summary
Constructors Modifier Constructor Description PdfStream()
Creates an empty PdfStream instance.PdfStream(byte[] bytes)
Creates a PdfStream instance.PdfStream(byte[] bytes, int compressionLevel)
Constructs aPdfStream
-object.PdfStream(int compressionLevel)
Constructs aPdfStream
-object.(package private)
PdfStream(long offset, PdfDictionary keys)
PdfStream(PdfDocument doc, java.io.InputStream inputStream)
Creates an efficient stream.PdfStream(PdfDocument doc, java.io.InputStream inputStream, int compressionLevel)
Creates an efficient stream.protected
PdfStream(java.io.OutputStream outputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
copyContent(PdfObject from, PdfDocument document)
Copies object content from object 'from'.protected void
copyContent(PdfObject from, PdfDocument document, ICopyFilter copyFilter)
Copies object content from object 'from'.byte[]
getBytes()
Gets decoded stream bytes.byte[]
getBytes(boolean decoded)
Gets stream bytes.int
getCompressionLevel()
Gets compression level of this PdfStream.protected java.io.InputStream
getInputStream()
int
getLength()
protected long
getOffset()
PdfOutputStream
getOutputStream()
Gets output stream.byte
getType()
Gets object type.protected void
initOutputStream(java.io.OutputStream stream)
protected PdfObject
newInstance()
Creates new instance of object.protected void
releaseContent()
Release content of PdfStream.void
setCompressionLevel(int compressionLevel)
Sets compression level of this PdfStream.void
setData(byte[] bytes)
Setsbytes
as stream's content.void
setData(byte[] bytes, boolean append)
Sets or appendsbytes
to stream content.protected void
updateLength(int length)
Update length manually in case its correction.-
Methods inherited from class com.itextpdf.kernel.pdf.PdfDictionary
clear, clone, containsKey, containsValue, copyTo, copyTo, entrySet, get, get, getAsArray, getAsBool, getAsBoolean, getAsDictionary, getAsFloat, getAsInt, getAsName, getAsNumber, getAsRectangle, getAsStream, getAsString, isEmpty, keySet, mergeDifferent, put, putAll, remove, size, toString, values, values
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObject
checkState, clearState, clone, clone, containsIndirectReference, copyTo, copyTo, copyTo, copyTo, equalContent, flush, flush, getIndirectReference, isArray, isBoolean, isDictionary, isFlushed, isIndirect, isIndirectReference, isLiteral, isModified, isName, isNull, isNumber, isReleaseForbidden, isStream, isString, makeIndirect, makeIndirect, processCopying, processCopying, release, setIndirectReference, setModified, setState
-
-
-
-
Field Detail
-
compressionLevel
protected int compressionLevel
-
outputStream
protected PdfOutputStream outputStream
-
inputStream
private java.io.InputStream inputStream
-
offset
private long offset
-
length
private int length
-
-
Constructor Detail
-
PdfStream
public PdfStream(byte[] bytes, int compressionLevel)
Constructs aPdfStream
-object.- Parameters:
bytes
- initial content ofPdfOutputStream
.compressionLevel
- the compression level (0 = best speed, 9 = best compression, -1 is default)
-
PdfStream
public PdfStream(byte[] bytes)
Creates a PdfStream instance.- Parameters:
bytes
- bytes to write to the PdfStream
-
PdfStream
public PdfStream(PdfDocument doc, java.io.InputStream inputStream, int compressionLevel)
Creates an efficient stream. No temporary array is ever created. TheInputStream
is totally consumed but is not closed. The general usage is:
PdfDocument document = ?; InputStream in = ?; PdfStream stream = new PdfStream(document, in, PdfOutputStream.DEFAULT_COMPRESSION); ? stream.flush(); in.close();
- Parameters:
doc
- thepdf document
in which this stream liesinputStream
- the data to write to this streamcompressionLevel
- the compression level (0 = best speed, 9 = best compression, -1 is default)
-
PdfStream
public PdfStream(PdfDocument doc, java.io.InputStream inputStream)
Creates an efficient stream. No temporary array is ever created. TheInputStream
is totally consumed but is not closed. The general usage is:
PdfDocument document = ?; InputStream in = ?; PdfStream stream = new PdfStream(document, in); stream.flush(); in.close();
- Parameters:
doc
- thepdf document
in which this stream liesinputStream
- the data to write to this stream
-
PdfStream
public PdfStream(int compressionLevel)
Constructs aPdfStream
-object.- Parameters:
compressionLevel
- the compression level (0 = best speed, 9 = best compression, -1 is default)
-
PdfStream
public PdfStream()
Creates an empty PdfStream instance.
-
PdfStream
protected PdfStream(java.io.OutputStream outputStream)
-
PdfStream
PdfStream(long offset, PdfDictionary keys)
-
-
Method Detail
-
getOutputStream
public PdfOutputStream getOutputStream()
Gets output stream.- Returns:
- output stream
-
getCompressionLevel
public int getCompressionLevel()
Gets compression level of this PdfStream. For more details @seeDeflaterOutputStream
.- Returns:
- compression level.
-
setCompressionLevel
public void setCompressionLevel(int compressionLevel)
Sets compression level of this PdfStream. For more details @seeDeflaterOutputStream
.- Parameters:
compressionLevel
- the compression level (0 = best speed, 9 = best compression, -1 is default)
-
getType
public byte getType()
Description copied from class:PdfObject
Gets object type.- Overrides:
getType
in classPdfDictionary
- Returns:
- object type.
-
getLength
public int getLength()
-
getBytes
public byte[] getBytes()
Gets decoded stream bytes. Note,PdfName.DCTDecode
andPdfName.JPXDecode
filters will be ignored.- Returns:
- byte content of the
PdfStream
. Byte content will benull
, if thePdfStream
was created byInputStream
.
-
getBytes
public byte[] getBytes(boolean decoded)
Gets stream bytes. Note,PdfName.DCTDecode
andPdfName.JPXDecode
filters will be ignored.- Parameters:
decoded
- true if to get decoded stream bytes, otherwise false.- Returns:
- byte content of the
PdfStream
. Byte content will benull
, if thePdfStream
was created byInputStream
.
-
setData
public void setData(byte[] bytes)
Setsbytes
as stream's content. Could not be used with streams which were created byInputStream
.- Parameters:
bytes
- new content for stream; ifnull
then stream's content will be discarded
-
setData
public void setData(byte[] bytes, boolean append)
Sets or appendsbytes
to stream content. Could not be used with streams which were created byInputStream
.- Parameters:
bytes
- New content for stream. These bytes are considered to be a raw data (i.e. not encoded/compressed/encrypted) and if it's not true, the corresponding filters shall be set to the PdfStream object manually. Data compression generally should be configured viasetCompressionLevel(int)
and is handled on stream writing to the output document. Ifnull
andappend
is false then stream's content will be discarded.append
- If set to true thenbytes
will be appended to the end, rather then replace original content. The original content will be decoded if needed.
-
newInstance
protected PdfObject newInstance()
Description copied from class:PdfObject
Creates new instance of object.- Overrides:
newInstance
in classPdfDictionary
- Returns:
- new instance of object.
-
getOffset
protected long getOffset()
-
updateLength
protected void updateLength(int length)
Update length manually in case its correction.- Parameters:
length
- the new length- See Also:
PdfReader.checkPdfStreamLength(PdfStream)
-
copyContent
protected void copyContent(PdfObject from, PdfDocument document)
Description copied from class:PdfDictionary
Copies object content from object 'from'.- Overrides:
copyContent
in classPdfDictionary
- Parameters:
from
- object to copy content from.document
- document to copy object to.
-
copyContent
protected void copyContent(PdfObject from, PdfDocument document, ICopyFilter copyFilter)
Description copied from class:PdfDictionary
Copies object content from object 'from'.- Overrides:
copyContent
in classPdfDictionary
- Parameters:
from
- object to copy content from.document
- document to copy object to.copyFilter
-ICopyFilter
a filter that will apply on dictionaries and array UseNullCopyFilter
for no filtering
-
initOutputStream
protected void initOutputStream(java.io.OutputStream stream)
-
releaseContent
protected void releaseContent()
Release content of PdfStream.- Overrides:
releaseContent
in classPdfDictionary
-
getInputStream
protected java.io.InputStream getInputStream()
-
-