java.lang.Object
org.sejda.sambox.output.ExistingPagesSizePredictor
- All Implemented Interfaces:
Closeable,AutoCloseable,COSVisitor
Component that tries to predict the size of a resulting document if
PDPages and COSObjectables are
added to it. The component does its best to return exact predicted values and it does that by simulating an actual
write, despite that, the predicted values should be considered rough estimations and not a byte precision ones.- Author:
- Andrea Vacondio
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdds theCOSObjectableto the predicted size.voidAdds aPDPageto the predicted size.voidclose()booleanhasPages()static ExistingPagesSizePredictorinstance(WriteOption... opts) Factory method for an ExistingPagesSizePredictorvoidCalled during the visit on the objects graph, when a potential indirect object is met.longpages()longlongvoidvoidvisit(COSDictionary value) voidvisit(COSDocument document) voidvoidwrite(COSDocument document) Writes the body of the given documentvoidwrite(IncrementablePDDocument document) Writes the given document
-
Method Details
-
addPage
Adds aPDPageto the predicted size. This component simulates the page write to aDevNullWritableByteChanneland does not release the page objects once written.- Parameters:
page-- Throws:
IOException
-
addIndirectReferenceFor
Adds theCOSObjectableto the predicted size. The object is added as an indirect reference and is processed, specifically, in case ofCOSDictionaryorCOSArray, indirect reference might be created for their values.- Parameters:
value-- Throws:
IOException
-
predictedPagesSize
- Returns:
- the current predicted page size
- Throws:
IOException
-
predictedXrefTableSize
public long predictedXrefTableSize()- Returns:
- the current predicted xref size
- Throws:
IOException
-
hasPages
public boolean hasPages()- Returns:
- true if some page has been written
-
pages
public long pages()- Returns:
- the current number of written pages
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
instance
Factory method for an ExistingPagesSizePredictor- Parameters:
opts-- Returns:
-
write
Writes the given document- Parameters:
document-- Throws:
IOException
-
write
Writes the body of the given document- Parameters:
document-- Throws:
IOException
-
visit
- Specified by:
visitin interfaceCOSVisitor- Throws:
IOException
-
visit
- Specified by:
visitin interfaceCOSVisitor- Throws:
IOException
-
visit
- Specified by:
visitin interfaceCOSVisitor- Throws:
IOException
-
visit
- Specified by:
visitin interfaceCOSVisitor- Throws:
IOException
-
onPotentialIndirectObject
Called during the visit on the objects graph, when a potential indirect object is met. Default implementation creates a new indirect reference for it.- Parameters:
item-- Throws:
IOException
-