Interface LimitEncodedOutput<T,E extends Exception>

Type Parameters:
T - the downstream output type
E - the exception type that can be thrown while writing to the output type
All Superinterfaces:
AutoCloseable, Output<E>, Output.CloseableEncodedOutput<E>, Output.EncodedOutput<E>
All Known Implementing Classes:
ThresholdEncodedOutput, ThresholdEncodedOutput.OutputStreamThresholdEncodedOutput

public sealed interface LimitEncodedOutput<T,E extends Exception> extends Output.CloseableEncodedOutput<E> permits ThresholdEncodedOutput<T,E> (not exhaustive)
This output will limit buffering by byte count and then fallback to pushing to the downstream output type of T once limit is exceeded. If the limit is not exceeded then the buffered data will be replayed and pushed when closed. Consequently this output strategy is a better fit for integration of blocking APIs such as Servlet based frameworks where the data is pushed instead of pulled. If pulling is more desired (non blocking code generally prefers a pull approach) than BufferedEncodedOutput is a better fit but requires the entire output be buffered.

The output T is generally lazily created once and only once by calling and the total size buffered will be passed if under limit. If the limit is exceeded than the size passed will be -1.

For this implementation to work Output.CloseableEncodedOutput.close() must be called and thus a try-with-resource is recommended regardless if the downstream consumer needs to be closed or not!

The total buffered amount of data is not guaranteed to be exactly at the limit even if the total output is greater than the limit.

Author:
agentgt
See Also:
API Note
This class is not thread safe.
  • Method Details

    • limit

      int limit()
      Buffer limit
      Returns:
      limit buffer to this amount of bytes
    • size

      int size()
      Current amount of bytes written.
      Returns:
      number of bytes written.
    • consumer

      @Nullable T consumer()
      The created consumer. Maybe null but on successful close should not be. This is not to create the consumer but to fetch it after processing has finished since the consumer is created on demand.
      Returns:
      created consumer