Package com.itextpdf.text.pdf
Class MemoryLimitsAwareHandler
- java.lang.Object
-
- com.itextpdf.text.pdf.MemoryLimitsAwareHandler
-
public class MemoryLimitsAwareHandler extends java.lang.Object
AMemoryLimitsAwareHandler
handles memory allocation and prevents decompressed pdf streams from occupation of more space than allowed.
-
-
Field Summary
Fields Modifier and Type Field Description private long
allMemoryUsedForDecompression
(package private) boolean
considerCurrentPdfStream
private long
maxSizeOfDecompressedPdfStreamsSum
private int
maxSizeOfSingleDecompressedPdfStream
private long
memoryUsedForCurrentPdfStreamDecompression
private static int
SINGLE_DECOMPRESSED_PDF_STREAM_MIN_SIZE
private static int
SINGLE_SCALE_COEFFICIENT
private static long
SUM_OF_DECOMPRESSED_PDF_STREAMW_MIN_SIZE
private static int
SUM_SCALE_COEFFICIENT
-
Constructor Summary
Constructors Constructor Description MemoryLimitsAwareHandler()
Creates aMemoryLimitsAwareHandler
which will be used to handle decompression of pdf streams.MemoryLimitsAwareHandler(long documentSize)
Creates aMemoryLimitsAwareHandler
which will be used to handle decompression of pdf streams.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) MemoryLimitsAwareHandler
beginDecompressedPdfStreamProcessing()
Begins handling of current pdf stream decompression.private static long
calculateDefaultParameter(long documentSize, int scale, long min)
(package private) MemoryLimitsAwareHandler
considerBytesOccupiedByDecompressedPdfStream(long numOfOccupiedBytes)
Considers the number of bytes which are occupied by the decompressed pdf stream.(package private) MemoryLimitsAwareHandler
endDecompressedPdfStreamProcessing()
Ends handling of current pdf stream decompression.private void
ensureCurrentStreamIsReset()
(package private) long
getAllMemoryUsedForDecompression()
long
getMaxSizeOfDecompressedPdfStreamsSum()
Gets the maximum allowed size which can be occupied by all decompressed pdf streams.int
getMaxSizeOfSingleDecompressedPdfStream()
Gets the maximum allowed size which can be occupied by a single decompressed pdf stream.MemoryLimitsAwareHandler
setMaxSizeOfDecompressedPdfStreamsSum(long maxSizeOfDecompressedPdfStreamsSum)
Sets the maximum allowed size which can be occupied by all decompressed pdf streams.MemoryLimitsAwareHandler
setMaxSizeOfSingleDecompressedPdfStream(int maxSizeOfSingleDecompressedPdfStream)
Sets the maximum allowed size which can be occupied by a single decompressed pdf stream.
-
-
-
Field Detail
-
SINGLE_SCALE_COEFFICIENT
private static final int SINGLE_SCALE_COEFFICIENT
- See Also:
- Constant Field Values
-
SUM_SCALE_COEFFICIENT
private static final int SUM_SCALE_COEFFICIENT
- See Also:
- Constant Field Values
-
SINGLE_DECOMPRESSED_PDF_STREAM_MIN_SIZE
private static final int SINGLE_DECOMPRESSED_PDF_STREAM_MIN_SIZE
- See Also:
- Constant Field Values
-
SUM_OF_DECOMPRESSED_PDF_STREAMW_MIN_SIZE
private static final long SUM_OF_DECOMPRESSED_PDF_STREAMW_MIN_SIZE
- See Also:
- Constant Field Values
-
maxSizeOfSingleDecompressedPdfStream
private int maxSizeOfSingleDecompressedPdfStream
-
maxSizeOfDecompressedPdfStreamsSum
private long maxSizeOfDecompressedPdfStreamsSum
-
allMemoryUsedForDecompression
private long allMemoryUsedForDecompression
-
memoryUsedForCurrentPdfStreamDecompression
private long memoryUsedForCurrentPdfStreamDecompression
-
considerCurrentPdfStream
boolean considerCurrentPdfStream
-
-
Constructor Detail
-
MemoryLimitsAwareHandler
public MemoryLimitsAwareHandler()
Creates aMemoryLimitsAwareHandler
which will be used to handle decompression of pdf streams. The max allowed memory limits will be generated by default.
-
MemoryLimitsAwareHandler
public MemoryLimitsAwareHandler(long documentSize)
Creates aMemoryLimitsAwareHandler
which will be used to handle decompression of pdf streams. The max allowed memory limits will be generated by default, based on the size of the document.- Parameters:
documentSize
- the size of the document, which is going to be handled by iText.
-
-
Method Detail
-
getMaxSizeOfSingleDecompressedPdfStream
public int getMaxSizeOfSingleDecompressedPdfStream()
Gets the maximum allowed size which can be occupied by a single decompressed pdf stream.- Returns:
- the maximum allowed size which can be occupied by a single decompressed pdf stream.
-
setMaxSizeOfSingleDecompressedPdfStream
public MemoryLimitsAwareHandler setMaxSizeOfSingleDecompressedPdfStream(int maxSizeOfSingleDecompressedPdfStream)
Sets the maximum allowed size which can be occupied by a single decompressed pdf stream. This value correlates with maximum heap size. This value should not exceed limit of the heap size. iText will throw an exception if during decompression a pdf stream with two or more filters of identical type occupies more memory than allowed.- Parameters:
maxSizeOfSingleDecompressedPdfStream
- the maximum allowed size which can be occupied by a single decompressed pdf stream.- Returns:
- this
MemoryLimitsAwareHandler
instance.
-
getMaxSizeOfDecompressedPdfStreamsSum
public long getMaxSizeOfDecompressedPdfStreamsSum()
Gets the maximum allowed size which can be occupied by all decompressed pdf streams.- Returns:
- the maximum allowed size value which streams may occupy
-
setMaxSizeOfDecompressedPdfStreamsSum
public MemoryLimitsAwareHandler setMaxSizeOfDecompressedPdfStreamsSum(long maxSizeOfDecompressedPdfStreamsSum)
Sets the maximum allowed size which can be occupied by all decompressed pdf streams. This value can be limited by the maximum expected PDF file size when it's completely decompressed. Setting this value correlates with the maximum processing time spent on document reading iText will throw an exception if during decompression pdf streams with two or more filters of identical type occupy more memory than allowed.- Parameters:
maxSizeOfDecompressedPdfStreamsSum
- he maximum allowed size which can be occupied by all decompressed pdf streams.- Returns:
- this
MemoryLimitsAwareHandler
instance.
-
considerBytesOccupiedByDecompressedPdfStream
MemoryLimitsAwareHandler considerBytesOccupiedByDecompressedPdfStream(long numOfOccupiedBytes)
Considers the number of bytes which are occupied by the decompressed pdf stream. If memory limits have not been faced, throws an exception.- Parameters:
numOfOccupiedBytes
- the number of bytes which are occupied by the decompressed pdf stream.- Returns:
- this
MemoryLimitsAwareHandler
instance.
-
beginDecompressedPdfStreamProcessing
MemoryLimitsAwareHandler beginDecompressedPdfStreamProcessing()
Begins handling of current pdf stream decompression.- Returns:
- this
MemoryLimitsAwareHandler
instance.
-
endDecompressedPdfStreamProcessing
MemoryLimitsAwareHandler endDecompressedPdfStreamProcessing()
Ends handling of current pdf stream decompression. If memory limits have not been faced, throws an exception.- Returns:
- this
MemoryLimitsAwareHandler
instance.
-
getAllMemoryUsedForDecompression
long getAllMemoryUsedForDecompression()
-
calculateDefaultParameter
private static long calculateDefaultParameter(long documentSize, int scale, long min)
-
ensureCurrentStreamIsReset
private void ensureCurrentStreamIsReset()
-
-