Class Body
java.lang.Object
de.craftsblock.craftsnet.api.http.body.Body
- All Implemented Interfaces:
AutoCloseable
The abstract class
Body is the base class for all types of HTTP request bodies
supported by CraftsNet.
An HTTP request body contains data that is sent to the server when making an HTTP request. This abstract class serves to provide common properties and methods for different types of request bodies.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCloses all bodies corresponding to a specific request.voidclose()Closes the request body.final JsonBodyReturns this object as aJsonBodyif the body is a json object.final MultipartFormBodyReturns this object as aMultipartFormBodyif the body is a multipart form body.final StandardFormBodyReturns this object as aStandardFormBodyif the body is a standard form body.final <T extends Body>
TReturns this object as a specific type of request body if the body is an instance of the specific request body.final ConcurrentHashMap<Class<? extends Body>,Body> Returns anConcurrentHashMapcontaining all parsed bodies for the underlying request.Returns a set containing all the valid types this body was parsed for.final StringReturns this content type of the underlying request.final booleanisBodyFromType(Class<? extends Body> type) Checks if this request body is a specific type of request body.final booleanisClosed()Checks if this request body is already closed.final booleanChecks if this request body is a JSON request body.final booleanChecks if this request body is a multipart form request body.final booleanChecks if this request body is a standard form request body.
-
Constructor Details
-
Body
Constructs a new instance of a request body.- Parameters:
request- The representation of the http request.
-
-
Method Details
-
getRawContentType
Returns this content type of the underlying request.
Important: This method does not return the exact content type of the inputted data! It relies on the request to retrieve the estimated content type.- Returns:
- The content type retrieved by the request.
- Since:
- 3.0.4-SNAPSHOT
-
close
public void close()Closes the request body.- Specified by:
closein interfaceAutoCloseable
-
isClosed
public final boolean isClosed()Checks if this request body is already closed.- Returns:
trueif it is closed, otherwisefalse.
-
isJsonBody
public final boolean isJsonBody()Checks if this request body is a JSON request body.- Returns:
trueif it is a JSON request body, otherwisefalse.
-
getAsJsonBody
Returns this object as aJsonBodyif the body is a json object.- Returns:
- This object as a
JsonBodyif the body is a json object otherwise, null.
-
isStandardFormBody
public final boolean isStandardFormBody()Checks if this request body is a standard form request body.- Returns:
trueif it is a standard form request body, otherwisefalse.
-
getAsStandardFormBody
Returns this object as aStandardFormBodyif the body is a standard form body.- Returns:
- This object as a
StandardFormBodyif the body is a standard form body otherwise, null.
-
isMultipartFormBody
public final boolean isMultipartFormBody()Checks if this request body is a multipart form request body.- Returns:
trueif it is a multipart form request body, otherwisefalse.
-
getAsMultipartFormBody
Returns this object as aMultipartFormBodyif the body is a multipart form body.- Returns:
- This object as a
MultipartFormBodyif the body is a multipart form body otherwise, null.
-
isBodyFromType
Checks if this request body is a specific type of request body.Important: As it is only a preview it may change in a future release.
- Parameters:
type- The type which should be checked.- Returns:
- true if the type is the type of the current request body, false otherwise.
-
getAsType
Returns this object as a specific type of request body if the body is an instance of the specific request body.Important: As it is only a preview it may change in a future release.
- Type Parameters:
T- The type of the request body.- Parameters:
type- The type which the current request body should be cast to.- Returns:
- The object after casting, or null if the current request body is not an instance of the type.
-
getBodyTypes
Returns a set containing all the valid types this body was parsed for.Important: As it is only a preview it may change in a future release.
- Returns:
- The set containing all body types as classes.
-
getBodies
Returns anConcurrentHashMapcontaining all parsed bodies for the underlying request. The key is the type of the body as it's class representation.Important: As it is only a preview it may change in a future release.
- Returns:
- The
ConcurrentHashMapcontaining all parsed bodies.
-
cleanUp
Closes all bodies corresponding to a specific request.Important: As it is only a preview it may change in a future release.
- Parameters:
request- The request which should be cleaned.
-