Class MediaType


  • public final class MediaType
    extends Object
    Represents a media type as defined by RFC 2045 and RFC 2046. It specifies a primary type (e.g. text) and a subtype (e.g. xml). Note that in RFC 2045, "media type" refers to what is called "primary type" here, while this class uses "media type" to refer to the combination of primary and subtype.

    This class is immutable. It overrides Object.equals(Object) and Object.hashCode() to allow comparing media types as described by RFC 2045, i.e. in a case insensitive way.

    • Field Detail

      • TEXT_XML

        public static final MediaType TEXT_XML
        The media type for text/xml.
      • APPLICATION_XML

        public static final MediaType APPLICATION_XML
        The media type for application/xml.
      • APPLICATION_SOAP_XML

        public static final MediaType APPLICATION_SOAP_XML
        The media type for application/soap+xml.
      • APPLICATION_XOP_XML

        public static final MediaType APPLICATION_XOP_XML
        The media type for application/xop+xml.
      • MULTIPART_RELATED

        public static final MediaType MULTIPART_RELATED
        The media type for multipart/related.
      • APPLICATION_OCTET_STREAM

        public static final MediaType APPLICATION_OCTET_STREAM
        The media type for application/octet-stream.
      • TEXT_PLAIN

        public static final MediaType TEXT_PLAIN
        The media type for text/plain.
    • Constructor Detail

      • MediaType

        public MediaType​(String primaryType,
                         String subType)
        Constructor.
        Parameters:
        primaryType - the primary type
        subType - the subtype
      • MediaType

        public MediaType​(String type)
                  throws ParseException
        Constructor that parses a media type.
        Parameters:
        type - the media type to parse
        Throws:
        ParseException - if the value is invalid and could not be parsed
    • Method Detail

      • getPrimaryType

        public String getPrimaryType()
        Get the primary type.
        Returns:
        the primary type
      • getSubType

        public String getSubType()
        Get the subtype.
        Returns:
        the subtype
      • hasPrimaryType

        public boolean hasPrimaryType​(String type)
        Check if this media type has the given primary type.
        Parameters:
        type - the primary type to check against
        Returns:
        whether the primary type matches
      • hasSubType

        public boolean hasSubType​(String type)
        Check if this media type has the given sub type.
        Parameters:
        type - the sub type to check against
        Returns:
        whether the sub type matches
      • isXML

        public boolean isXML()
        Check if this media type describes XML content as defined in RFC 7303.
        Returns:
        whether the content expected for this media type is XML
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object