Package org.apache.juneau.http.entity
Class MultipartBody
java.lang.Object
org.apache.juneau.http.entity.MultipartBody
- All Implemented Interfaces:
HttpBody
An
HttpBody that serializes a multipart/form-data message (RFC 7578).
Each part is a MultipartBody.MultipartPart that carries a field name, an optional filename, an optional
per-part Content-Type, and a body writer. When writeTo(OutputStream) is called the
parts are streamed directly — no full-body buffering occurs.
Example:
isRepeatable() returns false when any part wraps a one-shot stream, and true
when all parts are repeatable (e.g. strings, files, byte arrays).
See Also:
- Since:
- 9.2.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFluent builder forMultipartBody.static final recordA single part within aMultipartBody. -
Method Summary
Modifier and TypeMethodDescriptionstatic MultipartBody.Builderbuilder()Returns a newMultipartBody.Builder.Returns the multipart boundary string.longReturns-1— multipart bodies are streamed without pre-computing the total length.Returns the MIME content type of this body, e.g.getParts()Returns an unmodifiable view of the parts in this multipart body.booleanReturnstrueif this body can be written more than once.voidwriteTo(OutputStream out) Writes the body content to the given output stream.
-
Method Details
-
builder
Returns a newMultipartBody.Builder. -
getContentType
Description copied from interface:HttpBodyReturns the MIME content type of this body, e.g."application/json; charset=UTF-8".- Specified by:
getContentTypein interfaceHttpBody- Returns:
- The content type, or
null if unknown.
-
getContentLength
Returns-1— multipart bodies are streamed without pre-computing the total length.- Specified by:
getContentLengthin interfaceHttpBody- Returns:
- The content length, or
-1if unknown.
-
writeTo
Description copied from interface:HttpBodyWrites the body content to the given output stream.Implementations must not close
out.- Specified by:
writeToin interfaceHttpBody- Parameters:
out- The stream to write to. Nevernull .- Throws:
IOException- If an I/O error occurs.
-
isRepeatable
Description copied from interface:HttpBodyReturnstrueif this body can be written more than once.Streaming bodies backed by a one-shot
InputStreamshould returnfalse. Buffered bodies (byte arrays, strings, files) should returntrue.- Specified by:
isRepeatablein interfaceHttpBody- Returns:
trueif repeatable.
-
getBoundary
Returns the multipart boundary string.- Returns:
- The boundary. Never
null .
-
getParts
Returns an unmodifiable view of the parts in this multipart body.- Returns:
- The parts. Never
null .
-