Class MediaType

    • Constructor Summary

      Constructors 
      Constructor Description
      MediaType​(java.lang.String type, java.lang.String subtype)
      Create a new MediaType for the given primary type and subtype, with empty parameters.
      MediaType​(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,​java.lang.String> parameters)
      Create a new MediaType for the given type, subtype, and parameters.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<java.nio.charset.Charset> getCharset()
      Return the character set, as indicated by a charset parameter, if available.
      java.lang.String getParameter​(java.lang.String name)
      Return a generic parameter value, given a parameter name.
      java.util.Map<java.lang.String,​java.lang.String> getParameters()
      Returns all media type parameters in a read-only Map
      double getQualityValue()
      Return the quality factor, as indicated by a q parameter, if any.
      java.lang.String getSubtype()
      Return the subtype.
      java.lang.String getType()
      Return the primary type.
      boolean includes​(MediaType other)
      Indicate whether this MediaType includes the given media type.
      boolean isWildcardSubtype()
      Indicates whether the subtype is the wildcard character * or the wildcard character followed by a suffix (e.g.
      static MediaType parseMediaType​(java.lang.String mediaType)  
      static java.util.List<MediaType> parseMediaTypes​(java.lang.String... mediaTypes)  
      java.lang.String toString()  
      static java.lang.String toString​(java.util.Collection<MediaType> mediaTypes)
      Return a string representation of the given list of MediaType objects, to be used in an Accept or Content-Type header.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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
    • Constructor Detail

      • MediaType

        public MediaType​(java.lang.String type,
                         java.lang.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:
        java.lang.IllegalArgumentException - if any of the arguments contain illegal characters
      • MediaType

        public MediaType​(java.lang.String type,
                         java.lang.String subtype,
                         java.util.Map<java.lang.String,​java.lang.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:
        java.lang.IllegalArgumentException - if any of the arguments contain illegal characters
    • Method Detail

      • getType

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

        public java.lang.String getSubtype()
        Return the subtype.
      • getCharset

        public java.util.Optional<java.nio.charset.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 java.lang.String getParameter​(java.lang.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 java.util.Map<java.lang.String,​java.lang.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​(java.lang.String mediaType)
      • parseMediaTypes

        public static java.util.List<MediaType> parseMediaTypes​(java.lang.String... mediaTypes)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public static java.lang.String toString​(java.util.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