Class FormBody<T>
java.lang.Object
de.craftsblock.craftsnet.api.http.body.Body
de.craftsblock.craftsnet.api.http.body.bodies.FormBody<T>
- Type Parameters:
T- The type of data that each field in the form body holds.
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
MultipartFormBody,StandardFormBody
The
FormBody class is an abstract base class for representing HTTP request bodies that
contain form data. It provides common functionality for handling form data, such as deserialization
and field retrieval.- Since:
- 2.2.0-SNAPSHOT
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final InputStreamprotected final ConcurrentHashMap<String,T> -
Constructor Summary
ConstructorsConstructorDescriptionFormBody(Request request, InputStream body) Constructs a newFormBodywith the given input stream and deserializes the form data if it is of the standard form body type. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Clears the internal data map when the form body is closed.protected abstract voidThis method should be implemented by concrete subclasses to handle the deserialization of form data from the input stream and populate the internal data map.final InputStreamgetBody()Returns the raw input stream containing the form data.final ConcurrentHashMap<String,T> getData()Returns the concurrent hash map containing the form fields and their values.abstract TRetrieves the value of a specific field from the form data.abstract booleanChecks if a specific field exists in the form data.Methods inherited from class de.craftsblock.craftsnet.api.http.body.Body
cleanUp, getAsJsonBody, getAsMultipartFormBody, getAsStandardFormBody, getAsType, getBodies, getBodyTypes, getRawContentType, isBodyFromType, isClosed, isJsonBody, isMultipartFormBody, isStandardFormBody
-
Field Details
-
body
-
data
-
-
Constructor Details
-
FormBody
Constructs a newFormBodywith the given input stream and deserializes the form data if it is of the standard form body type.- Parameters:
request- The representation of the http request.body- The input stream containing the form data.- Throws:
IOException- If an error occurs while reading or parsing the form data.
-
-
Method Details
-
deserialize
This method should be implemented by concrete subclasses to handle the deserialization of form data from the input stream and populate the internal data map.- Throws:
IOException- If an error occurs while reading or parsing the form data.
-
close
public void close()Clears the internal data map when the form body is closed. This is important to release resources and ensure that the form body is in a clean state after processing.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classBody
-
hasField
Checks if a specific field exists in the form data.- Parameters:
name- The name of the field to check.- Returns:
trueif the field exists, otherwisefalse.
-
getField
Retrieves the value of a specific field from the form data.- Parameters:
name- The name of the field to retrieve.- Returns:
- The value of the field, or
nullif the field does not exist.
-
getBody
Returns the raw input stream containing the form data.- Returns:
- The input stream.
-
getData
Returns the concurrent hash map containing the form fields and their values.- Returns:
- The data map.
-