Class OutputBudget

java.lang.Object
com.scroogexhtml.converter.OutputBudget

public final class OutputBudget extends Object
Counts what a conversion produces and stops it when it exceeds SecurityConfiguration.getMaxElementCount() or SecurityConfiguration.getMaxOutputChars(), so a small input cannot expand into a huge document.

One instance is used per conversion; it is not thread-safe. Each check is a counter increment and a comparison.

  • Constructor Details

  • Method Details

    • orUnlimited

      public static OutputBudget orUnlimited(OutputBudget budget)
      Parameters:
      budget - a budget, or null
      Returns:
      the budget, or a new one without limits if it is null
    • element

      public void element()
      Counts one element created from the RTF content.
      Throws:
      ConversionException - if the element limit is exceeded
    • text

      public void text(int length)
      Counts text taken from the RTF content. The result is at least as long as its text, so exceeding the limit here stops the conversion early.
      Parameters:
      length - number of characters added
      Throws:
      ConversionException - if the output size limit is exceeded
    • result

      public void result(int length)
      Checks the length of the finished result, markup included.
      Parameters:
      length - the result length in characters
      Throws:
      ConversionException - if the output size limit is exceeded