Class MultipartFormBody
java.lang.Object
de.craftsblock.craftsnet.api.http.body.Body
de.craftsblock.craftsnet.api.http.body.bodies.FormBody<MultipartFormBody.MultipartData>
de.craftsblock.craftsnet.api.http.body.bodies.MultipartFormBody
- All Implemented Interfaces:
AutoCloseable
The
MultipartFormBody class represents an HTTP request body that contains data in the
multipart/form-data format. This format is often used to upload files and form fields in HTTP
requests.- Since:
- 2.2.0-SNAPSHOT
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordTheMultipartDataclass represents the multipart data for a single field in the multipart/form-data.static final recordTheMultipartItemclass represents an individual part of the multipart data, which can be a file or a form field. -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionMultipartFormBody(Request request, String boundary, InputStream body) Constructs a newMultipartFormBodyby specifying the boundary and providing an input stream containing the multipart/form-data. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDeserializes the multipart form body, parsing it into individual parts and storing them in the data map.Gets the boundary string used to separate parts in the multipart request.Retrieves the multipart data for a specific field.booleanChecks if a specific field exists in the multipart data.Methods inherited from class de.craftsblock.craftsnet.api.http.body.bodies.FormBody
close, getBody, getDataMethods inherited from class de.craftsblock.craftsnet.api.http.body.Body
cleanUp, getAsJsonBody, getAsMultipartFormBody, getAsStandardFormBody, getAsType, getBodies, getBodyTypes, getRawContentType, isBodyFromType, isClosed, isJsonBody, isMultipartFormBody, isStandardFormBody
-
Constructor Details
-
MultipartFormBody
Constructs a newMultipartFormBodyby specifying the boundary and providing an input stream containing the multipart/form-data.- Parameters:
request- The representation of the http request.boundary- The boundary string that separates parts in the multipart request.body- The input stream containing the multipart/form-data.- Throws:
IOException- If an error occurs while reading or parsing the multipart data.
-
-
Method Details
-
deserialize
Deserializes the multipart form body, parsing it into individual parts and storing them in the data map. This method reads the input stream and processes multipart form data, which consists of multiple parts separated by a boundary. It extracts the name, content type, and data of each part and stores them in the data map.- Specified by:
deserializein classFormBody<MultipartFormBody.MultipartData>- Throws:
IOException- If an I/O error occurs while reading the input stream.
-
hasField
Checks if a specific field exists in the multipart data.- Specified by:
hasFieldin classFormBody<MultipartFormBody.MultipartData>- Parameters:
name- The name of the field to check.- Returns:
trueif the field exists, otherwisefalse.
-
getField
Retrieves the multipart data for a specific field.- Specified by:
getFieldin classFormBody<MultipartFormBody.MultipartData>- Parameters:
name- The name of the field to retrieve.- Returns:
- The multipart data for the field, or
nullif the field does not exist.
-
getBoundary
Gets the boundary string used to separate parts in the multipart request.- Returns:
- The boundary string.
-