Class MediaType


  • public final class MediaType
    extends Metadata
    Metadata used to specify the format of representations. The Metadata.getName() method returns a full String representation of the media type including the parameters.
    Author:
    Jerome Louvel
    See Also:
    MIME types on Wikipedia
    • Field Detail

      • APPLICATION_ALL

        public static final MediaType APPLICATION_ALL
      • APPLICATION_ALL_JSON

        public static final MediaType APPLICATION_ALL_JSON
      • APPLICATION_ALL_XML

        public static final MediaType APPLICATION_ALL_XML
      • APPLICATION_ATOM

        public static final MediaType APPLICATION_ATOM
      • APPLICATION_ATOMPUB_CATEGORY

        public static final MediaType APPLICATION_ATOMPUB_CATEGORY
      • APPLICATION_ATOMPUB_SERVICE

        public static final MediaType APPLICATION_ATOMPUB_SERVICE
      • APPLICATION_CAB

        public static final MediaType APPLICATION_CAB
      • APPLICATION_COMPRESS

        public static final MediaType APPLICATION_COMPRESS
      • APPLICATION_ECORE

        public static final MediaType APPLICATION_ECORE
      • APPLICATION_EXCEL

        public static final MediaType APPLICATION_EXCEL
      • APPLICATION_FLASH

        public static final MediaType APPLICATION_FLASH
      • APPLICATION_GNU_TAR

        public static final MediaType APPLICATION_GNU_TAR
      • APPLICATION_GNU_ZIP

        public static final MediaType APPLICATION_GNU_ZIP
      • APPLICATION_HTTP_COOKIES

        public static final MediaType APPLICATION_HTTP_COOKIES
      • APPLICATION_JAVA

        public static final MediaType APPLICATION_JAVA
      • APPLICATION_JAVA_ARCHIVE

        public static final MediaType APPLICATION_JAVA_ARCHIVE
      • APPLICATION_JAVA_OBJECT

        public static final MediaType APPLICATION_JAVA_OBJECT
      • APPLICATION_JAVA_OBJECT_GWT

        public static final MediaType APPLICATION_JAVA_OBJECT_GWT
      • APPLICATION_JAVA_OBJECT_XML

        public static final MediaType APPLICATION_JAVA_OBJECT_XML
      • APPLICATION_JAVASCRIPT

        public static final MediaType APPLICATION_JAVASCRIPT
      • APPLICATION_JNLP

        public static final MediaType APPLICATION_JNLP
      • APPLICATION_JSON

        public static final MediaType APPLICATION_JSON
      • APPLICATION_JSON_ACTIVITY

        public static final MediaType APPLICATION_JSON_ACTIVITY
      • APPLICATION_JSON_PATCH

        public static final MediaType APPLICATION_JSON_PATCH
      • APPLICATION_JSON_SMILE

        public static final MediaType APPLICATION_JSON_SMILE
      • APPLICATION_KML

        public static final MediaType APPLICATION_KML
      • APPLICATION_KMZ

        public static final MediaType APPLICATION_KMZ
      • APPLICATION_LATEX

        public static final MediaType APPLICATION_LATEX
      • APPLICATION_MAC_BINHEX40

        public static final MediaType APPLICATION_MAC_BINHEX40
      • APPLICATION_MATHML

        public static final MediaType APPLICATION_MATHML
      • APPLICATION_MSML

        public static final MediaType APPLICATION_MSML
      • APPLICATION_MSOFFICE_DOCM

        public static final MediaType APPLICATION_MSOFFICE_DOCM
      • APPLICATION_MSOFFICE_DOCX

        public static final MediaType APPLICATION_MSOFFICE_DOCX
      • APPLICATION_MSOFFICE_DOTM

        public static final MediaType APPLICATION_MSOFFICE_DOTM
      • APPLICATION_MSOFFICE_DOTX

        public static final MediaType APPLICATION_MSOFFICE_DOTX
      • APPLICATION_MSOFFICE_ONETOC

        public static final MediaType APPLICATION_MSOFFICE_ONETOC
      • APPLICATION_MSOFFICE_ONETOC2

        public static final MediaType APPLICATION_MSOFFICE_ONETOC2
      • APPLICATION_MSOFFICE_POTM

        public static final MediaType APPLICATION_MSOFFICE_POTM
      • APPLICATION_MSOFFICE_POTX

        public static final MediaType APPLICATION_MSOFFICE_POTX
      • APPLICATION_MSOFFICE_PPAM

        public static final MediaType APPLICATION_MSOFFICE_PPAM
      • APPLICATION_MSOFFICE_PPSM

        public static final MediaType APPLICATION_MSOFFICE_PPSM
      • APPLICATION_MSOFFICE_PPSX

        public static final MediaType APPLICATION_MSOFFICE_PPSX
      • APPLICATION_MSOFFICE_PPTM

        public static final MediaType APPLICATION_MSOFFICE_PPTM
      • APPLICATION_MSOFFICE_PPTX

        public static final MediaType APPLICATION_MSOFFICE_PPTX
      • APPLICATION_MSOFFICE_SLDM

        public static final MediaType APPLICATION_MSOFFICE_SLDM
      • APPLICATION_MSOFFICE_SLDX

        public static final MediaType APPLICATION_MSOFFICE_SLDX
      • APPLICATION_MSOFFICE_XLAM

        public static final MediaType APPLICATION_MSOFFICE_XLAM
      • APPLICATION_MSOFFICE_XLSB

        public static final MediaType APPLICATION_MSOFFICE_XLSB
      • APPLICATION_MSOFFICE_XLSM

        public static final MediaType APPLICATION_MSOFFICE_XLSM
      • APPLICATION_MSOFFICE_XLSX

        public static final MediaType APPLICATION_MSOFFICE_XLSX
      • APPLICATION_MSOFFICE_XLTM

        public static final MediaType APPLICATION_MSOFFICE_XLTM
      • APPLICATION_MSOFFICE_XLTX

        public static final MediaType APPLICATION_MSOFFICE_XLTX
      • APPLICATION_OCTET_STREAM

        public static final MediaType APPLICATION_OCTET_STREAM
      • APPLICATION_OPENOFFICE_ODB

        public static final MediaType APPLICATION_OPENOFFICE_ODB
      • APPLICATION_OPENOFFICE_ODC

        public static final MediaType APPLICATION_OPENOFFICE_ODC
      • APPLICATION_OPENOFFICE_ODF

        public static final MediaType APPLICATION_OPENOFFICE_ODF
      • APPLICATION_OPENOFFICE_ODG

        public static final MediaType APPLICATION_OPENOFFICE_ODG
      • APPLICATION_OPENOFFICE_ODI

        public static final MediaType APPLICATION_OPENOFFICE_ODI
      • APPLICATION_OPENOFFICE_ODM

        public static final MediaType APPLICATION_OPENOFFICE_ODM
      • APPLICATION_OPENOFFICE_ODP

        public static final MediaType APPLICATION_OPENOFFICE_ODP
      • APPLICATION_OPENOFFICE_ODS

        public static final MediaType APPLICATION_OPENOFFICE_ODS
      • APPLICATION_OPENOFFICE_ODT

        public static final MediaType APPLICATION_OPENOFFICE_ODT
      • APPLICATION_OPENOFFICE_OTG

        public static final MediaType APPLICATION_OPENOFFICE_OTG
      • APPLICATION_OPENOFFICE_OTH

        public static final MediaType APPLICATION_OPENOFFICE_OTH
      • APPLICATION_OPENOFFICE_OTP

        public static final MediaType APPLICATION_OPENOFFICE_OTP
      • APPLICATION_OPENOFFICE_OTS

        public static final MediaType APPLICATION_OPENOFFICE_OTS
      • APPLICATION_OPENOFFICE_OTT

        public static final MediaType APPLICATION_OPENOFFICE_OTT
      • APPLICATION_OPENOFFICE_OXT

        public static final MediaType APPLICATION_OPENOFFICE_OXT
      • APPLICATION_PDF

        public static final MediaType APPLICATION_PDF
      • APPLICATION_POSTSCRIPT

        public static final MediaType APPLICATION_POSTSCRIPT
      • APPLICATION_POWERPOINT

        public static final MediaType APPLICATION_POWERPOINT
      • APPLICATION_PROJECT

        public static final MediaType APPLICATION_PROJECT
      • APPLICATION_RDF_TRIG

        public static final MediaType APPLICATION_RDF_TRIG
      • APPLICATION_RDF_TRIX

        public static final MediaType APPLICATION_RDF_TRIX
      • APPLICATION_RDF_TURTLE

        @Deprecated
        public static final MediaType APPLICATION_RDF_TURTLE
        Deprecated.
        Replaced by the official TEXT_TURTLE media type.
      • APPLICATION_RDF_XML

        public static final MediaType APPLICATION_RDF_XML
      • APPLICATION_RELAXNG_COMPACT

        public static final MediaType APPLICATION_RELAXNG_COMPACT
      • APPLICATION_RELAXNG_XML

        public static final MediaType APPLICATION_RELAXNG_XML
      • APPLICATION_RSS

        public static final MediaType APPLICATION_RSS
      • APPLICATION_RTF

        public static final MediaType APPLICATION_RTF
      • APPLICATION_SDP

        public static final MediaType APPLICATION_SDP
      • APPLICATION_SPARQL_RESULTS_JSON

        public static final MediaType APPLICATION_SPARQL_RESULTS_JSON
      • APPLICATION_SPARQL_RESULTS_XML

        public static final MediaType APPLICATION_SPARQL_RESULTS_XML
      • APPLICATION_SPSS_SAV

        public static final MediaType APPLICATION_SPSS_SAV
      • APPLICATION_SPSS_SPS

        public static final MediaType APPLICATION_SPSS_SPS
      • APPLICATION_STATA_STA

        public static final MediaType APPLICATION_STATA_STA
      • APPLICATION_STUFFIT

        public static final MediaType APPLICATION_STUFFIT
      • APPLICATION_TAR

        public static final MediaType APPLICATION_TAR
      • APPLICATION_TEX

        public static final MediaType APPLICATION_TEX
      • APPLICATION_TROFF_MAN

        public static final MediaType APPLICATION_TROFF_MAN
      • APPLICATION_VOICEXML

        public static final MediaType APPLICATION_VOICEXML
      • APPLICATION_W3C_SCHEMA

        public static final MediaType APPLICATION_W3C_SCHEMA
      • APPLICATION_W3C_XSLT

        public static final MediaType APPLICATION_W3C_XSLT
      • APPLICATION_WADL

        public static final MediaType APPLICATION_WADL
      • APPLICATION_WORD

        public static final MediaType APPLICATION_WORD
      • APPLICATION_WWW_FORM

        public static final MediaType APPLICATION_WWW_FORM
      • APPLICATION_XHTML

        public static final MediaType APPLICATION_XHTML
      • APPLICATION_XMI

        public static final MediaType APPLICATION_XMI
      • APPLICATION_XML

        public static final MediaType APPLICATION_XML
      • APPLICATION_XML_DTD

        public static final MediaType APPLICATION_XML_DTD
      • APPLICATION_XQUERY

        public static final MediaType APPLICATION_XQUERY
      • APPLICATION_XUL

        public static final MediaType APPLICATION_XUL
      • APPLICATION_YAML

        public static final MediaType APPLICATION_YAML
      • APPLICATION_ZIP

        public static final MediaType APPLICATION_ZIP
      • AUDIO_ALL

        public static final MediaType AUDIO_ALL
      • AUDIO_BASIC

        public static final MediaType AUDIO_BASIC
      • AUDIO_MIDI

        public static final MediaType AUDIO_MIDI
      • AUDIO_MPEG

        public static final MediaType AUDIO_MPEG
      • AUDIO_REAL

        public static final MediaType AUDIO_REAL
      • AUDIO_WAV

        public static final MediaType AUDIO_WAV
      • IMAGE_ALL

        public static final MediaType IMAGE_ALL
      • IMAGE_BMP

        public static final MediaType IMAGE_BMP
      • IMAGE_GIF

        public static final MediaType IMAGE_GIF
      • IMAGE_ICON

        public static final MediaType IMAGE_ICON
      • IMAGE_JPEG

        public static final MediaType IMAGE_JPEG
      • IMAGE_PNG

        public static final MediaType IMAGE_PNG
      • IMAGE_SVG

        public static final MediaType IMAGE_SVG
      • IMAGE_TIFF

        public static final MediaType IMAGE_TIFF
      • MESSAGE_ALL

        public static final MediaType MESSAGE_ALL
      • MESSAGE_HTTP

        public static final MediaType MESSAGE_HTTP
      • MODEL_ALL

        public static final MediaType MODEL_ALL
      • MODEL_VRML

        public static final MediaType MODEL_VRML
      • MULTIPART_ALL

        public static final MediaType MULTIPART_ALL
      • MULTIPART_FORM_DATA

        public static final MediaType MULTIPART_FORM_DATA
      • TEXT_ALL

        public static final MediaType TEXT_ALL
      • TEXT_CALENDAR

        public static final MediaType TEXT_CALENDAR
      • TEXT_CSS

        public static final MediaType TEXT_CSS
      • TEXT_CSV

        public static final MediaType TEXT_CSV
      • TEXT_DAT

        public static final MediaType TEXT_DAT
      • TEXT_HTML

        public static final MediaType TEXT_HTML
      • TEXT_J2ME_APP_DESCRIPTOR

        public static final MediaType TEXT_J2ME_APP_DESCRIPTOR
      • TEXT_JAVASCRIPT

        public static final MediaType TEXT_JAVASCRIPT
      • TEXT_PLAIN

        public static final MediaType TEXT_PLAIN
      • TEXT_RDF_N3

        public static final MediaType TEXT_RDF_N3
      • TEXT_RDF_NTRIPLES

        public static final MediaType TEXT_RDF_NTRIPLES
      • TEXT_TSV

        public static final MediaType TEXT_TSV
      • TEXT_TURTLE

        public static final MediaType TEXT_TURTLE
      • TEXT_URI_LIST

        public static final MediaType TEXT_URI_LIST
      • TEXT_VCARD

        public static final MediaType TEXT_VCARD
      • TEXT_XML

        public static final MediaType TEXT_XML
      • TEXT_YAML

        public static final MediaType TEXT_YAML
      • VIDEO_ALL

        public static final MediaType VIDEO_ALL
      • VIDEO_AVI

        public static final MediaType VIDEO_AVI
      • VIDEO_MP4

        public static final MediaType VIDEO_MP4
      • VIDEO_MPEG

        public static final MediaType VIDEO_MPEG
      • VIDEO_QUICKTIME

        public static final MediaType VIDEO_QUICKTIME
      • VIDEO_WMV

        public static final MediaType VIDEO_WMV
    • Constructor Detail

      • MediaType

        public MediaType​(java.lang.String name)
        Constructor.
        Parameters:
        name - The name.
      • MediaType

        public MediaType​(java.lang.String name,
                         Series<Parameter> parameters)
        Constructor.
        Parameters:
        name - The name.
        parameters - The list of parameters.
      • MediaType

        public MediaType​(java.lang.String name,
                         Series<Parameter> parameters,
                         java.lang.String description)
        Constructor.
        Parameters:
        name - The name.
        parameters - The list of parameters.
        description - The description.
      • MediaType

        public MediaType​(java.lang.String name,
                         java.lang.String description)
        Constructor.
        Parameters:
        name - The name.
        description - The description.
    • Method Detail

      • getMostSpecific

        public static MediaType getMostSpecific​(MediaType... mediaTypes)
                                         throws java.lang.IllegalArgumentException
        Returns the first of the most specific media type of the given array of MediaTypes.

        Examples:

        • "text/plain" is more specific than "text/*" or "image/*"
        • "text/html" is same specific as "application/pdf" or "image/jpg"
        • "text/*" is same specific than "application/*" or "image/*"
        • "*/*" is the most unspecific MediaType
        Parameters:
        mediaTypes - An array of media types.
        Returns:
        The most concrete MediaType.
        Throws:
        java.lang.IllegalArgumentException - If the array is null or empty.
      • register

        public static MediaType register​(java.lang.String name,
                                         java.lang.String description)
        Register a media type as a known type that can later be retrieved using valueOf(String). If the type already exists, the existing type is returned, otherwise a new instance is created.
        Parameters:
        name - The name.
        description - The description.
        Returns:
        The registered media type
      • valueOf

        public static MediaType valueOf​(java.lang.String name)
        Returns the media type associated to a name. If an existing constant exists then it is returned, otherwise a new instance is created.
        Parameters:
        name - The name.
        Returns:
        The associated media type.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class Metadata
      • equals

        public boolean equals​(java.lang.Object obj,
                              boolean ignoreParameters)
        Test the equality of two media types, with the possibility to ignore the parameters.
        Parameters:
        obj - The object to compare to.
        ignoreParameters - Indicates if parameters should be ignored during comparison.
        Returns:
        True if both media types are equal.
      • getMainType

        public java.lang.String getMainType()
        Returns the main type.
        Returns:
        The main type.
      • getParameters

        public Series<Parameter> getParameters()
        Returns the unmodifiable list of parameters corresponding to subtype modifiers. Creates a new instance if no one has been set.
        Returns:
        The list of parameters.
      • getParent

        public MediaType getParent()
        Returns the parent metadata if available or null.
        In case the media type has parameters, this method returns the concatenation of the main type and the subtype. If the subtype is not equal to "*", it returns the concatenation of the main type and "*". Otherwise, it returns either the ALL media type if it is already the ALL media type, or null.
        Specified by:
        getParent in class Metadata
        Returns:
        The parent metadata.
      • getSubType

        public java.lang.String getSubType()
        Returns the sub-type.
        Returns:
        The sub-type.
      • includes

        public boolean includes​(Metadata included,
                                boolean ignoreParameters)
        Indicates if a given media type is included in the current one @see includes(Metadata, boolean). The test is true if both types are equal or if the given media type is within the range of the current one. For example, ALL includes all media types. Parameters are ignored for this comparison. A null media type is considered as included into the current one. It ignores the parameters.

        Examples:

        • TEXT_ALL.includes(TEXT_PLAIN) returns true
        • TEXT_PLAIN.includes(TEXT_ALL) returns false
        Parameters:
        included - The media type to test for inclusion.
        Returns:
        True if the given media type is included in the current one.
        See Also:
        Metadata.isCompatible(Metadata)
      • isConcrete

        public boolean isConcrete()
        Checks if the current media type is concrete. A media type is concrete if neither the main type nor the sub-type are equal to "*".
        Returns:
        True if this media type is concrete.