java.lang.Object
de.craftsblock.craftsnet.api.http.body.Body
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
FormBody, TypedBody

public abstract class Body extends Object implements 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.

Since:
2.2.0-SNAPSHOT
See Also:
  • Constructor Details

    • Body

      public Body(Request request)
      Constructs a new instance of a request body.
      Parameters:
      request - The representation of the http request.
  • Method Details

    • getRawContentType

      public final String 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:
      close in interface AutoCloseable
    • isClosed

      public final boolean isClosed()
      Checks if this request body is already closed.
      Returns:
      true if it is closed, otherwise false.
    • isJsonBody

      public final boolean isJsonBody()
      Checks if this request body is a JSON request body.
      Returns:
      true if it is a JSON request body, otherwise false.
    • getAsJsonBody

      public final JsonBody getAsJsonBody()
      Returns this object as a JsonBody if the body is a json object.
      Returns:
      This object as a JsonBody if 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:
      true if it is a standard form request body, otherwise false.
    • getAsStandardFormBody

      public final StandardFormBody getAsStandardFormBody()
      Returns this object as a StandardFormBody if the body is a standard form body.
      Returns:
      This object as a StandardFormBody if 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:
      true if it is a multipart form request body, otherwise false.
    • getAsMultipartFormBody

      public final MultipartFormBody getAsMultipartFormBody()
      Returns this object as a MultipartFormBody if the body is a multipart form body.
      Returns:
      This object as a MultipartFormBody if the body is a multipart form body otherwise, null.
    • isBodyFromType

      public final boolean isBodyFromType(Class<? extends Body> type)
      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

      @Nullable public final <T extends Body> T getAsType(Class<T> type)
      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

      public final Set<Class<? extends Body>> 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

      public final ConcurrentHashMap<Class<? extends Body>,Body> getBodies()
      Returns an ConcurrentHashMap containing 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 ConcurrentHashMap containing all parsed bodies.
    • cleanUp

      @Internal public static void cleanUp(Request request)
      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.