Class MultipartFormBody

All Implemented Interfaces:
AutoCloseable

public final class MultipartFormBody extends FormBody<MultipartFormBody.MultipartData>
The MultipartFormBody class represents an HTTP request body that contains data in the multipart/form-data format. This format is often used to upload files and form fields in HTTP requests.
Since:
2.2.0-SNAPSHOT
See Also:
  • Constructor Details

    • MultipartFormBody

      public MultipartFormBody(Request request, String boundary, InputStream body) throws IOException
      Constructs a new MultipartFormBody by specifying the boundary and providing an input stream containing the multipart/form-data.
      Parameters:
      request - The representation of the http request.
      boundary - The boundary string that separates parts in the multipart request.
      body - The input stream containing the multipart/form-data.
      Throws:
      IOException - If an error occurs while reading or parsing the multipart data.
  • Method Details

    • deserialize

      protected void deserialize() throws IOException
      Deserializes the multipart form body, parsing it into individual parts and storing them in the data map. This method reads the input stream and processes multipart form data, which consists of multiple parts separated by a boundary. It extracts the name, content type, and data of each part and stores them in the data map.
      Specified by:
      deserialize in class FormBody<MultipartFormBody.MultipartData>
      Throws:
      IOException - If an I/O error occurs while reading the input stream.
    • hasField

      public boolean hasField(String name)
      Checks if a specific field exists in the multipart data.
      Specified by:
      hasField in class FormBody<MultipartFormBody.MultipartData>
      Parameters:
      name - The name of the field to check.
      Returns:
      true if the field exists, otherwise false.
    • getField

      public MultipartFormBody.MultipartData getField(String name)
      Retrieves the multipart data for a specific field.
      Specified by:
      getField in class FormBody<MultipartFormBody.MultipartData>
      Parameters:
      name - The name of the field to retrieve.
      Returns:
      The multipart data for the field, or null if the field does not exist.
    • getBoundary

      public String getBoundary()
      Gets the boundary string used to separate parts in the multipart request.
      Returns:
      The boundary string.