Class BufferedTextStream

java.lang.Object
io.superdurable.dex.BufferedTextStream

public final class BufferedTextStream extends Object
Batches text chunks into best-effort Stream messages during one Step invocation.

Create one writer with create(Context, Stream) and call write(String) from the handler or pass the method as a text-delta callback. The first nonempty chunk starts a one-shot timer. The Worker automatically stops the timer and flushes remaining text before the handler result or error is sent. Chunks are concatenated without separators and never split.

  • Field Details

    • DEFAULT_FLUSH_INTERVAL

      public static final Duration DEFAULT_FLUSH_INTERVAL
      Default one-shot flush interval.
    • DEFAULT_MAX_BUFFERED_BYTES

      public static final int DEFAULT_MAX_BUFFERED_BYTES
      Default soft UTF-8 batch threshold.
      See Also:
  • Method Details

    • create

      public static BufferedTextStream create(Context context, Stream<String> stream)
      Creates a writer with a one-second interval and 16 KiB soft threshold.
      Parameters:
      context - current Step Context
      stream - registered String Stream
      Returns:
      invocation-managed writer
      Throws:
      IllegalArgumentException - if an argument is null or the Stream is not String-valued
      IllegalStateException - if the Context is not an active Step invocation
    • create

      public static BufferedTextStream create(Context context, Stream<String> stream, Duration flushInterval, int maxBufferedBytes)
      Creates a writer with explicit buffering settings.
      Parameters:
      context - current Step Context
      stream - registered String Stream
      flushInterval - positive one-shot flush interval
      maxBufferedBytes - positive soft UTF-8 batch threshold
      Returns:
      invocation-managed writer
      Throws:
      IllegalArgumentException - if an argument or setting is invalid
      IllegalStateException - if the Context is not an active Step invocation
    • write

      public void write(String chunk)
      Appends one chunk and flushes after crossing the soft size threshold.
      Parameters:
      chunk - text appended without modification; an empty value is ignored
      Throws:
      IllegalArgumentException - if chunk is null
      IllegalStateException - if the invocation ended
      RuntimeException - if an earlier background or current output write failed
    • finalizeStepOutput

      public void finalizeStepOutput()
      Flushes the tail and closes this writer during invocation finalization.
    • cancelStepOutput

      public void cancelStepOutput()
      Discards buffered text and stops the timer after invocation cancellation.