Class MimeType

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

    public class MimeType
    extends java.lang.Object
    implements java.lang.Comparable<MimeType>, java.io.Serializable
    Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in other Internet protocols including HTTP.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String WILDCARD_TYPE  
    • Constructor Summary

      Constructors 
      Constructor Description
      MimeType​(MimeType other, java.util.Map<java.lang.String,​java.lang.String> parameters)
      Copy-constructor that copies the type and subtype of the given MimeType, and allows for different parameter.
      MimeType​(java.lang.String type)
      Create a new MimeType for the given primary type.
      MimeType​(java.lang.String type, java.lang.String subtype)
      Create a new MimeType for the given primary type and subtype.
      MimeType​(java.lang.String type, java.lang.String subtype, java.nio.charset.Charset charSet)
      Create a new MimeType for the given type, subtype, and character set.
      MimeType​(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,​java.lang.String> parameters)
      Create a new MimeType for the given type, subtype, and parameters.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void appendTo​(java.lang.StringBuilder builder)  
      protected void checkParameters​(java.lang.String attribute, java.lang.String value)  
      int compareTo​(MimeType other)
      Compares this MediaType to another alphabetically.
      boolean equals​(java.lang.Object other)  
      java.nio.charset.Charset getCharSet()
      Return the character set, as indicated by a charset parameter, if any.
      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()
      Return all generic parameter values.
      java.lang.String getSubtype()
      Return the subtype.
      java.lang.String getType()
      Return the primary type.
      int hashCode()  
      boolean includes​(MimeType other)
      Indicate whether this MediaType includes the given media type.
      boolean isCompatibleWith​(MimeType other)
      Indicate whether this MediaType is compatible with the given media type.
      boolean isConcrete()
      Indicates whether this media type is concrete, i.e.
      boolean isWildcardSubtype()
      Indicates whether the subtype is the wildcard character * or the wildcard character followed by a suffix (e.g.
      boolean isWildcardType()
      Indicates whether the type is the wildcard character * or not.
      static MimeType parseMimeType​(java.lang.String mimeType)
      Parse the given String into a single MimeType.
      java.lang.String toString()  
      protected java.lang.String unquote​(java.lang.String s)  
      static MimeType valueOf​(java.lang.String value)
      Parse the given String value into a MimeType object, with this method name following the 'valueOf' naming convention (as supported by org.springframework.core.convert.ConversionService}.
      • Methods inherited from class java.lang.Object

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

    • Constructor Detail

      • MimeType

        public MimeType​(java.lang.String type)
        Create a new MimeType for the given primary type.

        The subtype is set to "*", and the parameters are empty.

        Parameters:
        type - the primary type
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters contains illegal characters
      • MimeType

        public MimeType​(java.lang.String type,
                        java.lang.String subtype)
        Create a new MimeType for the given primary type and subtype.

        The parameters are empty.

        Parameters:
        type - the primary type
        subtype - the subtype
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters contains illegal characters
      • MimeType

        public MimeType​(java.lang.String type,
                        java.lang.String subtype,
                        java.nio.charset.Charset charSet)
        Create a new MimeType for the given type, subtype, and character set.
        Parameters:
        type - the primary type
        subtype - the subtype
        charSet - the character set
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters contains illegal characters
      • MimeType

        public MimeType​(MimeType other,
                        java.util.Map<java.lang.String,​java.lang.String> parameters)
        Copy-constructor that copies the type and subtype of the given MimeType, and allows for different parameter.
        Parameters:
        other - the other media type
        parameters - the parameters, may be null
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters contains illegal characters
      • MimeType

        public MimeType​(java.lang.String type,
                        java.lang.String subtype,
                        java.util.Map<java.lang.String,​java.lang.String> parameters)
        Create a new MimeType 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 parameters contains illegal characters
    • Method Detail

      • checkParameters

        protected void checkParameters​(java.lang.String attribute,
                                       java.lang.String value)
      • unquote

        protected java.lang.String unquote​(java.lang.String s)
      • isWildcardType

        public boolean isWildcardType()
        Indicates whether the type is the wildcard character * or not.
      • 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
      • isConcrete

        public boolean isConcrete()
        Indicates whether this media type is concrete, i.e. whether neither the type nor the subtype is a wildcard character *.
        Returns:
        whether this media type is concrete
      • getType

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

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

        public java.nio.charset.Charset getCharSet()
        Return the character set, as indicated by a charset parameter, if any.
        Returns:
        the character set, or null if not available
      • 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()
        Return all generic parameter values.
        Returns:
        a read-only map (possibly empty, never null)
      • includes

        public boolean includes​(MimeType other)
        Indicate whether this MediaType includes the given media type.

        For instance, text/* includes text/plain and text/html, and application/*+xml includes application/soap+xml, etc. This method is not symmetric.

        Parameters:
        other - the reference media type with which to compare
        Returns:
        true if this media type includes the given media type; false otherwise
      • isCompatibleWith

        public boolean isCompatibleWith​(MimeType other)
        Indicate whether this MediaType is compatible with the given media type.

        For instance, text/* is compatible with text/plain, text/html, and vice versa. In effect, this method is similar to includes(com.jalios.util.MimeType), except that it is symmetric.

        Parameters:
        other - the reference media type with which to compare
        Returns:
        true if this media type is compatible with the given media type; false otherwise
      • compareTo

        public int compareTo​(MimeType other)
        Compares this MediaType to another alphabetically.
        Specified by:
        compareTo in interface java.lang.Comparable<MimeType>
        Parameters:
        other - media type to compare to
      • equals

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

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

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

        protected void appendTo​(java.lang.StringBuilder builder)
      • valueOf

        public static MimeType valueOf​(java.lang.String value)
        Parse the given String value into a MimeType object, with this method name following the 'valueOf' naming convention (as supported by org.springframework.core.convert.ConversionService}.
      • parseMimeType

        public static MimeType parseMimeType​(java.lang.String mimeType)
        Parse the given String into a single MimeType.
        Parameters:
        mimeType - the string to parse
        Returns:
        the mime type