Package de.redsix.pdfcompare
Class AbstractCompareResultWithSwap
java.lang.Object
de.redsix.pdfcompare.CompareResultImpl
de.redsix.pdfcompare.AbstractCompareResultWithSwap
- All Implemented Interfaces:
CompareResult,ResultCollector
- Direct Known Subclasses:
CompareResultWithMemoryOverflow,CompareResultWithPageOverflow
This CompareResult monitors the memory the JVM consumes through Runtime.totalMemory() - Runtime.freeMemory()
when a new page is added. When the consumed memory crosses a threshold, images are swapped to disk and removed
from memory. The threshold defaults to 70% of Runtime.maxMemory() but at least 200MB, which worked for me.
After swapping, a System.gc() is triggered.
-
Field Summary
Fields inherited from class de.redsix.pdfcompare.CompareResultImpl
diffImages, environment, hasDifferenceInExclusion, isEqual -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPage(PageDiffCalculator diffCalculator, int pageIndex, ImageWithDimension expectedImage, ImageWithDimension actualImage, ImageWithDimension diffImage) protected voidprotected voidfinalize()protected booleanchecks, whether this CompareResult has stored images.protected abstract booleanbooleanwriteTo(OutputStream outputStream) Write the result Pdf to an OutputStream.booleanWrite the result Pdf to a file.Methods inherited from class de.redsix.pdfcompare.CompareResultImpl
actualOnly, addImagesToDocument, addImagesToDocument, addPageToDocument, expectedOnly, getDifferences, getDifferencesJson, getNumberOfPages, getPageDiffsInPercent, getPagesWithDifferences, hasDifferenceInExclusion, hasOnlyActual, hasOnlyExpected, hasOnlyOneDoc, isEqual, isNotEqual, keepImages, noPagesFound, setEnvironmentMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.redsix.pdfcompare.ResultCollector
done
-
Constructor Details
-
AbstractCompareResultWithSwap
public AbstractCompareResultWithSwap()
-
-
Method Details
-
writeTo
Description copied from interface:CompareResultWrite the result Pdf to a file. Warning: This will remove the diffImages from memory! Writing can only be done once. When no diff images are present, nothing is written.- Specified by:
writeToin interfaceCompareResult- Overrides:
writeToin classCompareResultImpl- Parameters:
filename- without pdf-Extension- Returns:
- a boolean indicating, whether the comparison is equal. When true, the files are equal.
-
writeTo
Description copied from interface:CompareResultWrite the result Pdf to an OutputStream. Warning: This will remove the diffImages from memory! Writing can only be done once. When no diff images are present, nothing is written. The given OutputStream will be closed when this method returns.- Specified by:
writeToin interfaceCompareResult- Overrides:
writeToin classCompareResultImpl- Parameters:
outputStream- to write the pdfFile to.- Returns:
- a boolean indicating, whether the comparison is equal. When true, the files are equal.
-
addPage
public void addPage(PageDiffCalculator diffCalculator, int pageIndex, ImageWithDimension expectedImage, ImageWithDimension actualImage, ImageWithDimension diffImage) - Specified by:
addPagein interfaceResultCollector- Overrides:
addPagein classCompareResultImpl
-
afterSwap
protected void afterSwap() -
needToSwap
protected abstract boolean needToSwap() -
hasImages
protected boolean hasImages()Description copied from class:CompareResultImplchecks, whether this CompareResult has stored images.- Overrides:
hasImagesin classCompareResultImpl- Returns:
- true, when images are stored in this CompareResult
-
finalize
protected void finalize()
-