Class MediaType

java.lang.Object
com.contentgrid.opa.client.rest.http.MediaType

public class MediaType extends Object
Represents a RFC 2046 Media Type. A media type consists of type/subtype and MAY be followed by parameters in the form of name=value{code} paris.
See Also:
  • Field Details

    • APPLICATION_JSON

      public static final MediaType APPLICATION_JSON
    • APPLICATION_OCTET_STREAM

      public static final MediaType APPLICATION_OCTET_STREAM
    • TEXT_ALL

      public static final MediaType TEXT_ALL
    • TEXT_PLAIN

      public static final MediaType TEXT_PLAIN
    • WILDCARD

      protected static final String WILDCARD
      See Also:
  • Constructor Details

    • MediaType

      public MediaType(String type, String subtype)
      Create a new MediaType for the given primary type and subtype, with empty parameters.
      Parameters:
      type - the primary type
      subtype - the subtype
      Throws:
      IllegalArgumentException - if any of the arguments contain illegal characters
    • MediaType

      public MediaType(String type, String subtype, Map<String,String> parameters)
      Create a new MediaType for the given type, subtype, and parameters.
      Parameters:
      type - the primary type
      subtype - the subtype
      parameters - the parameters, may be null
      Throws:
      IllegalArgumentException - if any of the arguments contain illegal characters
  • Method Details

    • getType

      public String getType()
      Return the primary type.
    • getSubtype

      public String getSubtype()
      Return the subtype.
    • getCharset

      public Optional<Charset> getCharset()
      Return the character set, as indicated by a charset parameter, if available.
      Returns:
      the character set wrapped in an Optional, or Optional.empty() if not available
    • isWildcardSubtype

      public boolean isWildcardSubtype()
      Indicates whether the subtype is the wildcard character * or the wildcard character followed by a suffix (e.g. *+xml).
      Returns:
      whether the subtype is a wildcard
    • getParameter

      public String getParameter(String name)
      Return a generic parameter value, given a parameter name.
      Parameters:
      name - the parameter name
      Returns:
      the parameter value, or null if not present
    • getParameters

      public Map<String,String> getParameters()
      Returns all media type parameters in a read-only Map
      Returns:
      an immutable map with all parameters, never null
    • getQualityValue

      public double getQualityValue()
      Return the quality factor, as indicated by a q parameter, if any. Defaults to 1.0.
      Returns:
      the quality factor as double value
    • includes

      public boolean includes(MediaType other)
      Indicate whether this MediaType includes the given media type. For example, text/* should includes text/plain and text/html, and application/*+xml includes application/soap+xml.
      Parameters:
      other - the reference media type with which to compare
      Returns:
      true if this media type includes the given media type; false otherwise
    • parseMediaType

      public static MediaType parseMediaType(String mediaType)
    • parseMediaTypes

      public static List<MediaType> parseMediaTypes(String... mediaTypes)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public static String toString(Collection<MediaType> mediaTypes)
      Return a string representation of the given list of MediaType objects, to be used in an Accept or Content-Type header.
      Parameters:
      mediaTypes - the media types to create a string representation for
      Returns:
      the string representation