Class RequestBody
bytes()— materialises the full body into abyte[]and caches it. Safe to call multiple times; the second call returns the cached array. Throws for bodies larger than 2 GB.stream()— returns a boundedInputStreamwithout upfront allocation. For fixed-length bodies this is a view into the already-buffered header bytes stitched to the socket; for chunked bodies it is the rawthat de-chunks on the fly.invalid reference
dev.relism.ChunkedInputStream
Mutual exclusivity: calling both bytes() and stream() on the same
request produces undefined results. Choose one mode per handler.
Keep-alive: unread body bytes are discarded by Request.drain() after the
handler returns so the socket is correctly positioned for the next pipelined request.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]bytes()Materialises and caches the full body.longDeclared body size in bytes.booleanisEmpty()trueif the body has zero bytes (Content-Length: 0or no body).stream()Returns a boundedInputStreamover the body without upfront allocation.
-
Method Details
-
isEmpty
public boolean isEmpty()trueif the body has zero bytes (Content-Length: 0or no body). -
contentLength
public long contentLength()Declared body size in bytes. Returns-1forTransfer-Encoding: chunkedbodies where the size is not known upfront. -
bytes
public byte[] bytes()Materialises and caches the full body. Suitable for JSON, small form data, and any payload that must be inspected in full. The result is cached — repeated calls return the same array.For chunked bodies (
contentLength()== -1), reads until the chunked stream signals EOF.- Throws:
IllegalStateException- ifcontentLength()exceedsInteger.MAX_VALUE(~2 GB); usestream()for large bodies instead
-
stream
Returns a boundedInputStreamover the body without upfront allocation.For fixed-length bodies: a
SequenceInputStreamof any already-buffered header bytes followed by a bounded view of the socket stream — zero heap beyond those small pre-buffered bytes.For chunked bodies: the raw
that de-chunks on the fly; EOF signals the end of the logical body and leaves the socket positioned for the next keep-alive request.invalid reference
dev.relism.ChunkedInputStreamIf
bytes()was called first, returns a freshByteArrayInputStreamover the cached array.
-