For blocking frameworks
LimitEncodedOutput provides a
good solution over just writing to directly to the body
the length of output is needed apriori while avoiding running out of memory for rare
large outputs (in those cases the length will not be determined before writing to the
Because JStachio does not have a reactive model the only reliable solution is to
completely buffer the output. As long as template output is not that large this is
generally not much of a problem as memory is often cheap and GC pretty fast these days.
For this model
BufferedEncodedOutput can allow the
complete output to be read either as a ByteBuffer or a channel.
By typeIn some cases frameworks only allow returning output by a certain type. Below is rough guide based on type.
ClassDescriptionA custom OutputStream that is designed for generating bytes from pre-encoded output as well as reused carefully either by threadlocals or some other pooling mechanism.An encoded output optimized for producing a single
ByteBuffer.Maintains the encoded output in an iterable of chunks of type
Tthat is optimized for
BufferedEncodedOutput.asReadableByteChannel().An encoded output that forwards all calls to a delegate.An encoded output that forwards all calls to a delegate.This output will limit buffering by byte count and then fallback to pushing to the downstream output type of
Tonce limit is exceeded.An OutputStream like callback.Creates output like objects with a buffer size.This abstract output will limit buffering by byte count and then fallback to pushing to the downstream output type of
Tonce limit is exceeded.An OutputStream backed buffer limited encoded output.