Fork me on GitHub

LimitedSizeWriter

In package com.mitchellbosecke.pebble.utils

public class LimitedSizeWriter extends Writer

A Writer that will wrap around the internal writer if the user also provided a limit on the size of the rendered template. The context is shared between all the writers used to evaluate a template: the one supplied by the user when calling template.evaluate as well as any internally created writers e.g. when evaluating a macro.

There will be false positives. For example if a function writes something and its output is passed to a filter than we count both the output of the function and the output of the filter, when we should only count the output of the filter. This is fine because the user can increase the maximum allowable size accordingly. The purpose here is not to be precise but to protect against abuse.

If the limit is reached a PebbleException will be thrown. If the limit is negative then no checks will be performed and the original writer used as is.

This is thread-safe if RenderedSizeContext is thread-safe.

Methods

public static Writer from(Writer internalWriter, RenderedSizeContext context)
Parameters:
public void write(char cbuf, int off, int len)
Parameters:
  • char cbuf
  • int off
  • int len
public void flush()
Parameters:
  • No parameters
public void close()
Parameters:
  • No parameters
public String toString()
Parameters:
  • No parameters