public final class MediaType extends Object
* 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().
| Modifier and Type | Field and Description |
|---|---|
static MediaType |
AAC_AUDIO
Advanced Audio Coding.
|
static MediaType |
ANY_APPLICATION_TYPE |
static MediaType |
ANY_AUDIO_TYPE |
static MediaType |
ANY_IMAGE_TYPE |
static MediaType |
ANY_TEXT_TYPE |
static MediaType |
ANY_TYPE |
static MediaType |
ANY_VIDEO_TYPE |
static MediaType |
APPLE_MOBILE_CONFIG
|
static MediaType |
APPLE_PASSBOOK
|
static MediaType |
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.
|
static MediaType |
APPLICATION_XML_UTF_8
As described in RFC 3023, this constant
(
application/xml) is used for XML documents that are "unreadable by casual users." |
static MediaType |
ATOM_UTF_8 |
static MediaType |
BASIC_AUDIO
Basic Audio, as defined by RFC
2046.
|
static MediaType |
BMP
Bitmap file format (
bmp
files). |
static MediaType |
BZIP2 |
static MediaType |
CACHE_MANIFEST_UTF_8 |
static MediaType |
CRW
The Canon Image File
Format (
crw files), a widely-used "raw image" format for cameras. |
static MediaType |
CSS_UTF_8 |
static MediaType |
CSV_UTF_8 |
static MediaType |
DART_UTF_8
Files in the dart.
|
static MediaType |
EOT
Embedded OpenType fonts.
|
static MediaType |
EPUB
As described in the International Digital Publishing Forum
EPUB is the distribution and interchange format standard for digital publications and
documents.
|
static MediaType |
EVENT_STREAM
As described in Server-Sent Events, this constant
(
text/event-stream) is used when sending notifications in the form of DOM events from a server. |
static MediaType |
FLV_VIDEO
Flash video.
|
static MediaType |
FORM_DATA |
static MediaType |
GEO_JSON
GeoJSON Format, a geospatial data interchange format
based on JSON.
|
static MediaType |
GIF |
static MediaType |
GZIP |
static MediaType |
HAL_JSON
|
static MediaType |
HTML_UTF_8 |
static MediaType |
I_CALENDAR_UTF_8 |
static MediaType |
ICO |
static MediaType |
JAVASCRIPT_UTF_8
RFC 4329 declares this to be the
correct media type for JavaScript, but
text/javascript may be
necessary in certain situations for compatibility. |
static MediaType |
JOSE
|
static MediaType |
JOSE_JSON
|
static MediaType |
JPEG |
static MediaType |
JSON |
static MediaType |
JSON_PATCH
As described in RFC 6902, this constant
(
application/json-patch+json) is used for expressing a sequence of operations to apply
to a JavaScript Object Notation(JSON) document. |
static MediaType |
JSON_SEQ
As described in RFC 7464, this constant
(
application/json-seq) is used for expressing JSON text sequences. |
static MediaType |
JSON_UTF_8 |
static MediaType |
KEY_ARCHIVE
|
static MediaType |
KMZ
OGC KML (Keyhole Markup Language),
compressed using the ZIP format into KMZ archives.
|
static MediaType |
L16_AUDIO
L16 audio, as defined by RFC 2586.
|
static MediaType |
L24_AUDIO
L24 audio, as defined by RFC 3190.
|
static MediaType |
MANIFEST_JSON_UTF_8
|
static MediaType |
MBOX
The mbox database format.
|
static MediaType |
MICROSOFT_EXCEL
Microsoft Excel spreadsheets.
|
static MediaType |
MICROSOFT_OUTLOOK
Microsoft Outlook items.
|
static MediaType |
MICROSOFT_POWERPOINT
Microsoft Powerpoint presentations.
|
static MediaType |
MICROSOFT_WORD
Microsoft Word documents.
|
static MediaType |
MP4_AUDIO |
static MediaType |
MP4_VIDEO |
static MediaType |
MPEG_AUDIO |
static MediaType |
MPEG_VIDEO |
static MediaType |
NACL_APPLICATION
NaCl applications.
|
static MediaType |
NACL_PORTABLE_APPLICATION
NaCl portable applications.
|
static MediaType |
OCTET_STREAM |
static MediaType |
OGG_AUDIO |
static MediaType |
OGG_CONTAINER |
static MediaType |
OGG_VIDEO |
static MediaType |
OOXML_DOCUMENT |
static MediaType |
OOXML_PRESENTATION |
static MediaType |
OOXML_SHEET |
static MediaType |
OPENDOCUMENT_GRAPHICS |
static MediaType |
OPENDOCUMENT_PRESENTATION |
static MediaType |
OPENDOCUMENT_SPREADSHEET |
static MediaType |
OPENDOCUMENT_TEXT |
static MediaType |
PDF |
static MediaType |
PLAIN_TEXT_UTF_8 |
static MediaType |
PNG |
static MediaType |
POSTSCRIPT |
static MediaType |
PROTOBUF
|
static MediaType |
PSD
|
static MediaType |
QUICKTIME |
static MediaType |
RDF_XML_UTF_8
RDF/XML documents, which are XML
serializations of Resource Description
Framework graphs.
|
static MediaType |
RTF_UTF_8 |
static MediaType |
SFNT
|
static MediaType |
SHOCKWAVE_FLASH |
static MediaType |
SKETCHUP
skp files produced by the 3D Modeling software SketchUp. |
static MediaType |
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. |
static MediaType |
SVG_UTF_8 |
static MediaType |
TAR |
static MediaType |
TEXT_JAVASCRIPT_UTF_8
RFC 4329 declares
application/javascript to be the correct media type for JavaScript, but this
may be necessary in certain situations for compatibility. |
static MediaType |
THREE_GPP_VIDEO
The 3GP multimedia container format.
|
static MediaType |
THREE_GPP2_VIDEO
The 3G2 multimedia container format.
|
static MediaType |
TIFF |
static MediaType |
TSV_UTF_8
|
static MediaType |
VCARD_UTF_8 |
static MediaType |
VND_REAL_AUDIO
Real Audio.
|
static MediaType |
VND_WAVE_AUDIO
WAVE format, as defined by RFC 2361.
|
static MediaType |
VORBIS_AUDIO
Vorbis Audio, as defined by RFC 5215.
|
static MediaType |
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.
|
static MediaType |
WASM_APPLICATION
WASM applications.
|
static MediaType |
WAX_AUDIO
Windows Media metafiles.
|
static MediaType |
WEBM_AUDIO |
static MediaType |
WEBM_VIDEO |
static MediaType |
WEBP
|
static MediaType |
WMA_AUDIO
Windows Media Audio.
|
static MediaType |
WML_UTF_8
UTF-8 encoded Wireless Markup
Language.
|
static MediaType |
WMV |
static MediaType |
WOFF
Web Open Font Format (WOFF) defined by the W3C.
|
static MediaType |
WOFF2
Web Open Font Format (WOFF)
version 2 defined by the W3C.
|
static MediaType |
XHTML_UTF_8 |
static MediaType |
XML_UTF_8
As described in RFC 3023, this constant
(
text/xml) is used for XML documents that are "readable by casual users." |
static MediaType |
XRD_UTF_8
Extensible Resource Descriptors.
|
static MediaType |
ZIP |
| Modifier and Type | Method and Description |
|---|---|
boolean |
belongsTo(MediaType mediaTypeRange)
|
Charset |
charset()
Returns a
Charset for the value of the charset parameter if it is specified. |
Charset |
charset(Charset defaultCharset)
Returns a
Charset for the value of the charset parameter if it is specified. |
static MediaType |
create(String type,
String subtype)
Creates a new media type with the given type and subtype.
|
boolean |
equals(Object obj) |
int |
hashCode() |
boolean |
hasWildcard()
Returns
true if either the type or subtype is the wildcard. |
boolean |
is(MediaType mediaTypeRange)
Returns
true 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. |
String |
nameWithoutParameters()
Returns a name of this
MediaType only consisting of the type and the sub type. |
int |
numWildcards()
Returns the number of wildcards of this
MediaType. |
Map<String,List<String>> |
parameters()
Returns a multimap containing the parameters of this media type.
|
static MediaType |
parse(String input)
Parses a media type from its string representation.
|
float |
qualityFactor()
Returns the quality factor of this
MediaType. |
float |
qualityFactor(float defaultValueIfNotSpecified)
Returns the quality factor of this
MediaType. |
String |
subtype()
Returns the media subtype.
|
String |
toString()
Returns the string representation of this media type in the format described in RFC 2045.
|
String |
type()
Returns the top-level media type.
|
MediaType |
withCharset(Charset charset)
Returns a new instance with the same type and subtype as this instance, with the
charset parameter set to the name of the given charset. |
MediaType |
withoutParameters()
Returns a new instance with the same type and subtype as this instance, but without any
parameters.
|
MediaType |
withParameter(String attribute,
String value)
Replaces all parameters with the given attribute with a single parameter with the
given value.
|
MediaType |
withParameters(Map<String,? extends Iterable<String>> parameters)
Replaces all parameters with the given parameters.
|
MediaType |
withParameters(String attribute,
Iterable<String> values)
Replaces all parameters with the given attribute with parameters using the given
values.
|
public static final MediaType ANY_TYPE
public static final MediaType ANY_TEXT_TYPE
public static final MediaType ANY_IMAGE_TYPE
public static final MediaType ANY_AUDIO_TYPE
public static final MediaType ANY_VIDEO_TYPE
public static final MediaType ANY_APPLICATION_TYPE
public static final MediaType CACHE_MANIFEST_UTF_8
public static final MediaType CSS_UTF_8
public static final MediaType CSV_UTF_8
public static final MediaType HTML_UTF_8
public static final MediaType I_CALENDAR_UTF_8
public static final MediaType PLAIN_TEXT_UTF_8
public static final MediaType EVENT_STREAM
text/event-stream) is used when sending notifications in the form of DOM events from a server.public static final MediaType TEXT_JAVASCRIPT_UTF_8
application/javascript to be the correct media type for JavaScript, but this
may be necessary in certain situations for compatibility.public static final MediaType TSV_UTF_8
public static final MediaType VCARD_UTF_8
public static final MediaType WML_UTF_8
public static final MediaType XML_UTF_8
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.public static final MediaType VTT_UTF_8
public static final MediaType BMP
bmp
files).public static final MediaType CRW
crw files), a widely-used "raw image" format for cameras. It is found in
/etc/mime.types, e.g. in Debian 3.48-1.public static final MediaType GIF
public static final MediaType ICO
public static final MediaType JPEG
public static final MediaType PNG
public static final MediaType PSD
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.
public static final MediaType SVG_UTF_8
public static final MediaType TIFF
public static final MediaType WEBP
public static final MediaType MP4_AUDIO
public static final MediaType MPEG_AUDIO
public static final MediaType OGG_AUDIO
public static final MediaType WEBM_AUDIO
public static final MediaType AAC_AUDIO
public static final MediaType WMA_AUDIO
public static final MediaType WAX_AUDIO
public static final MediaType VND_REAL_AUDIO
public static final MediaType MP4_VIDEO
public static final MediaType MPEG_VIDEO
public static final MediaType OGG_VIDEO
public static final MediaType QUICKTIME
public static final MediaType WEBM_VIDEO
public static final MediaType WMV
public static final MediaType THREE_GPP_VIDEO
public static final MediaType THREE_GPP2_VIDEO
public static final MediaType APPLICATION_XML_UTF_8
public static final MediaType ATOM_UTF_8
public static final MediaType BZIP2
public static final MediaType APPLE_PASSBOOK
public static final MediaType EOT
public static final MediaType EPUB
public static final MediaType FORM_DATA
public static final MediaType KEY_ARCHIVE
public static final MediaType APPLICATION_BINARY
OCTET_STREAM for binary data that is not being served to a browser.public static final MediaType GEO_JSON
public static final MediaType GZIP
public static final MediaType HAL_JSON
public static final MediaType JAVASCRIPT_UTF_8
text/javascript may be
necessary in certain situations for compatibility.public static final MediaType JOSE
public static final MediaType JOSE_JSON
public static final MediaType JSON_UTF_8
public static final MediaType JSON
public static final MediaType JSON_PATCH
application/json-patch+json) is used for expressing a sequence of operations to apply
to a JavaScript Object Notation(JSON) document.public static final MediaType JSON_SEQ
application/json-seq) is used for expressing JSON text sequences.public static final MediaType MANIFEST_JSON_UTF_8
public static final MediaType KML
public static final MediaType KMZ
public static final MediaType MBOX
public static final MediaType APPLE_MOBILE_CONFIG
public static final MediaType MICROSOFT_EXCEL
public static final MediaType MICROSOFT_OUTLOOK
public static final MediaType MICROSOFT_POWERPOINT
public static final MediaType MICROSOFT_WORD
public static final MediaType WASM_APPLICATION
public static final MediaType NACL_APPLICATION
public static final MediaType NACL_PORTABLE_APPLICATION
public static final MediaType OCTET_STREAM
public static final MediaType OGG_CONTAINER
public static final MediaType OOXML_DOCUMENT
public static final MediaType OOXML_PRESENTATION
public static final MediaType OOXML_SHEET
public static final MediaType OPENDOCUMENT_GRAPHICS
public static final MediaType OPENDOCUMENT_PRESENTATION
public static final MediaType OPENDOCUMENT_SPREADSHEET
public static final MediaType OPENDOCUMENT_TEXT
public static final MediaType PDF
public static final MediaType POSTSCRIPT
public static final MediaType PROTOBUF
public static final MediaType RDF_XML_UTF_8
public static final MediaType RTF_UTF_8
public static final MediaType SFNT
public static final MediaType SHOCKWAVE_FLASH
public static final MediaType SKETCHUP
skp files produced by the 3D Modeling software SketchUp.public static final MediaType SOAP_XML_UTF_8
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
public static final MediaType TAR
public static final MediaType WOFF
public static final MediaType WOFF2
public static final MediaType XHTML_UTF_8
public static final MediaType XRD_UTF_8
public static final MediaType ZIP
public String type()
"text" in "text/plain".public String subtype()
"plain" in "text/plain".public Map<String,List<String>> parameters()
public Charset charset()
Charset for the value of the charset parameter if it is specified.Charset, or null if the charset parameter is not specified.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 machinepublic Charset charset(Charset defaultCharset)
Charset for the value of the charset parameter if it is specified.Charset, or defaultCharset if the charset parameter is not specified.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 machinepublic MediaType withoutParameters()
public MediaType withParameters(Map<String,? extends Iterable<String>> parameters)
IllegalArgumentException - if any parameter or value is invalidpublic MediaType withParameters(String attribute, Iterable<String> values)
IllegalArgumentException - if either attribute or values is invalidpublic MediaType withParameter(String attribute, String value)
withParameters(String, Iterable). Prefer withCharset(java.nio.charset.Charset) for setting the charset
parameter when using a Charset object.IllegalArgumentException - if either attribute or value is invalidpublic MediaType withCharset(Charset charset)
charset parameter set to the name of the given charset. Only one charset 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, use withParameter(java.lang.String, java.lang.String).
public boolean hasWildcard()
true if either the type or subtype is the wildcard.public int numWildcards()
MediaType.public boolean is(MediaType mediaTypeRange)
true if this instance falls within the range (as defined by the HTTP Accept header) given
by the argument according to three criteria:
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".
public boolean belongsTo(MediaType mediaTypeRange)
true if this MediaType belongs to the given MediaType.
Similar to what is(MediaType) does except that this one compares the parameters
case-insensitively and excludes 'q' parameter.public float qualityFactor(float defaultValueIfNotSpecified)
MediaType. If it is not specified,
defaultValueIfNotSpecified will be returned.public float qualityFactor()
MediaType. If it is not specified,
1.0f will be returned.public String nameWithoutParameters()
MediaType only consisting of the type and the sub type.public static MediaType create(String type, String subtype)
IllegalArgumentException - if type or subtype is invalid or if a wildcard is used for the
type, but not the subtype.public static MediaType parse(String input)
IllegalArgumentException - if the input is not parsableCopyright © 2020 LeanCloud. All rights reserved.