java.lang.Object
org.sejda.sambox.output.PDFBodyWriter
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.sejda.io.CountingWritableByteChannelprivate static final org.slf4j.Loggerprivate longprivate static final intprivate final IndirectObjectsWriterFields inherited from class org.sejda.sambox.output.PDFBodyWriter
objectsWriter -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateExistingPagesSizePredictor(PDFWriteContext context, IndirectObjectsWriter writer, org.sejda.io.CountingWritableByteChannel channel) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds theCOSObjectableto the predicted size.voidAdds aPDPageto the predicted size.voidclose()booleanhasPages()static ExistingPagesSizePredictorinstance(WriteOption... opts) Factory method for an ExistingPagesSizePredictorlongpages()longlongMethods inherited from class org.sejda.sambox.output.PDFBodyWriter
context, createIndirectReferenceIfNeededFor, onPotentialIndirectObject, startWriting, visit, visit, visit, visit, write, write
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
STREAM_WRAPPING_SIZE
private static final int STREAM_WRAPPING_SIZE- See Also:
-
channel
private final org.sejda.io.CountingWritableByteChannel channel -
writer
-
pages
private long pages
-
-
Constructor Details
-
ExistingPagesSizePredictor
private ExistingPagesSizePredictor(PDFWriteContext context, IndirectObjectsWriter writer, org.sejda.io.CountingWritableByteChannel channel)
-
-
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- Overrides:
closein classPDFBodyWriter- Throws:
IOException
-
instance
Factory method for an ExistingPagesSizePredictor- Parameters:
opts-- Returns:
-