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()
.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final MediaType
Advanced Audio Coding.static final MediaType
static final MediaType
static final MediaType
Wildcard matching any "font" top-level media type.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
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
As described in RFC 3023, this constant (application/xml
) is used for XML documents that are "unreadable by casual users."static final MediaType
static final MediaType
static final MediaType
Basic Audio, as defined by RFC 2046.static final MediaType
Bitmap file format (bmp
files).static final MediaType
Brotli Compression format, a lossless data compression format.static final MediaType
static final MediaType
static final MediaType
The Canon Image File Format (crw
files), a widely-used "raw image" format for cameras.static final MediaType
static final MediaType
static final MediaType
Files in the dart.static final MediaType
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
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 final MediaType
Flash video.static final MediaType
A collection of font outlines as defined by RFC 8081.static final MediaType
Open Type Font Format (OTF) as defined by RFC 8081.static final MediaType
Spline or Scalable Font Format (SFNT).static final MediaType
True Type Font Format (TTF) as defined by RFC 8081.static final MediaType
Web Open Font Format (WOFF).static final MediaType
Web Open Font Format (WOFF2).static final MediaType
static final MediaType
GeoJSON Format, a geospatial data interchange format based on JSON.static final MediaType
static final MediaType
static final MediaType
Deprecated.static final MediaType
GraphQL over JSON which is the official GraphQL response content type.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
static final MediaType
static final MediaType
static final MediaType
As described in JSON Lines, this constant is used for expressing JSON lines.static final MediaType
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 final MediaType
As described in RFC 7464, this constant (application/json-seq
) is used for expressing JSON text sequences.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
OGC KML (Keyhole Markup Language), compressed using the ZIP format into KMZ archives.static final MediaType
L16 audio, as defined by RFC 2586.static final MediaType
L24 audio, as defined by RFC 3190.static final MediaType
static final MediaType
The mbox database format.static final MediaType
Media type for Dynamic Adaptive Streaming over HTTP (DASH).static final MediaType
Microsoft Excel spreadsheets.static final MediaType
Microsoft Outlook items.static final MediaType
Microsoft Powerpoint presentations.static final MediaType
Microsoft Word documents.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
AMediaType
constant representingmultipart/alternative
media type.static final MediaType
AMediaType
constant representingmultipart/digest
media type.static final MediaType
AMediaType
constant representingmultipart/encrypted
media type.static final MediaType
AMediaType
constant representingmultipart/form-data
media type.static final MediaType
AMediaType
constant representingmultipart/mixed
media type.static final MediaType
AMediaType
constant representingmultipart/parallel
media type.static final MediaType
AMediaType
constant representingmultipart/related
media type.static final MediaType
AMediaType
constant representingmultipart/signed
media type.static final MediaType
NaCl applications.static final MediaType
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
OpenSearch Description files are XML files that describe how a website can be used as a search engine by consumers (e.g. web browsers).static final MediaType
static final MediaType
The text/plain content type is the generic subtype for plain text.static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
static final MediaType
RDF/XML documents, which are XML serializations of Resource Description Framework graphs.static final MediaType
static final MediaType
static final MediaType
static final MediaType
skp
files produced by the 3D Modeling software SketchUp.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
The 3GP multimedia container format.static final MediaType
The 3G2 multimedia container format.static final MediaType
static final MediaType
static final MediaType
static final MediaType
Real Audio.static final MediaType
WAVE format, as defined by RFC 2361.static final MediaType
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
WASM applications.static final MediaType
Windows Media metafiles.static final MediaType
static final MediaType
static final MediaType
static final MediaType
Windows Media Audio.static final MediaType
UTF-8 encoded Wireless Markup Language.static final MediaType
static final MediaType
static final MediaType
RFC 8081 declaresfont/woff2
to be the correct media type for WOFF2, but this may be necessary in certain situations for compatibility.static final MediaType
static final MediaType
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."static final MediaType
Extensible Resource Descriptors.static final MediaType
static final MediaType
Zstandard Compression format, a lossless data compression format. -
Method Summary
Modifier and TypeMethodDescriptionboolean
charset()
Returns aCharset
for the value of the charset parameter if it is specified.Returns aCharset
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
Returnstrue
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.boolean
isJson()
boolean
Returnstrue
if the type is multipart.boolean
Returns a name of thisMediaType
only consisting of the type and the sub type.int
Returns the number of wildcards of thisMediaType
.Returns a multimap containing the parameters of this media type.static MediaType
Parses a media type from its string representation.float
Returns the quality factor of thisMediaType
.float
qualityFactor
(float defaultValueIfNotSpecified) Returns the quality factor of thisMediaType
.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 the name 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
(String attribute, Iterable<String> values) Replaces all parameters with the given attribute with parameters using the given values.withParameters
(Map<String, ? extends Iterable<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
-
ANY_FONT_TYPE
Wildcard matching any "font" top-level media type. -
ANY_MULTIPART_TYPE
-
CACHE_MANIFEST_UTF_8
-
CSS_UTF_8
-
CSV_UTF_8
-
HTML_UTF_8
-
I_CALENDAR_UTF_8
-
PLAIN_TEXT_UTF_8
-
PLAIN_TEXT
The text/plain content type is the generic subtype for plain text. -
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. -
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
-
VCARD_UTF_8
-
WML_UTF_8
UTF-8 encoded Wireless Markup Language. -
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. -
BMP
Bitmap file format (bmp
files). -
CRW
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. -
GIF
-
ICO
-
JPEG
-
PNG
-
PSD
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. -
SVG_UTF_8
-
TIFF
-
WEBP
-
HEIF
-
JP2K
-
AVIF
-
MP4_AUDIO
-
MPEG_AUDIO
-
OGG_AUDIO
-
WEBM_AUDIO
-
L16_AUDIO
L16 audio, as defined by RFC 2586. -
L24_AUDIO
L24 audio, as defined by RFC 3190. -
BASIC_AUDIO
Basic Audio, as defined by RFC 2046. -
AAC_AUDIO
Advanced Audio Coding. For more information, see Advanced Audio Coding. -
VORBIS_AUDIO
Vorbis Audio, as defined by RFC 5215. -
WMA_AUDIO
Windows Media Audio. For more information, see file name extensions for Windows Media metafiles. -
WAX_AUDIO
Windows Media metafiles. For more information, see file name extensions for Windows Media metafiles. -
VND_REAL_AUDIO
Real Audio. For more information, see this link. -
VND_WAVE_AUDIO
WAVE format, as defined by RFC 2361. -
MP4_VIDEO
-
MPEG_VIDEO
-
OGG_VIDEO
-
QUICKTIME
-
WEBM_VIDEO
-
WMV
-
FLV_VIDEO
Flash video. For more information, see this link. -
THREE_GPP_VIDEO
The 3GP multimedia container format. For more information, see 3GPP TS 26.244. -
THREE_GPP2_VIDEO
The 3G2 multimedia container format. For more information, see 3GPP2 C.S0050-B. -
APPLICATION_XML_UTF_8
-
ATOM_UTF_8
-
BZIP2
-
DART_UTF_8
Files in the dart. -
APPLE_PASSBOOK
-
EOT
Embedded OpenType fonts. This is registered with the IANA. -
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. -
FORM_DATA
-
MULTIPART_ALTERNATIVE
AMediaType
constant representingmultipart/alternative
media type. As described in RFC 1521: MIME Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies -
MULTIPART_DIGEST
AMediaType
constant representingmultipart/digest
media type. As described in RFC 1521: MIME Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies -
MULTIPART_ENCRYPTED
AMediaType
constant representingmultipart/encrypted
media type. As described in RFC 1847: Security Multiparts for MIME: Multipart/Signed and Multipart/Encrypted -
MULTIPART_FORM_DATA
AMediaType
constant representingmultipart/form-data
media type. As described in RFC 1867: Form-based File Upload in HTML -
MULTIPART_MIXED
AMediaType
constant representingmultipart/mixed
media type. As described in RFC 1521: MIME Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies -
MULTIPART_PARALLEL
AMediaType
constant representingmultipart/parallel
media type. As described in RFC 1521: MIME Part One: Mechanisms for Specifying and Describing the Format of Internet Message Bodies -
MULTIPART_RELATED
AMediaType
constant representingmultipart/related
media type. As described in RFC 2112: The MIME Multipart/Related Content-type -
MULTIPART_SIGNED
AMediaType
constant representingmultipart/signed
media type. As described in RFC 1847: Security Multiparts for MIME: Multipart/Signed and Multipart/Encrypted -
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. -
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. -
GEO_JSON
GeoJSON Format, a geospatial data interchange format based on JSON. -
GZIP
-
BROTLI
Brotli Compression format, a lossless data compression format. -
ZSTD
Zstandard Compression format, a lossless data compression format. -
HAL_JSON
-
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. -
JOSE
-
JOSE_JSON
-
JSON_UTF_8
-
JSON
-
JWT
-
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. -
JSON_SEQ
As described in RFC 7464, this constant (application/json-seq
) is used for expressing JSON text sequences. -
JSON_LINES
As described in JSON Lines, this constant is used for expressing JSON lines. -
MANIFEST_JSON_UTF_8
-
KML
-
KMZ
OGC KML (Keyhole Markup Language), compressed using the ZIP format into KMZ archives. -
MBOX
The mbox database format. -
APPLE_MOBILE_CONFIG
-
MICROSOFT_EXCEL
Microsoft Excel spreadsheets. -
MICROSOFT_OUTLOOK
Microsoft Outlook items. -
MICROSOFT_POWERPOINT
Microsoft Powerpoint presentations. -
MICROSOFT_WORD
Microsoft Word documents. -
MEDIA_PRESENTATION_DESCRIPTION
Media type for Dynamic Adaptive Streaming over HTTP (DASH). This is registered with the IANA. -
WASM_APPLICATION
WASM applications. For more information see the Web Assembly overview. -
NACL_APPLICATION
NaCl applications. For more information see the Developer Guide for Native Client Application Structure. -
NACL_PORTABLE_APPLICATION
NaCl portable applications. For more information see the Developer Guide for Native Client Application Structure. -
OCTET_STREAM
-
OGG_CONTAINER
-
OOXML_DOCUMENT
-
OOXML_PRESENTATION
-
OOXML_SHEET
-
OPENDOCUMENT_GRAPHICS
-
OPENDOCUMENT_PRESENTATION
-
OPENDOCUMENT_SPREADSHEET
-
OPENDOCUMENT_TEXT
-
OPENSEARCH_DESCRIPTION_UTF_8
OpenSearch Description files are XML files that describe how a website can be used as a search engine by consumers (e.g. web browsers). -
PDF
-
POSTSCRIPT
-
PROTOBUF
-
X_PROTOBUF
-
X_GOOGLE_PROTOBUF
-
RDF_XML_UTF_8
RDF/XML documents, which are XML serializations of Resource Description Framework graphs. -
RTF_UTF_8
-
SFNT
-
SHOCKWAVE_FLASH
-
SKETCHUP
skp
files produced by the 3D Modeling software 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 -
TAR
-
WOFF
-
WOFF2
RFC 8081 declaresfont/woff2
to be the correct media type for WOFF2, but this may be necessary in certain situations for compatibility. -
XHTML_UTF_8
-
XRD_UTF_8
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
-
FONT_COLLECTION
A collection of font outlines as defined by RFC 8081. -
FONT_OTF
Open Type Font Format (OTF) as defined by RFC 8081. -
FONT_SFNT
Spline or Scalable Font Format (SFNT). RFC 8081 declares this to be the correct media type for SFNT, butapplication/font-sfnt
may be necessary in certain situations for compatibility. -
FONT_TTF
True Type Font Format (TTF) as defined by RFC 8081. -
FONT_WOFF
Web Open Font Format (WOFF). RFC 8081 declares this to be the correct media type for WOFF, butapplication/font-woff
may be necessary in certain situations for compatibility. -
FONT_WOFF2
Web Open Font Format (WOFF2). RFC 8081 declares this to be the correct media type for WOFF2, butapplication/font-woff2
may be necessary in certain situations for compatibility. -
GRAPHQL
-
GRAPHQL_JSON
Deprecated.UseGRAPHQL_RESPONSE_JSON
if the client can recognize the media type.The GraphQL response content type is changed fromGRAPHQL_JSON
toGRAPHQL_RESPONSE_JSON
in this PR. Change media type -
GRAPHQL_RESPONSE_JSON
GraphQL over JSON which is the official GraphQL response content type.
-
-
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 aCharset
for the value of the charset parameter if it is specified.- Returns:
- the
Charset
, ornull
if the charset parameter is not 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
-
charset
Returns aCharset
for the value of the charset parameter if it is specified.- Returns:
- the
Charset
, ordefaultCharset
if the charset parameter is not 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
-
withParameters
Replaces all parameters with the given attribute with parameters using the given values. If there are no values, any existing parameters with the given attribute are removed.- Throws:
IllegalArgumentException
- if eitherattribute
orvalues
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(String, Iterable)
. 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 the name 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()Returnstrue
if either the type or subtype is the wildcard. -
numWildcards
public int numWildcards()Returns the number of wildcards of thisMediaType
. -
isMultipart
public boolean isMultipart()Returnstrue
if the type is multipart. Otherwisefalse
.- See Also:
-
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"
. -
isJson
public boolean isJson()Returnstrue
when the subtype isJSON
or ends with+json
. Otherwisefalse
.JSON.isJson() // true JSON_UTF_8.isJson() // true PLAIN_TEXT_UTF_8.isJson() // false MediaType.parse("application/graphql+json").isJson() // true
-
isProtobuf
public boolean isProtobuf()Returnstrue
when the subtype is one ofPROTOBUF
,X_PROTOBUF
andX_GOOGLE_PROTOBUF
. Otherwisefalse
.PROTOBUF.isProtobuf() // true X_PROTOBUF.isProtobuf() // true X_GOOGLE_PROTOBUF.isProtobuf() // true
-
belongsTo
Returnstrue
if thisMediaType
belongs to the givenMediaType
. Similar to whatis(MediaType)
does except that this one compares the parameters case-insensitively and excludes 'q' parameter. -
qualityFactor
public float qualityFactor(float defaultValueIfNotSpecified) Returns the quality factor of thisMediaType
. If it is not specified,defaultValueIfNotSpecified
will be returned. -
qualityFactor
public float qualityFactor()Returns the quality factor of thisMediaType
. If it is not specified,1.0f
will be returned. -
nameWithoutParameters
Returns a name of thisMediaType
only consisting of the type and the sub type. -
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.
-
GRAPHQL_RESPONSE_JSON
if the client can recognize the media type.