Class MediaType
*
character is treated as a wildcard and is used to represent any acceptable
type or subtype value. A media type may not have wildcard type with a declared subtype. The
*
character has no special meaning as part of a parameter. All values for type, subtype,
parameter attributes or parameter values must be valid according to RFCs
2045 and
2046.
All portions of the media type that are case-insensitive (type, subtype, parameter attributes)
are normalized to lowercase. The value of the charset
parameter is normalized to
lowercase, but all others are left as-is.
Note that this specifically does not represent the value of the MIME
Content-Type
header and as such has no support for header-specific considerations such as
line folding and comments.
For media types that take a charset the predefined constants default to UTF-8 and have a
"_UTF_8" suffix. To get a version without a character set, use withoutParameters()
.
- Since:
- 12.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MediaType
Media type for Advanced Audio Coding.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
Media type for Apple over-the-air mobile configuration profiles.static final MediaType
Media type for Apple Passbook.static final MediaType
This is a non-standard media type, but is commonly used in serving hosted binary files as it is known not to trigger content sniffing in current browsers.static final MediaType
static final MediaType
static final MediaType
Media type for Basic Audio, as defined by RFC 2046.static final MediaType
static final MediaType
static final MediaType
static final MediaType
The media type for the Canon Image File Format (crw
files), a widely-used "raw image" format for cameras.static final MediaType
static final MediaType
static final MediaType
Media type for dart files.static final MediaType
Media type for Embedded OpenType fonts.static final MediaType
As described in the International Digital Publishing Forum EPUB is the distribution and interchange format standard for digital publications and documents.static final MediaType
Media type for Flash video.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
RFC 4329 declares this to be the correct media type for JavaScript, buttext/javascript
may be necessary in certain situations for compatibility.static final MediaType
static final MediaType
static final MediaType
As described in PKCS #12: Personal Information Exchange Syntax Standard, PKCS #12 defines an archive file format for storing many cryptography objects as a single file.static final MediaType
static final MediaType
static final MediaType
Media type for L24 audio, as defined by RFC 3190.static final MediaType
Media type for the Manifest for a web application.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
Media type for NaCl applications.static final MediaType
Media type for NaCl portable applications.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
The media type for the Photoshop File Format (psd
files) as defined by IANA, and found in/etc/mime.types
, e.g.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
As described in RFC 3902, this constant (application/soap+xml
) is used to identify SOAP 1.2 message envelopes that have been serialized with XML 1.0.static final MediaType
static final MediaType
static final MediaType
RFC 4329 declaresapplication/javascript
to be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility.static final MediaType
Media type for the 3GP multimedia container format.static final MediaType
Media type for the 3G2 multimedia container format.static final MediaType
static final MediaType
static final MediaType
static final MediaType
Media type for Real Audio.static final MediaType
Media type for WAVE format, as defined by RFC 2361.static final MediaType
Media type for Vorbis Audio, as defined by RFC 5215.static final MediaType
As described in the VTT spec, this is used for Web Video Text Tracks (WebVTT) files, used with the HTML5 track element.static final MediaType
Media type for Windows Media metafiles.static final MediaType
static final MediaType
static final MediaType
static final MediaType
Media type for Windows Media Audio.static final MediaType
static final MediaType
static final MediaType
Media type for the Web Open Font Format (WOFF) defined by the W3C.static final MediaType
Media type for the Web Open Font Format (WOFF) version 2 defined by the W3C.static final MediaType
static final MediaType
As described in RFC 3023, this constant (text/xml
) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8
is provided for documents that are intended for applications.static final MediaType
Media type for Extensible Resource Descriptors.static final MediaType
-
Method Summary
Modifier and TypeMethodDescriptioncharset()
Returns an optional charset for the value of the charset parameter if it is specified.static MediaType
Creates a new media type with the given type and subtype.boolean
int
hashCode()
boolean
Returns true if either the type or subtype is the wildcard.boolean
Returnstrue
if this instance falls within the range (as defined by the HTTP Accept header) given by the argument according to three criteria: The type of the argument is the wildcard or equal to the type of this instance.Returns a multimap containing the parameters of this media type.static MediaType
Parses a media type from its string representation.subtype()
Returns the media subtype.toString()
Returns the string representation of this media type in the format described in RFC 2045.type()
Returns the top-level media type.withCharset
(Charset charset) Returns a new instance with the same type and subtype as this instance, with thecharset
parameter set to thename
of the given charset.Returns a new instance with the same type and subtype as this instance, but without any parameters.withParameter
(String attribute, String value) Replaces all parameters with the given attribute with a single parameter with the given value.withParameters
(Multimap<String, String> parameters) Replaces all parameters with the given parameters.
-
Field Details
-
ANY_TYPE
-
ANY_TEXT_TYPE
-
ANY_IMAGE_TYPE
-
ANY_AUDIO_TYPE
-
ANY_VIDEO_TYPE
-
ANY_APPLICATION_TYPE
-
CACHE_MANIFEST_UTF_8
-
CSS_UTF_8
-
CSV_UTF_8
-
HTML_UTF_8
-
I_CALENDAR_UTF_8
-
PLAIN_TEXT_UTF_8
-
TEXT_JAVASCRIPT_UTF_8
RFC 4329 declaresapplication/javascript
to be the correct media type for JavaScript, but this may be necessary in certain situations for compatibility. -
TSV_UTF_8
- Since:
- 15.0
-
VCARD_UTF_8
-
WML_UTF_8
-
XML_UTF_8
As described in RFC 3023, this constant (text/xml
) is used for XML documents that are "readable by casual users."APPLICATION_XML_UTF_8
is provided for documents that are intended for applications. -
VTT_UTF_8
As described in the VTT spec, this is used for Web Video Text Tracks (WebVTT) files, used with the HTML5 track element.- Since:
- 20.0
-
BMP
-
CRW
The media type for the Canon Image File Format (crw
files), a widely-used "raw image" format for cameras. It is found in/etc/mime.types
, e.g. in Debian 3.48-1.- Since:
- 15.0
-
GIF
-
ICO
-
JPEG
-
PNG
-
PSD
The media type for the Photoshop File Format (psd
files) as defined by IANA, and found in/etc/mime.types
, e.g. of the Apache HTTPD project; for the specification, see Adobe Photoshop Document Format and Wikipedia; this is the regular output/input of Photoshop (which can also export to various image formats; note that files with extension "PSB" are in a distinct but related format).This is a more recent replacement for the older, experimental type
x-photoshop
: RFC-2046.6.- Since:
- 15.0
-
SVG_UTF_8
-
TIFF
-
WEBP
-
MP4_AUDIO
-
MPEG_AUDIO
-
OGG_AUDIO
-
WEBM_AUDIO
-
L24_AUDIO
Media type for L24 audio, as defined by RFC 3190.- Since:
- 20.0
-
BASIC_AUDIO
Media type for Basic Audio, as defined by RFC 2046.- Since:
- 20.0
-
AAC_AUDIO
Media type for Advanced Audio Coding. For more information, see Advanced Audio Coding.- Since:
- 20.0
-
VORBIS_AUDIO
Media type for Vorbis Audio, as defined by RFC 5215.- Since:
- 20.0
-
WMA_AUDIO
Media type for Windows Media Audio. For more information, see file name extensions for Windows Media metafiles.- Since:
- 20.0
-
WAX_AUDIO
Media type for Windows Media metafiles. For more information, see file name extensions for Windows Media metafiles.- Since:
- 20.0
-
VND_REAL_AUDIO
Media type for Real Audio. For more information, see this link.- Since:
- 20.0
-
VND_WAVE_AUDIO
Media type for WAVE format, as defined by RFC 2361.- Since:
- 20.0
-
MP4_VIDEO
-
MPEG_VIDEO
-
OGG_VIDEO
-
QUICKTIME
-
WEBM_VIDEO
-
WMV
-
FLV_VIDEO
Media type for Flash video. For more information, see this link.- Since:
- 20.0
-
THREE_GPP_VIDEO
Media type for the 3GP multimedia container format. For more information, see 3GPP TS 26.244.- Since:
- 20.0
-
THREE_GPP2_VIDEO
Media type for the 3G2 multimedia container format. For more information, see 3GPP2 C.S0050-B.- Since:
- 20.0
-
APPLICATION_XML_UTF_8
-
ATOM_UTF_8
-
BZIP2
-
DART_UTF_8
Media type for dart files.- Since:
- 19.0
-
APPLE_PASSBOOK
Media type for Apple Passbook.- Since:
- 19.0
-
EOT
Media type for Embedded OpenType fonts. This is registered with the IANA.- Since:
- 17.0
-
EPUB
As described in the International Digital Publishing Forum EPUB is the distribution and interchange format standard for digital publications and documents. This media type is defined in the EPUB Open Container Format specification.- Since:
- 15.0
-
FORM_DATA
-
KEY_ARCHIVE
As described in PKCS #12: Personal Information Exchange Syntax Standard, PKCS #12 defines an archive file format for storing many cryptography objects as a single file.- Since:
- 15.0
-
APPLICATION_BINARY
This is a non-standard media type, but is commonly used in serving hosted binary files as it is known not to trigger content sniffing in current browsers. It should not be used in other situations as it is not specified by any RFC and does not appear in the /IANA MIME Media Types list. ConsiderOCTET_STREAM
for binary data that is not being served to a browser.- Since:
- 14.0
-
GZIP
-
JAVASCRIPT_UTF_8
RFC 4329 declares this to be the correct media type for JavaScript, buttext/javascript
may be necessary in certain situations for compatibility. -
JSON_UTF_8
-
MANIFEST_JSON_UTF_8
Media type for the Manifest for a web application.- Since:
- 19.0
-
KML
-
KMZ
-
MBOX
-
APPLE_MOBILE_CONFIG
Media type for Apple over-the-air mobile configuration profiles.- Since:
- 18.0
-
MICROSOFT_EXCEL
-
MICROSOFT_POWERPOINT
-
MICROSOFT_WORD
-
NACL_APPLICATION
Media type for NaCl applications. For more information see the Developer Guide for Native Client Application Structure.- Since:
- 20.0
-
NACL_PORTABLE_APPLICATION
Media type for NaCl portable applications. For more information see the Developer Guide for Native Client Application Structure.- Since:
- 20.0
-
OCTET_STREAM
-
OGG_CONTAINER
-
OOXML_DOCUMENT
-
OOXML_PRESENTATION
-
OOXML_SHEET
-
OPENDOCUMENT_GRAPHICS
-
OPENDOCUMENT_PRESENTATION
-
OPENDOCUMENT_SPREADSHEET
-
OPENDOCUMENT_TEXT
-
PDF
-
POSTSCRIPT
-
PROTOBUF
- Since:
- 15.0
-
RDF_XML_UTF_8
-
RTF_UTF_8
-
SFNT
Media type for SFNT fonts (which includes TrueType and OpenType fonts). This is registered with the IANA.- Since:
- 17.0
-
SHOCKWAVE_FLASH
-
SKETCHUP
-
SOAP_XML_UTF_8
As described in RFC 3902, this constant (application/soap+xml
) is used to identify SOAP 1.2 message envelopes that have been serialized with XML 1.0.For SOAP 1.1 messages, see
XML_UTF_8
per W3C Note on Simple Object Access Protocol (SOAP) 1.1- Since:
- 20.0
-
TAR
-
WOFF
Media type for the Web Open Font Format (WOFF) defined by the W3C. This is registered with the IANA.- Since:
- 17.0
-
WOFF2
Media type for the Web Open Font Format (WOFF) version 2 defined by the W3C.- Since:
- 20.0
-
XHTML_UTF_8
-
XRD_UTF_8
Media type for Extensible Resource Descriptors. This is not yet registered with the IANA, but it is specified by OASIS in the XRD definition and implemented in projects such as WebFinger. -
ZIP
-
-
Method Details
-
type
Returns the top-level media type. For example,"text"
in"text/plain"
. -
subtype
Returns the media subtype. For example,"plain"
in"text/plain"
. -
parameters
Returns a multimap containing the parameters of this media type. -
charset
Returns an optional charset for the value of the charset parameter if it is specified.- Throws:
IllegalStateException
- if multiple charset values have been set for this media typeIllegalCharsetNameException
- if a charset value is present, but illegalUnsupportedCharsetException
- if a charset value is present, but no support is available in this instance of the Java virtual machine
-
withoutParameters
Returns a new instance with the same type and subtype as this instance, but without any parameters. -
withParameters
Replaces all parameters with the given parameters.- Throws:
IllegalArgumentException
- if any parameter or value is invalid
-
withParameter
Replaces all parameters with the given attribute with a single parameter with the given value. If multiple parameters with the same attributes are necessary usewithParameters(com.google.common.collect.Multimap<java.lang.String, java.lang.String>)
. PreferwithCharset(java.nio.charset.Charset)
for setting thecharset
parameter when using aCharset
object.- Throws:
IllegalArgumentException
- if eitherattribute
orvalue
is invalid
-
withCharset
Returns a new instance with the same type and subtype as this instance, with thecharset
parameter set to thename
of the given charset. Only onecharset
parameter will be present on the new instance regardless of the number set on this one.If a charset must be specified that is not supported on this JVM (and thus is not representable as a
Charset
instance, usewithParameter(java.lang.String, java.lang.String)
. -
hasWildcard
public boolean hasWildcard()Returns true if either the type or subtype is the wildcard. -
is
Returnstrue
if this instance falls within the range (as defined by the HTTP Accept header) given by the argument according to three criteria:- The type of the argument is the wildcard or equal to the type of this instance.
- The subtype of the argument is the wildcard or equal to the subtype of this instance.
- All of the parameters present in the argument are present in this instance.
For example:
PLAIN_TEXT_UTF_8.is(PLAIN_TEXT_UTF_8) // true PLAIN_TEXT_UTF_8.is(HTML_UTF_8) // false PLAIN_TEXT_UTF_8.is(ANY_TYPE) // true PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE) // true PLAIN_TEXT_UTF_8.is(ANY_IMAGE_TYPE) // false PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE.withCharset(UTF_8)) // true PLAIN_TEXT_UTF_8.withoutParameters().is(ANY_TEXT_TYPE.withCharset(UTF_8)) // false PLAIN_TEXT_UTF_8.is(ANY_TEXT_TYPE.withCharset(UTF_16)) // false
Note that while it is possible to have the same parameter declared multiple times within a media type this method does not consider the number of occurrences of a parameter. For example,
"text/plain; charset=UTF-8"
satisfies"text/plain; charset=UTF-8; charset=UTF-8"
. -
create
Creates a new media type with the given type and subtype.- Throws:
IllegalArgumentException
- if type or subtype is invalid or if a wildcard is used for the type, but not the subtype.
-
parse
Parses a media type from its string representation.- Throws:
IllegalArgumentException
- if the input is not parsable
-
equals
-
hashCode
public int hashCode() -
toString
Returns the string representation of this media type in the format described in RFC 2045.
-