Class MediaType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<MediaType>

    public final class MediaType
    extends java.lang.Object
    implements java.lang.Comparable<MediaType>, java.io.Serializable
    Internet media type.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      MediaType​(java.lang.String type, java.lang.String subtype)  
      MediaType​(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,​java.lang.String> parameters)  
      MediaType​(MediaType type, java.lang.String name, java.lang.String value)
      Creates a media type by adding a parameter to a base type.
      MediaType​(MediaType type, java.nio.charset.Charset charset)
      Creates a media type by adding the "charset" parameter to a base type.
      MediaType​(MediaType type, java.util.Map<java.lang.String,​java.lang.String> parameters)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static MediaType application​(java.lang.String type)  
      static MediaType audio​(java.lang.String type)  
      int compareTo​(MediaType that)  
      boolean equals​(java.lang.Object object)  
      MediaType getBaseType()
      Returns the base form of the MediaType, excluding any parameters, such as "text/plain" for "text/plain; charset=utf-8"
      java.util.Map<java.lang.String,​java.lang.String> getParameters()
      Returns an immutable sorted map of the parameters of this media type.
      java.lang.String getSubtype()
      Return the Sub-Type of the MediaType, such as "plain" for "text/plain"
      java.lang.String getType()
      Return the Type of the MediaType, such as "text" for "text/plain"
      int hashCode()  
      boolean hasParameters()
      Checks whether this media type contains parameters.
      static MediaType image​(java.lang.String type)  
      static MediaType parse​(java.lang.String string)
      Parses the given string to a media type.
      static java.util.Set<MediaType> set​(java.lang.String... types)
      Convenience method that parses the given media type strings and returns an unmodifiable set that contains all the parsed types.
      static java.util.Set<MediaType> set​(MediaType... types)
      Convenience method that returns an unmodifiable set that contains all the given media types.
      static MediaType text​(java.lang.String type)  
      java.lang.String toString()  
      static MediaType video​(java.lang.String type)  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • OCTET_STREAM

        public static final MediaType OCTET_STREAM
      • TEXT_PLAIN

        public static final MediaType TEXT_PLAIN
      • TEXT_HTML

        public static final MediaType TEXT_HTML
      • APPLICATION_XML

        public static final MediaType APPLICATION_XML
      • APPLICATION_ZIP

        public static final MediaType APPLICATION_ZIP
    • Constructor Detail

      • MediaType

        public MediaType​(java.lang.String type,
                         java.lang.String subtype,
                         java.util.Map<java.lang.String,​java.lang.String> parameters)
      • MediaType

        public MediaType​(java.lang.String type,
                         java.lang.String subtype)
      • MediaType

        public MediaType​(MediaType type,
                         java.util.Map<java.lang.String,​java.lang.String> parameters)
      • MediaType

        public MediaType​(MediaType type,
                         java.lang.String name,
                         java.lang.String value)
        Creates a media type by adding a parameter to a base type.
        Parameters:
        type - base type
        name - parameter name
        value - parameter value
        Since:
        Apache Tika 1.2
      • MediaType

        public MediaType​(MediaType type,
                         java.nio.charset.Charset charset)
        Creates a media type by adding the "charset" parameter to a base type.
        Parameters:
        type - base type
        charset - charset value
        Since:
        Apache Tika 1.2
    • Method Detail

      • application

        public static MediaType application​(java.lang.String type)
      • audio

        public static MediaType audio​(java.lang.String type)
      • image

        public static MediaType image​(java.lang.String type)
      • text

        public static MediaType text​(java.lang.String type)
      • video

        public static MediaType video​(java.lang.String type)
      • set

        public static java.util.Set<MediaType> set​(MediaType... types)
        Convenience method that returns an unmodifiable set that contains all the given media types.
        Parameters:
        types - media types
        Returns:
        unmodifiable set of the given types
        Since:
        Apache Tika 1.2
      • set

        public static java.util.Set<MediaType> set​(java.lang.String... types)
        Convenience method that parses the given media type strings and returns an unmodifiable set that contains all the parsed types.
        Parameters:
        types - media type strings
        Returns:
        unmodifiable set of the parsed types
        Since:
        Apache Tika 1.2
      • parse

        public static MediaType parse​(java.lang.String string)
        Parses the given string to a media type. The string is expected to be of the form "type/subtype(; parameter=...)*" as defined in RFC 2045, though we also handle "charset=xxx; type/subtype" for broken web servers.
        Parameters:
        string - media type string to be parsed
        Returns:
        parsed media type, or null if parsing fails
      • getBaseType

        public MediaType getBaseType()
        Returns the base form of the MediaType, excluding any parameters, such as "text/plain" for "text/plain; charset=utf-8"
      • getType

        public java.lang.String getType()
        Return the Type of the MediaType, such as "text" for "text/plain"
      • getSubtype

        public java.lang.String getSubtype()
        Return the Sub-Type of the MediaType, such as "plain" for "text/plain"
      • hasParameters

        public boolean hasParameters()
        Checks whether this media type contains parameters.
        Returns:
        true if this type has one or more parameters, false otherwise
        Since:
        Apache Tika 0.8
      • getParameters

        public java.util.Map<java.lang.String,​java.lang.String> getParameters()
        Returns an immutable sorted map of the parameters of this media type. The parameter names are guaranteed to be trimmed and in lower case.
        Returns:
        sorted map of parameters
      • toString

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

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(MediaType that)
        Specified by:
        compareTo in interface java.lang.Comparable<MediaType>