Class MIMEType


  • public class MIMEType
    extends Object
    A Multipurpose Internet Mail Extension (MIME) type, as defined in RFC 2045 and 2046.

    This class is similar to e.g. java.awt.datatransfer.MimeType and org.apache.pivot.util.MIMEType. We reinvent the wheel here since there is no public MIME type class in core Java excluding AWT, which we could use cross-environment in e.g. Android.

    Author:
    Curtis Rueden
    • Constructor Detail

      • MIMEType

        public MIMEType​(String mimeType)
        Constructs a new MIME type object from the given MIME type string.
        Parameters:
        mimeType - The MIME type string, which may optionally include a list of semicolon-separated parameters.
      • MIMEType

        public MIMEType​(String mimeType,
                        Class<?> javaType)
        Constructs a new MIME type object from the given MIME type string.
        Parameters:
        mimeType - The MIME type string, which may optionally include a list of semicolon-separated parameters.
        javaType - The associated Java class of the MIME type. If non-null, a "class" parameter is guaranteed to exist with the MIME type indicating compatibility with the given Java class.
        Throws:
        IllegalArgumentException - if the mimeType includes a different Java class parameter than the javaType.
    • Method Detail

      • getBase

        public String getBase()
        Gets the MIME type with no parameter list.
      • getParameter

        public String getParameter​(String name)
        Gets the value of the parameter with the given name, or null if none.
      • getParameters

        public List<String> getParameters()
        Gets the parameter names associated with this MIME type.
      • isCompatible

        public boolean isCompatible​(MIMEType mimeType)
        Gets whether this MIME type is compatible with the given one. Being "compatible" means that the base types match, and that the given MIME type has the same parameters with the same values as this one does (although the given MIME type may also have additional parameters not present in this one).
      • isCompatible

        public boolean isCompatible​(Class<?> javaType)
        Gets whether this MIME type represents objects of the given Java class.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object