Package com.jsgalactic.axiom.http
Class Body
java.lang.Object
com.jsgalactic.axiom.http.Body
Immutable request content and its declared content type.
A body owns a private copy of its bytes: factories copy their input, and bytes()
returns a fresh copy, so neither the producer nor any reader can change what others see. Bodies
are safe to share between threads. Transports enforce size limits before creating a body; a body
itself has no limit beyond the array size. toString() reports only the length and media
type, never content.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCollects bytes into a private array and turns it into aBodywithout copying it again. -
Method Summary
Modifier and TypeMethodDescriptionReturns a read-only view of the content without copying it.static Body.BuilderStarts a body whose array is filled incrementally and then handed to the body without another copy.byte[]bytes()Returns a copy of the content.charset()Returns the lowercase value of the content type'scharsetparameter, unquoted.Returns the Content-Type header value as received.static Bodyempty()Returns the shared empty body without a content type.booleaninthashCode()booleanisEmpty()Reports whether there is no content.intlength()Returns the content length in bytes.Returns the lowercasetype/subtypeof the content type, without parameters.static BodyCreates a body from a copy of the supplied bytes.static Bodyof(String contentType, ByteBuffer... parts) Creates a body by concatenating the remaining bytes of each buffer in order, copying them once.toString()Describes the body without revealing its content.
-
Method Details
-
empty
Returns the shared empty body without a content type.- Returns:
- empty body
-
of
Creates a body from a copy of the supplied bytes.- Parameters:
contentType- Content-Type header value, or null when absentbytes- content; copied- Returns:
- body
- Throws:
IllegalArgumentException- if the content type contains control or non-Latin-1 characters
-
of
Creates a body by concatenating the remaining bytes of each buffer in order, copying them once. The buffers' positions are not changed.- Parameters:
contentType- Content-Type header value, or null when absentparts- content buffers; read, not retained- Returns:
- body
- Throws:
IllegalArgumentException- if the combined length exceeds the maximum array size or the content type is invalid
-
builder
Starts a body whose array is filled incrementally and then handed to the body without another copy. Transports use it to read network buffers straight into the array that becomes the request body, so a body is copied exactly once on its way in.- Parameters:
contentType- Content-Type header value, or null when absentcapacity- initial capacity in bytes; not negative- Returns:
- an empty builder
- Throws:
IllegalArgumentException- for a negative or oversized capacity
-
contentType
Returns the Content-Type header value as received.- Returns:
- raw content type, if declared
-
mediaType
Returns the lowercasetype/subtypeof the content type, without parameters.- Returns:
- media type, or empty when absent or malformed
-
charset
Returns the lowercase value of the content type'scharsetparameter, unquoted.- Returns:
- charset name, or empty when absent
-
length
public int length()Returns the content length in bytes.- Returns:
- length
-
isEmpty
public boolean isEmpty()Reports whether there is no content.- Returns:
- true for zero bytes
-
bytes
public byte[] bytes()Returns a copy of the content.- Returns:
- fresh array owned by the caller
-
asReadOnlyBuffer
Returns a read-only view of the content without copying it.- Returns:
- read-only buffer positioned at zero
-
equals
-
hashCode
public int hashCode() -
toString
Describes the body without revealing its content.
-