java.lang.Object
org.miaixz.bus.http.bodys.MultipartBody.Builder
- Enclosing class:
MultipartBody
A builder for creating
MultipartBody instances.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddFormDataPart(String name, String value) Adds a form-data part.addFormDataPart(String name, String filename, RequestBody body) Adds a form-data part with a filename.addPart(MultipartBody.Part part) Adds a part.addPart(RequestBody body) Adds a part with no headers.addPart(Headers headers, RequestBody body) Adds a part with the given headers and body.build()Builds a newMultipartBodyinstance.setType(org.miaixz.bus.core.lang.MediaType type) Sets the media type.
-
Constructor Details
-
Builder
public Builder()Default constructor that uses a random UUID as the boundary. -
Builder
Constructs a new builder with a specified boundary.- Parameters:
boundary- The boundary separator.
-
-
Method Details
-
setType
Sets the media type.Supported types include
MediaType.MULTIPART_MIXED(default),MediaType.MULTIPART_ALTERNATIVE,MediaType.MULTIPART_DIGEST,MediaType.MULTIPART_PARALLEL, andMediaType.MULTIPART_FORM_DATA.- Parameters:
type- The media type.- Returns:
- this builder instance.
- Throws:
NullPointerException- if type is null.IllegalArgumentException- if the type is not a multipart type.
-
addPart
Adds a part with no headers.- Parameters:
body- The request body.- Returns:
- this builder instance.
-
addPart
Adds a part with the given headers and body.- Parameters:
headers- The headers.body- The request body.- Returns:
- this builder instance.
-
addFormDataPart
Adds a form-data part.- Parameters:
name- The field name.value- The field value.- Returns:
- this builder instance.
-
addFormDataPart
Adds a form-data part with a filename.- Parameters:
name- The field name.filename- The filename.body- The request body.- Returns:
- this builder instance.
-
addPart
Adds a part.- Parameters:
part- The part instance.- Returns:
- this builder instance.
- Throws:
NullPointerException- if part is null.
-
build
Builds a newMultipartBodyinstance.- Returns:
- A new
MultipartBodyinstance. - Throws:
IllegalStateException- if no parts have been added.
-