Class MarshaledResponse.Builder
java.lang.Object
com.soklet.MarshaledResponse.Builder
- Enclosing class:
MarshaledResponse
Builder used to construct instances of
MarshaledResponse via MarshaledResponse.withResponse(Response) or MarshaledResponse.withStatusCode(Integer).
Known-length bodies and streaming bodies are mutually exclusive. This builder does not automatically clear one
when the other is set; use withoutBody() or withoutStream() before build() when
switching body modes.
This class is intended for use by a single thread.
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionSets a byte-array-backed response body, or removes any current body ifbytesisnull.Sets a response body descriptor, or removes any current body ifbodyisnull.body(@Nullable ByteBuffer byteBuffer) Sets a byte-buffer-backed response body, or removes any current body ifbyteBufferisnull.body(@NonNull FileChannel fileChannel, @NonNull Long offset, @NonNull Long count, @NonNull Boolean closeOnComplete) Sets a file-channel-backed response body.Sets a ranged path-backed response body.Sets a path-backed response body, or removes any current body ifpathisnull.build()cookies(@Nullable Set<@NonNull ResponseCookie> cookies) statusCode(@NonNull Integer statusCode) stream(@Nullable StreamingResponseBody stream) Sets a streaming response body, or removes any current stream ifstreamisnull.Removes the response body from this builder.Removes the streaming response body from this builder.
-
Method Details
-
statusCode
-
cookies
-
headers
-
body
Sets a byte-array-backed response body, or removes any current body ifbytesisnull.- Parameters:
bytes- the response bytes to write, ornullfor no body- Returns:
- this builder
-
body
Sets a response body descriptor, or removes any current body ifbodyisnull.- Parameters:
body- the response body descriptor to write, ornullfor no body- Returns:
- this builder
-
body
Sets a path-backed response body, or removes any current body ifpathisnull.- Parameters:
path- the file path to write, ornullfor no body- Returns:
- this builder
-
body
public @NonNull MarshaledResponse.Builder body(@NonNull Path path, @NonNull Long offset, @NonNull Long count) Sets a ranged path-backed response body.- Parameters:
path- the file path to writeoffset- the zero-based file offset from which response bytes should be writtencount- the number of file bytes to write- Returns:
- this builder
-
body
public @NonNull MarshaledResponse.Builder body(@NonNull FileChannel fileChannel, @NonNull Long offset, @NonNull Long count, @NonNull Boolean closeOnComplete) Sets a file-channel-backed response body.- Parameters:
fileChannel- the file channel to writeoffset- the zero-based channel offset from which response bytes should be writtencount- the number of channel bytes to writecloseOnComplete- whether Soklet should close the channel after response completion- Returns:
- this builder
-
body
Sets a byte-buffer-backed response body, or removes any current body ifbyteBufferisnull.- Parameters:
byteBuffer- the byte buffer to write, ornullfor no body- Returns:
- this builder
-
stream
Sets a streaming response body, or removes any current stream ifstreamisnull.A response may have a known-length body or a stream, but not both. Setting a stream does not remove any current known-length body; call
withoutBody()first if replacing a known-length body with a stream.build()rejects responses that still specify both.- Parameters:
stream- the streaming response body to write, ornullfor no stream- Returns:
- this builder
-
withoutBody
Removes the response body from this builder.If the current body owns a caller-supplied
FileChannel, the channel is closed before it is removed. Path-backed file bodies are lazy and do not hold open resources at this point.- Returns:
- this builder
-
withoutStream
Removes the streaming response body from this builder.- Returns:
- this builder
-
build
-