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
public abstract class AbstractCompareResultWithSwap extends CompareResultImpl
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 Constructor Description AbstractCompareResultWithSwap()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddPage(PageDiffCalculator diffCalculator, int pageIndex, ImageWithDimension expectedImage, ImageWithDimension actualImage, ImageWithDimension diffImage)protected voidafterSwap()protected voidfinalize()protected booleanhasImages()checks, whether this CompareResult has stored images.protected abstract booleanneedToSwap()booleanwriteTo(OutputStream outputStream)Write the result Pdf to an OutputStream.booleanwriteTo(String filename)Write 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, setEnvironment
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.redsix.pdfcompare.ResultCollector
done
-
-
-
-
Method Detail
-
writeTo
public boolean writeTo(String filename)
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
public boolean writeTo(OutputStream outputStream)
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
-
-