Module bus.http

Class MultipartBody.Builder

java.lang.Object
org.miaixz.bus.http.bodys.MultipartBody.Builder
Enclosing class:
MultipartBody

public static final class MultipartBody.Builder extends Object
A builder for creating MultipartBody instances.
  • Constructor Details

    • Builder

      public Builder()
      Default constructor that uses a random UUID as the boundary.
    • Builder

      public Builder(String boundary)
      Constructs a new builder with a specified boundary.
      Parameters:
      boundary - The boundary separator.
  • Method Details

    • setType

      public MultipartBody.Builder setType(org.miaixz.bus.core.lang.MediaType type)
      Sets the media type.

      Supported types include MediaType.MULTIPART_MIXED (default), MediaType.MULTIPART_ALTERNATIVE, MediaType.MULTIPART_DIGEST, MediaType.MULTIPART_PARALLEL, and MediaType.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

      public MultipartBody.Builder addPart(RequestBody body)
      Adds a part with no headers.
      Parameters:
      body - The request body.
      Returns:
      this builder instance.
    • addPart

      public MultipartBody.Builder addPart(Headers headers, RequestBody body)
      Adds a part with the given headers and body.
      Parameters:
      headers - The headers.
      body - The request body.
      Returns:
      this builder instance.
    • addFormDataPart

      public MultipartBody.Builder addFormDataPart(String name, String value)
      Adds a form-data part.
      Parameters:
      name - The field name.
      value - The field value.
      Returns:
      this builder instance.
    • addFormDataPart

      public MultipartBody.Builder addFormDataPart(String name, String filename, RequestBody body)
      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

      public MultipartBody build()
      Builds a new MultipartBody instance.
      Returns:
      A new MultipartBody instance.
      Throws:
      IllegalStateException - if no parts have been added.