Class FormData

java.lang.Object
net.bjmsw.hda.vs.model.mime.FormData
All Implemented Interfaces:
HttpBody

public class FormData extends Object implements HttpBody
Represents HTTP form data objects.

This class is used to store form data in a key-value pair. This can be used for multipart/form-data and application/x-www-form-urlencoded.

  • Field Details

  • Constructor Details

    • FormData

      public FormData(Map<String,String> data)
      Constructs a FormData object with the given data.
      Parameters:
      data - a map containing the key-value pairs of the form data
    • FormData

      public FormData()
      Represents a HTTP form data object.

      This class is used to store form data in a key-value pair. It can be used for multipart/form-data and application/x-www-form-urlencoded.

  • Method Details

    • get

      public String get(String key)
      Retrieves the value associated with the given key from the FormData object.
      Parameters:
      key - the key for which the value needs to be retrieved
      Returns:
      the value associated with the key, or null if the key is not present
    • getAll

      public Map<String,String> getAll()
      Retrieves all the key-value pairs stored in the FormData object.
      Returns:
      a map containing all the key-value pairs
    • toString

      public String toString()
      Returns a string representation of the FormData object.

      This method constructs a string by iterating over the key-value pairs stored in the FormData object and appending them to a StringBuilder. The resulting string has the format "FormData(key1: value1; key2: value2; ...)".

      Used for debugging purposes.

      Specified by:
      toString in interface HttpBody
      Overrides:
      toString in class Object
      Returns:
      a string representation of the FormData object
    • set

      public void set(String key, String value)
      Adds a key-value pair to the FormData object.
      Parameters:
      key - the key to be added
      value - the value to be added
    • remove

      public void remove(String key)
      Removes the key-value pair associated with the given key from the FormData object.
      Parameters:
      key - the key to be removed
    • contains

      public boolean contains(String key)
      Checks if the FormData object contains a key-value pair with the given key.
      Parameters:
      key - the key to be checked
      Returns:
      true if the key is present, false otherwise
    • isEmpty

      public boolean isEmpty()
      Checks if the FormData object is empty.
      Returns:
      true if the FormData object is empty, false otherwise
    • size

      public int size()
      Retrieves the number of key-value pairs stored in the FormData object.
      Returns:
      the number of key-value pairs
    • clear

      public void clear()
      Removes all key-value pairs from the FormData object.
    • setFile

      public void setFile(String key, FormDataFile value)
      Adds a file to the FormData object.
      Parameters:
      key - the key to be added
      value - the file to be added
    • getFile

      public FormDataFile getFile(String key)
      Retrieves the file associated with the given key from the FormData object.
      Parameters:
      key - the key for which the file needs to be retrieved
      Returns:
      the file associated with the key, or null if the key is not present
    • getAllFiles

      public Map<String,FormDataFile> getAllFiles()
      Retrieves all the files stored in the FormData object.
      Returns:
      a map containing all the files
    • removeFile

      public void removeFile(String key)
      Removes the file associated with the given key from the FormData object.
      Parameters:
      key - the key to be removed
    • containsFile

      public boolean containsFile(String key)
      Checks if the FormData object contains a file with the given key.
      Parameters:
      key - the key to be checked
      Returns:
      true if the key is present, false otherwise
    • numOfFiles

      public int numOfFiles()
      Checks if the FormData object is empty.
      Returns:
      true if the FormData object is empty, false otherwise