Class BufferedTextStream
java.lang.Object
io.superdurable.dex.BufferedTextStream
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationDefault one-shot flush interval.static final intDefault soft UTF-8 batch threshold. -
Method Summary
Modifier and TypeMethodDescriptionvoidDiscards buffered text and stops the timer after invocation cancellation.static BufferedTextStreamCreates a writer with a one-second interval and 16 KiB soft threshold.static BufferedTextStreamCreates a writer with explicit buffering settings.voidFlushes the tail and closes this writer during invocation finalization.voidAppends one chunk and flushes after crossing the soft size threshold.
-
Field Details
-
DEFAULT_FLUSH_INTERVAL
Default one-shot flush interval. -
DEFAULT_MAX_BUFFERED_BYTES
public static final int DEFAULT_MAX_BUFFERED_BYTESDefault soft UTF-8 batch threshold.- See Also:
-
-
Method Details
-
create
Creates a writer with a one-second interval and 16 KiB soft threshold.- Parameters:
context- current Step Contextstream- registered String Stream- Returns:
- invocation-managed writer
- Throws:
IllegalArgumentException- if an argument is null or the Stream is not String-valuedIllegalStateException- 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 Contextstream- registered String StreamflushInterval- positive one-shot flush intervalmaxBufferedBytes- positive soft UTF-8 batch threshold- Returns:
- invocation-managed writer
- Throws:
IllegalArgumentException- if an argument or setting is invalidIllegalStateException- if the Context is not an active Step invocation
-
write
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 nullIllegalStateException- if the invocation endedRuntimeException- 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.
-