Module utilities

Class MimeType

java.lang.Object
de.grogra.util.MimeType
All Implemented Interfaces:
Serializable

public final class MimeType extends Object implements Serializable
This class implements a MIME type as specified by RFC 2045 and 2046. A MIME type consists of the specification of a top-level media type and a subtype, e.g., text/plain, and a (possibly empty) set of parameters. In the string representation of a MIME type, parameters are specified as the parameter charset in text/plain; charset=iso-8859-1.
Author:
Ole Kniemeyer
See Also:
  • Field Details

    • INVALID

      public static final MimeType INVALID
    • TEXT_PLAIN

      public static final MimeType TEXT_PLAIN
      The MIME type text/plain without parameters.
    • TEXT_XML

      public static final MimeType TEXT_XML
      The MIME type text/xml without parameters.
    • TEXT_HTML

      public static final MimeType TEXT_HTML
      The MIME type text/html without parameters.
    • APPLICATION_XML

      public static final MimeType APPLICATION_XML
      The MIME type application/xml without parameters.
    • OCTET_STREAM

      public static final MimeType OCTET_STREAM
      The MIME type application/octet-stream without parameters.
    • GZIP

      public static final MimeType GZIP
      The MIME type application/x-gzip without parameters.
    • JAR

      public static final MimeType JAR
      The MIME type application/x-jar without parameters.
    • CSV

      public static final MimeType CSV
      The MIME type text/x-csv without parameters.
    • PDF

      public static final MimeType PDF
      The MIME type application/pdf without parameters.
    • POSTSCRIPT

      public static final MimeType POSTSCRIPT
      The MIME type application/postscript without parameters.
    • PNG

      public static final MimeType PNG
      The MIME type image/png without parameters.
    • TEXT_SCI

      public static final MimeType TEXT_SCI
      The MIME type text/sci for greenscilab parameter files.
    • WRAPPED_TYPE_PARAM

      public static final String WRAPPED_TYPE_PARAM
      See Also:
    • CLASS_PARAM

      public static final String CLASS_PARAM
      The name class of the parameter which indicates the Java class of the MIME type JAVA_OBJECT.
      See Also:
    • JAVA_OBJECT

      public static final String JAVA_OBJECT
      The MIME type of local Java objects, application/x-java-jvm-local-objectref, as string.
      See Also:
  • Constructor Details

    • MimeType

      public MimeType(String mediaType, StringMap params, Class cls)
      Constructs a new MimeType for the given parameters.
      Parameters:
      mediaType - the media type (e.g., text/plain)
      params - the parameters of the MIME type
      cls - the representation class of data of this MIME type
    • MimeType

      public MimeType(String mediaType, StringMap params)
      Constructs a new MimeType for the given parameters.
      Parameters:
      mediaType - the media type (e.g., text/plain)
      params - the parameters of the MIME type
    • MimeType

      public MimeType(String mimeType)
      Parses mimeType and constructs a new MimeType using the parsed information. The complete syntax of RFC 2045 is supported.
      Parameters:
      mimeType - MIME type specification according to RFC 2045
  • Method Details

    • valueOf

      public static MimeType valueOf(Class cls)
      Returns a MIME type of media type JAVA_OBJECT and representation class cls.
      Parameters:
      cls - class of Java objects
      Returns:
      MIME type corresponding to local Java objects of class cls
    • valueOf

      public static MimeType valueOf(String mimeType)
      Parses mimeType and constructs a new MimeType as in MimeType(String); if mimeType is null, null is returned.
      Parameters:
      mimeType - MIME type specification according to RFC 2045
      Returns:
      MimeType instance or null
    • getMediaType

      public String getMediaType()
      Returns the media type of this MIME type as String, e.g., text/plain. This does not contain parameters.
      Returns:
      media type of this MIME type
    • getPrimaryType

      public String getPrimaryType()
      Returns the primary type of this MIME type, e.g., text for the media type text/plain.
      Returns:
      primary type of this MIME type
    • getSubType

      public String getSubType()
      Returns the subtype of this MIME type, e.g., plain for the media type text/plain.
      Returns:
      subtype of this MIME type
    • getComment

      public String getComment()
      Returns the comment which has been parsed from the MIME type specification.
      Returns:
      MIME type comment
    • getParameter

      public String getParameter(String name)
    • getParameters

      public StringMap getParameters()
    • getRepresentationClass

      public Class getRepresentationClass()
    • isXMLMimeType

      public boolean isXMLMimeType()
    • isAssignableFrom

      public boolean isAssignableFrom(MimeType s)
    • isAssignableFrom

      public static boolean isAssignableFrom(String target, String source)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object
    • quoteParameter

      public static String quoteParameter(String s)