Record Class MultipartFormBody.MultipartItem

java.lang.Object
java.lang.Record
de.craftsblock.craftsnet.api.http.body.bodies.MultipartFormBody.MultipartItem
Enclosing class:
MultipartFormBody

public static record MultipartFormBody.MultipartItem(List<byte[]> data, String contentType) extends Record
The MultipartItem class represents an individual part of the multipart data, which can be a file or a form field.
Since:
2.2.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    MultipartItem(List<byte[]> data, String contentType)
    Creates an instance of a MultipartItem record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the contentType record component.
    List<byte[]>
    Returns the value of the data record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Converts the multipart data to a file.
    getAsFile(String extension)
    Converts the multipart data to a file with a specified extension.
    Converts the multipart data to a string.
    Gets the file extension for the multipart item.
    final int
    Returns a hash code value for this object.
    boolean
    Checks if the multipart item represents a file.
    final String
    Returns a string representation of this record class.
    boolean
    Validates the content type of the multipart item by comparing it to the actual data.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MultipartItem

      public MultipartItem(List<byte[]> data, String contentType)
      Creates an instance of a MultipartItem record class.
      Parameters:
      data - the value for the data record component
      contentType - the value for the contentType record component
  • Method Details

    • getAsString

      public String getAsString()
      Converts the multipart data to a string.
      Returns:
      The multipart data as a string.
    • isFile

      public boolean isFile()
      Checks if the multipart item represents a file.
      Returns:
      true if it's a file, otherwise false.
    • getFileExtension

      public String getFileExtension() throws Exception
      Gets the file extension for the multipart item.
      Returns:
      The file extension.
      Throws:
      org.apache.tika.mime.MimeTypeException - If the content type is not recognized.
      Exception
    • getAsFile

      public File getAsFile() throws Exception
      Converts the multipart data to a file.
      Returns:
      The multipart data as a temporary file.
      Throws:
      org.apache.tika.mime.MimeTypeException - If the content type is not recognized.
      IOException - If an error occurs while creating the file or writing data to it.
      Exception
    • getAsFile

      public File getAsFile(String extension) throws Exception
      Converts the multipart data to a file with a specified extension.
      Parameters:
      extension - The file extension to use.
      Returns:
      The multipart data as a temporary file.
      Throws:
      IOException - If an error occurs while creating the file or writing data to it.
      org.apache.tika.mime.MimeTypeException - If the content type is not recognized.
      Exception
    • validateContentType

      public boolean validateContentType() throws Exception
      Validates the content type of the multipart item by comparing it to the actual data.
      Returns:
      true if the content type matches the data, otherwise false.
      Throws:
      org.apache.tika.mime.MimeTypeException - If the content type is not recognized.
      IOException - If an error occurs while reading the file.
      Exception
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • data

      public List<byte[]> data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component
    • contentType

      public String contentType()
      Returns the value of the contentType record component.
      Returns:
      the value of the contentType record component