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.
  • Constructor Details

    • AbstractCompareResultWithSwap

      public AbstractCompareResultWithSwap()
  • Method Details

    • writeTo

      public boolean writeTo(String filename)
      Description copied from interface: CompareResult
      Write 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:
      writeTo in interface CompareResult
      Overrides:
      writeTo in class CompareResultImpl
      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: CompareResult
      Write 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:
      writeTo in interface CompareResult
      Overrides:
      writeTo in class CompareResultImpl
      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:
      addPage in interface ResultCollector
      Overrides:
      addPage in class CompareResultImpl
    • afterSwap

      protected void afterSwap()
    • needToSwap

      protected abstract boolean needToSwap()
    • hasImages

      protected boolean hasImages()
      Description copied from class: CompareResultImpl
      checks, whether this CompareResult has stored images.
      Overrides:
      hasImages in class CompareResultImpl
      Returns:
      true, when images are stored in this CompareResult
    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object