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
ConstructorsConstructorDescriptionMultipartItem(List<byte[]> data, String contentType) Creates an instance of aMultipartItemrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thecontentTyperecord component.List<byte[]>data()Returns the value of thedatarecord component.final booleanIndicates whether some other object is "equal to" this one.Converts the multipart data to a file.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 inthashCode()Returns a hash code value for this object.booleanisFile()Checks if the multipart item represents a file.final StringtoString()Returns a string representation of this record class.booleanValidates the content type of the multipart item by comparing it to the actual data.
-
Constructor Details
-
MultipartItem
Creates an instance of aMultipartItemrecord class.- Parameters:
data- the value for thedatarecord componentcontentType- the value for thecontentTyperecord component
-
-
Method Details
-
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:
trueif it's a file, otherwisefalse.
-
getFileExtension
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
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
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
Validates the content type of the multipart item by comparing it to the actual data.- Returns:
trueif the content type matches the data, otherwisefalse.- Throws:
org.apache.tika.mime.MimeTypeException- If the content type is not recognized.IOException- If an error occurs while reading the file.Exception
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
data
Returns the value of thedatarecord component.- Returns:
- the value of the
datarecord component
-
contentType
Returns the value of thecontentTyperecord component.- Returns:
- the value of the
contentTyperecord component
-