Class StandardFormBody

All Implemented Interfaces:
AutoCloseable

public final class StandardFormBody extends FormBody<String>
The StandardFormBody class represents an HTTP request body that contains form data encoded in the standard application/x-www-form-urlencoded format.

This class extends the FormBody class and provides methods to deserialize the form data from an input stream and access individual form fields.

Since:
2.2.0-SNAPSHOT
See Also:
  • Constructor Details

    • StandardFormBody

      public StandardFormBody(Request request, InputStream body) throws IOException
      Constructs a new StandardFormBody by reading and parsing form data from an input stream.
      Parameters:
      request - The representation of the http request.
      body - The input stream containing the form data.
      Throws:
      IOException - If an error occurs while reading or parsing the form data.
  • Method Details

    • deserialize

      protected void deserialize() throws IOException
      Deserializes the input stream, parsing it into individual form fields and values. This method reads the input streamline by line, splitting it into form fields and their values. It then decodes and stores the field names and values in the data map.
      Specified by:
      deserialize in class FormBody<String>
      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 form data.
      Specified by:
      hasField in class FormBody<String>
      Parameters:
      name - The name of the field to check.
      Returns:
      true if the field exists, otherwise false.
    • getField

      public String getField(String name)
      Retrieves the value of a specific field from the form data.
      Specified by:
      getField in class FormBody<String>
      Parameters:
      name - The name of the field to retrieve.
      Returns:
      The value of the field, or null if the field does not exist.