Interface HttpMediaType

All Superinterfaces:
Comparable<HttpMediaType>, MediaType, Predicate<HttpMediaType>

public sealed interface HttpMediaType extends Predicate<HttpMediaType>, Comparable<HttpMediaType>, MediaType
Media type used in HTTP headers, in addition to the media type definition, these may contain additional parameters, such as QUALITY_FACTOR_PARAMETER and CHARSET_PARAMETER.
See Also:
  • Field Details

    • CHARSET_PARAMETER

      static final String CHARSET_PARAMETER
      The media type "charset" parameter name.
      See Also:
    • QUALITY_FACTOR_PARAMETER

      static final String QUALITY_FACTOR_PARAMETER
      The media type quality factor "q" parameter name.
      See Also:
  • Method Details

    • builder

      static HttpMediaType.Builder builder()
      A fluent API builder for creating customized Media type instances.
      Returns:
      a new builder
    • create

      static HttpMediaType create(MediaType mediaType)
      Create a new HTTP media type from media type.
      Parameters:
      mediaType - media type
      Returns:
      a new HTTP media type without any parameters
    • create

      static HttpMediaType create(String mediaTypeString)
      Parse media type from the provided string. Strict media type parsing mode is used.
      Parameters:
      mediaTypeString - media type string
      Returns:
      HTTP media type parsed from the string
    • create

      static HttpMediaType create(String mediaTypeString, ParserMode parserMode)
      Parse media type from the provided string.
      Parameters:
      mediaTypeString - media type string
      parserMode - media type parsing mode
      Returns:
      HTTP media type parsed from the string
    • mediaType

      MediaType mediaType()
      The underlying media type.
      Returns:
      media type
    • qualityFactor

      double qualityFactor()
      Quality factor, if not defined, defaults to 1.
      Returns:
      quality factor
    • parameters

      Map<String,String> parameters()
      Read-only parameter map. Keys are case-insensitive.
      Returns:
      an immutable map of parameters.
    • charset

      default Optional<String> charset()
      Gets Optional value of charset parameter.
      Returns:
      Charset parameter.
    • test

      boolean test(HttpMediaType other)
      Check if this media type is compatible with another media type. E.g. image/* is compatible with image/jpeg, image/png, etc. Media type parameters are ignored. The function is commutative.
      Specified by:
      test in interface Predicate<HttpMediaType>
      Parameters:
      other - the media type to compare with.
      Returns:
      true if the types are compatible, false otherwise.
    • test

      boolean test(MediaType mediaType)
      Check if this media type is compatible with another media type. E.g. image/* is compatible with image/jpeg, image/png, etc. Media type parameters are ignored. The function is commutative.
      Parameters:
      mediaType - the media type to compare with.
      Returns:
      true if the types are compatible, false otherwise.
    • type

      default String type()
      Description copied from interface: MediaType
      Type, such as application.
      Specified by:
      type in interface MediaType
      Returns:
      type part of the media type
    • subtype

      default String subtype()
      Description copied from interface: MediaType
      Subtype, such as yaml.
      Specified by:
      subtype in interface MediaType
      Returns:
      subtype part of the media type
    • withCharset

      default HttpMediaType withCharset(String charset)
      Create a new HttpMediaType instance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.
      Parameters:
      charset - the "charset" parameter value. If null or empty the "charset" parameter will not be set or updated.
      Returns:
      copy of the current MediaType instance with the "charset" parameter set to the supplied value.
    • withCharset

      default HttpMediaType withCharset(Charset charset)
      Create a new HttpMediaType instance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.
      Parameters:
      charset - the "charset" parameter value
      Returns:
      copy of the current MediaType instance with the "charset" parameter set to the supplied value.
    • text

      String text()
      Text of this media type, to be used on the wire.
      Specified by:
      text in interface MediaType
      Returns:
      text including all parameters
    • withParameter

      default HttpMediaType withParameter(String name, String value)
      Create a new HttpMediaType instance with the same type, subtype and parameters copied from the original instance and the supplied custom parameter.
      Parameters:
      name - name of the parameter
      value - value of the parameter
      Returns:
      copy of the current MediaType instance with the "charset" parameter set to the supplied value.