Record Class MultipartBody.MultipartPart

java.lang.Object
java.lang.Record
org.apache.juneau.http.entity.MultipartBody.MultipartPart
Enclosing class:
MultipartBody

public static record MultipartBody.MultipartPart(String name, String filename, String contentType, HttpBody body) extends Record
A single part within a MultipartBody.
Since:
9.2.1
  • Constructor Details

    • MultipartPart

      public MultipartPart(String name, String filename, String contentType, HttpBody body)
      Compact constructor enforcing the documented non-null contract on name and body, and rejecting CR/LF and other control characters in name, filename, and contentType that could otherwise inject an extra MIME header line into the multipart wire format.
  • Method Details

    • field

      public static MultipartBody.MultipartPart field(String name, String value)
      Creates a text field part with no filename and text/plain; charset=UTF-8 content type.
      Parameters:
      name - The field name. Must not be null.
      value - The string value. Must not be null.
      Returns:
      A new instance. Never null.
    • file

      public static MultipartBody.MultipartPart file(String name, File file, String contentType)
      Creates a file upload part.
      Parameters:
      name - The field name. Must not be null.
      file - The file to upload. Must not be null. Its File.getName() is validated like any other filename — a hostile name containing CR/LF or other control characters is rejected.
      contentType - The MIME content type for the file (e.g. "application/pdf"). May be null.
      Returns:
      A new instance. Never null.
    • of

      public static MultipartBody.MultipartPart of(String name, String filename, String contentType, HttpBody body)
      Creates a part from an arbitrary HttpBody.
      Parameters:
      name - The field name. Must not be null.
      filename - The filename to advertise in Content-Disposition. May be null.
      contentType - The MIME content type. May be null.
      body - The body content. Must not be null.
      Returns:
      A new instance. Never null.
    • 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.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • filename

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

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

      public HttpBody body()
      Returns the value of the body record component.
      Returns:
      the value of the body record component