Class BodyParser<T extends Body>

java.lang.Object
de.craftsblock.craftsnet.api.http.body.BodyParser<T>
Type Parameters:
T - The type of body that this parser can parse.
Direct Known Subclasses:
MultipartFormBodyParser, StandardFormBodyParser, TypedBodyParser

public abstract class BodyParser<T extends Body> extends Object
This abstract class represents a parser for HTTP request or response bodies. It provides methods to parse a body from an input stream and to check if a specific content type is parseable.
Since:
3.0.4-SNAPSHOT
See Also:
  • Constructor Details

    • BodyParser

      public BodyParser(String contentType, String... contentTypes)
      Constructs a new BodyParser with the given content types.
      Parameters:
      contentType - The primary content type supported by this parser.
      contentTypes - Additional content types supported by this parser.
  • Method Details

    • parse

      @Nullable public abstract T parse(Request request, InputStream body)
      Parses the body from the provided input stream.
      Parameters:
      request - The HTTP request associated with the body.
      body - The input stream containing the body data.
      Returns:
      The parsed body object, or null if parsing fails.
    • contentTypes

      public final @Unmodifiable List<String> contentTypes()
      Returns an unmodifiable list of supported content types as patterns.
      Returns:
      The list of supported content types as patterns.
    • isParseable

      public boolean isParseable(String contentType)
      Checks if this parser can parse the given content type.
      Parameters:
      contentType - The content type to check.
      Returns:
      true if the parser supports the given content type, false otherwise.