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).
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) Removes the 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
-
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
-
build
-