Class COSWriterCompressionPool
- java.lang.Object
-
- org.apache.pdfbox.pdfwriter.compress.COSWriterCompressionPool
-
public class COSWriterCompressionPool extends java.lang.ObjectAn instance of this class compresses the contents of a givenPDDocument.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<COSBase>allDirectObjectsprivate PDDocumentdocumentstatic floatMINIMUM_SUPPORTED_VERSIONprivate COSObjectPoolobjectPoolprivate java.util.List<COSObjectKey>objectStreamObjectsprivate CompressParametersparametersprivate java.util.List<COSObjectKey>topLevelObjects
-
Constructor Summary
Constructors Constructor Description COSWriterCompressionPool(PDDocument document, CompressParameters parameters)Constructs an object that can be used to compress the contents of a givenPDDocument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddElements(java.util.Iterator<COSBase> elements)private COSBaseaddObjectToPool(COSObjectKey key, COSBase base)Adds the givenCOSBaseto this pool, using the givenCOSObjectKeyas it's referencable ID.private voidaddStructure(COSBase current)Attempts to find yet unregistered streams and dictionaries in the given structure.booleancontains(COSBase object)Returns true, if the givenCOSBaseis a registered object of this compression pool.java.util.List<COSWriterObjectStream>createObjectStreams()CreatesCOSWriterObjectStreams for all currently registered objects of this pool, that have been marked as fit for being compressed in this manner.longgetHighestXRefObjectNumber()Returns the highest object number, that is registered in this compression pool.COSObjectKeygetKey(COSBase object)Returns theCOSObjectKey, that is registered for the givenCOSBasein this compression pool.COSBasegetObject(COSObjectKey key)Returns theCOSBase, that is registered for the givenCOSObjectKeyin this compression pool.java.util.List<COSObjectKey>getObjectStreamObjects()Returns allCOSBases that can be appended to an object stream.java.util.List<COSObjectKey>getTopLevelObjects()Returns allCOSBases, that must be added to the document's top level container.
-
-
-
Field Detail
-
MINIMUM_SUPPORTED_VERSION
public static final float MINIMUM_SUPPORTED_VERSION
- See Also:
- Constant Field Values
-
document
private final PDDocument document
-
parameters
private final CompressParameters parameters
-
objectPool
private final COSObjectPool objectPool
-
topLevelObjects
private final java.util.List<COSObjectKey> topLevelObjects
-
objectStreamObjects
private final java.util.List<COSObjectKey> objectStreamObjects
-
allDirectObjects
private final java.util.Set<COSBase> allDirectObjects
-
-
Constructor Detail
-
COSWriterCompressionPool
public COSWriterCompressionPool(PDDocument document, CompressParameters parameters) throws java.io.IOException
Constructs an object that can be used to compress the contents of a given
PDDocument. It provides the means to:- Compress the COSStructure of the document, by streaming
COSBases to compressedCOSWriterObjectStreams
- Parameters:
document- The document, that shall be compressed.parameters- The configuration of the compression operations, that shall be applied.- Throws:
java.io.IOException- Shall be thrown if a compression operation failed.
- Compress the COSStructure of the document, by streaming
-
-
Method Detail
-
addObjectToPool
private COSBase addObjectToPool(COSObjectKey key, COSBase base)
Adds the givenCOSBaseto this pool, using the givenCOSObjectKeyas it's referencable ID. This method shall determine an appropriate key, for yet unregistered objects, to register them. Depending on the type of object, it shall either be appended as-is or shall be appended to a compressedCOSWriterObjectStream.- Parameters:
key- TheCOSObjectKeythat shall be used as theCOSBases ID, if possible.base- TheCOSBase, that shall be registered in this pool.
-
addStructure
private void addStructure(COSBase current) throws java.io.IOException
Attempts to find yet unregistered streams and dictionaries in the given structure.- Parameters:
current- The object to be added for compressing.- Throws:
java.io.IOException- Shall be thrown, if compressing the object failed.
-
addElements
private void addElements(java.util.Iterator<COSBase> elements) throws java.io.IOException
- Throws:
java.io.IOException
-
getTopLevelObjects
public java.util.List<COSObjectKey> getTopLevelObjects()
Returns allCOSBases, that must be added to the document's top level container. Those objects are not valid to be added to an object stream.- Returns:
- A list of all top level
COSBases.
-
getObjectStreamObjects
public java.util.List<COSObjectKey> getObjectStreamObjects()
Returns allCOSBases that can be appended to an object stream. This list is only provided to enable reflections. Contained objects should indeed be added to a compressed document via an object stream, as can be created via calling:createObjectStreams()- Returns:
- A list of all
COSBases, that can be added to an object stream.
-
contains
public boolean contains(COSBase object)
Returns true, if the givenCOSBaseis a registered object of this compression pool.- Parameters:
object- The object, that shall be checked.- Returns:
- True, if the given
COSBaseis a registered object of this compression pool.
-
getKey
public COSObjectKey getKey(COSBase object)
Returns theCOSObjectKey, that is registered for the givenCOSBasein this compression pool.- Parameters:
object- TheCOSBaseaCOSObjectKeyis registered for in this compression pool.- Returns:
- The
COSObjectKey, that is registered for the givenCOSBasein this compression pool, if such an object is contained.
-
getObject
public COSBase getObject(COSObjectKey key)
Returns theCOSBase, that is registered for the givenCOSObjectKeyin this compression pool.- Parameters:
key- TheCOSObjectKeyaCOSBaseis registered for in this compression pool.- Returns:
- The
COSBase, that is registered for the givenCOSObjectKeyin this compression pool, if such an object is contained.
-
getHighestXRefObjectNumber
public long getHighestXRefObjectNumber()
Returns the highest object number, that is registered in this compression pool.- Returns:
- The highest object number, that is registered in this compression pool.
-
createObjectStreams
public java.util.List<COSWriterObjectStream> createObjectStreams()
CreatesCOSWriterObjectStreams for all currently registered objects of this pool, that have been marked as fit for being compressed in this manner. Such object streams may be added to a PDF document and shall be declared in a document'sPDFXRefStreamaccordingly. The objects contained in such a stream must not be added to the document separately.- Returns:
- The created
COSWriterObjectStreams for all currently registered compressible objects.
-
-