Package io.pebbletemplates.pebble.utils
Class LimitedSizeWriter
java.lang.Object
java.io.Writer
io.pebbletemplates.pebble.utils.LimitedSizeWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
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.
-
Method Details
-
from
-
write
- Specified by:
writein classWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
toString
-