Package io.jstach.jstachio.output

@NonNullByDefault package io.jstach.jstachio.output
Output utility classes particularly for leveraging pre-encoding efficiently and shared integration logic for plugging into web application frameworks.

Blocking frameworks


For blocking frameworks LimitEncodedOutput provides a good solution over just writing to directly to the body OutputStream if 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 stream).

Non-blocking frameworks


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 type

In some cases frameworks only allow returning output by a certain type. Below is rough guide based on type.
Output choice by type
Type Strategy
ByteBuffer or byte[] Use ByteBufferEncodedOutput.
Writer Use Renderer.execute(Object, Appendable) (pre-encoding will not be used).
ReadableByteChannel or Iterable<byte[]> Use ChunkEncodedOutput. The iterable of byte[] can also be converted to a reactive data type.
See Also:
API Note
As with most IO the classes in this package are not thread safe unless noted.