Interface StreamingResponseBody
- All Known Implementing Classes:
StreamingResponseBody.InputStreamBody, StreamingResponseBody.PublisherBody, StreamingResponseBody.ReaderBody, StreamingResponseBody.WriterBody
This type describes how response bytes are produced; it is not itself responsible for writing to a transport. Descriptors are immutable and thread-safe, but caller-supplied writers, publishers, readers, input streams, and suppliers are responsible for their own behavior.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classA streaming body backed by anInputStreamsupplier.static final classBuilder for input-stream-backed response bodies.static final classA streaming body backed by aFlow.Publisher.static final classA streaming body backed by aReadersupplier.static final classBuilder for reader-backed response bodies.static final classA streaming body backed by a writer callback. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NonNull CodingErrorActionstatic final @NonNull CodingErrorAction -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic @NonNull StreamingResponseBodyfromInputStream(@NonNull Supplier<? extends InputStream> inputStreamSupplier) Creates a streaming response body backed by an input stream supplier.static @NonNull StreamingResponseBodyfromPublisher(@NonNull Flow.Publisher<@NonNull ByteBuffer> publisher) Creates a streaming response body backed by aFlow.Publisherof byte buffers.static @NonNull StreamingResponseBodyCreates a streaming response body backed by a reader supplier.static @NonNull StreamingResponseBodyCreates a streaming response body backed by a writer callback.withInputStream(@NonNull Supplier<? extends InputStream> inputStreamSupplier) Acquires a builder for an input-stream-backed response body.Acquires a builder for a reader-backed response body.
-
Field Details
-
DEFAULT_INPUT_STREAM_BUFFER_SIZE_IN_BYTES
-
DEFAULT_READER_BUFFER_SIZE_IN_CHARACTERS
-
DEFAULT_MALFORMED_INPUT_ACTION
-
DEFAULT_UNMAPPABLE_CHARACTER_ACTION
-
-
Method Details
-
fromWriter
Creates a streaming response body backed by a writer callback.- Parameters:
writer- the callback that writes the response- Returns:
- a streaming response body
-
fromPublisher
static @NonNull StreamingResponseBody fromPublisher(@NonNull Flow.Publisher<@NonNull ByteBuffer> publisher) Creates a streaming response body backed by aFlow.Publisherof byte buffers.Soklet requests one item at a time and writes each item through its bounded streaming queue. If the queue is full, the subscriber's
onNextpath may block until space is available.If the response is canceled before the publisher terminates, Soklet cancels the publisher subscription.
- Parameters:
publisher- the publisher that emits response bytes- Returns:
- a streaming response body
-
fromInputStream
static @NonNull StreamingResponseBody fromInputStream(@NonNull Supplier<? extends InputStream> inputStreamSupplier) Creates a streaming response body backed by an input stream supplier.This adapter is intended for special cases where an existing streaming source is already exposed as an
InputStream. Dynamic application streaming should usually usefromWriter(StreamingResponseWriter)orfromPublisher(Flow.Publisher).If the response is canceled while a read is blocked, Soklet closes the supplied input stream.
- Parameters:
inputStreamSupplier- supplies the input stream to copy- Returns:
- a streaming response body
-
withInputStream
static @NonNull StreamingResponseBody.InputStreamBuilder withInputStream(@NonNull Supplier<? extends InputStream> inputStreamSupplier) Acquires a builder for an input-stream-backed response body.- Parameters:
inputStreamSupplier- supplies the input stream to copy- Returns:
- the builder
-
fromReader
static @NonNull StreamingResponseBody fromReader(@NonNull Supplier<? extends Reader> readerSupplier, @NonNull Charset charset) Creates a streaming response body backed by a reader supplier.The charset is required. Encoding errors default to
CodingErrorAction.REPORT; usewithReader(Supplier, Charset)to override the JDK encoder actions explicitly. If the response is canceled while a read is blocked, Soklet closes the supplied reader.- Parameters:
readerSupplier- supplies the reader to copycharset- charset used to encode characters to response bytes- Returns:
- a streaming response body
-
withReader
static @NonNull StreamingResponseBody.ReaderBuilder withReader(@NonNull Supplier<? extends Reader> readerSupplier, @NonNull Charset charset) Acquires a builder for a reader-backed response body.- Parameters:
readerSupplier- supplies the reader to copycharset- charset used to encode characters to response bytes- Returns:
- the builder
-