public class MediaType extends MimeType implements Serializable
MimeType
that adds support for quality parameters
as defined in the HTTP specification.MimeType.SpecificityComparator<T extends MimeType>
Modifier and Type | Field and Description |
---|---|
static MediaType |
ALL
Public constant media type that includes all media ranges (i.e.
|
static String |
ALL_VALUE
A String equivalent of
ALL . |
static MediaType |
APPLICATION_ATOM_XML
Public constant media type for
application/atom+xml . |
static String |
APPLICATION_ATOM_XML_VALUE
A String equivalent of
APPLICATION_ATOM_XML . |
static MediaType |
APPLICATION_CBOR
Public constant media type for
application/cbor . |
static String |
APPLICATION_CBOR_VALUE
A String equivalent of
APPLICATION_CBOR . |
static MediaType |
APPLICATION_FORM_URLENCODED
Public constant media type for
application/x-www-form-urlencoded . |
static String |
APPLICATION_FORM_URLENCODED_VALUE
A String equivalent of
APPLICATION_FORM_URLENCODED . |
static MediaType |
APPLICATION_GRAPHQL
Public constant media type for
application/graphql+json . |
static String |
APPLICATION_GRAPHQL_VALUE
A String equivalent of
APPLICATION_GRAPHQL . |
static MediaType |
APPLICATION_JSON
Public constant media type for
application/json . |
static MediaType |
APPLICATION_JSON_UTF8
Deprecated.
as of 5.2 in favor of
APPLICATION_JSON
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8 parameter. |
static String |
APPLICATION_JSON_UTF8_VALUE
Deprecated.
as of 5.2 in favor of
APPLICATION_JSON_VALUE
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8 parameter. |
static String |
APPLICATION_JSON_VALUE
A String equivalent of
APPLICATION_JSON . |
static MediaType |
APPLICATION_NDJSON
Public constant media type for
application/x-ndjson . |
static String |
APPLICATION_NDJSON_VALUE
A String equivalent of
APPLICATION_NDJSON . |
static MediaType |
APPLICATION_OCTET_STREAM
Public constant media type for
application/octet-stream . |
static String |
APPLICATION_OCTET_STREAM_VALUE
A String equivalent of
APPLICATION_OCTET_STREAM . |
static MediaType |
APPLICATION_PDF
Public constant media type for
application/pdf . |
static String |
APPLICATION_PDF_VALUE
A String equivalent of
APPLICATION_PDF . |
static MediaType |
APPLICATION_PROBLEM_JSON
Public constant media type for
application/problem+json . |
static MediaType |
APPLICATION_PROBLEM_JSON_UTF8
Deprecated.
as of 5.2 in favor of
APPLICATION_PROBLEM_JSON
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8 parameter. |
static String |
APPLICATION_PROBLEM_JSON_UTF8_VALUE
Deprecated.
as of 5.2 in favor of
APPLICATION_PROBLEM_JSON_VALUE
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8 parameter. |
static String |
APPLICATION_PROBLEM_JSON_VALUE
A String equivalent of
APPLICATION_PROBLEM_JSON . |
static MediaType |
APPLICATION_PROBLEM_XML
Public constant media type for
application/problem+xml . |
static String |
APPLICATION_PROBLEM_XML_VALUE
A String equivalent of
APPLICATION_PROBLEM_XML . |
static MediaType |
APPLICATION_RSS_XML
Public constant media type for
application/rss+xml . |
static String |
APPLICATION_RSS_XML_VALUE
A String equivalent of
APPLICATION_RSS_XML . |
static MediaType |
APPLICATION_STREAM_JSON
Deprecated.
as of 5.3, see notice on
APPLICATION_STREAM_JSON_VALUE . |
static String |
APPLICATION_STREAM_JSON_VALUE
Deprecated.
as of 5.3 since it originates from the W3C Activity Streams
specification which has a more specific purpose and has been since
replaced with a different mime type. Use
APPLICATION_NDJSON as
a replacement or any other line-delimited JSON format (e.g. JSON Lines,
JSON Text Sequences). |
static MediaType |
APPLICATION_XHTML_XML
Public constant media type for
application/xhtml+xml . |
static String |
APPLICATION_XHTML_XML_VALUE
A String equivalent of
APPLICATION_XHTML_XML . |
static MediaType |
APPLICATION_XML
Public constant media type for
application/xml . |
static String |
APPLICATION_XML_VALUE
A String equivalent of
APPLICATION_XML . |
static MediaType |
IMAGE_GIF
Public constant media type for
image/gif . |
static String |
IMAGE_GIF_VALUE
A String equivalent of
IMAGE_GIF . |
static MediaType |
IMAGE_JPEG
Public constant media type for
image/jpeg . |
static String |
IMAGE_JPEG_VALUE
A String equivalent of
IMAGE_JPEG . |
static MediaType |
IMAGE_PNG
Public constant media type for
image/png . |
static String |
IMAGE_PNG_VALUE
A String equivalent of
IMAGE_PNG . |
static MediaType |
MULTIPART_FORM_DATA
Public constant media type for
multipart/form-data . |
static String |
MULTIPART_FORM_DATA_VALUE
A String equivalent of
MULTIPART_FORM_DATA . |
static MediaType |
MULTIPART_MIXED
Public constant media type for
multipart/mixed . |
static String |
MULTIPART_MIXED_VALUE
A String equivalent of
MULTIPART_MIXED . |
static MediaType |
MULTIPART_RELATED
Public constant media type for
multipart/related . |
static String |
MULTIPART_RELATED_VALUE
A String equivalent of
MULTIPART_RELATED . |
static Comparator<MediaType> |
QUALITY_VALUE_COMPARATOR
Comparator used by
sortByQualityValue(List) . |
static Comparator<MediaType> |
SPECIFICITY_COMPARATOR
Comparator used by
sortBySpecificity(List) . |
static MediaType |
TEXT_EVENT_STREAM
Public constant media type for
text/event-stream . |
static String |
TEXT_EVENT_STREAM_VALUE
A String equivalent of
TEXT_EVENT_STREAM . |
static MediaType |
TEXT_HTML
Public constant media type for
text/html . |
static String |
TEXT_HTML_VALUE
A String equivalent of
TEXT_HTML . |
static MediaType |
TEXT_MARKDOWN
Public constant media type for
text/markdown . |
static String |
TEXT_MARKDOWN_VALUE
A String equivalent of
TEXT_MARKDOWN . |
static MediaType |
TEXT_PLAIN
Public constant media type for
text/plain . |
static String |
TEXT_PLAIN_VALUE
A String equivalent of
TEXT_PLAIN . |
static MediaType |
TEXT_XML
Public constant media type for
text/xml . |
static String |
TEXT_XML_VALUE
A String equivalent of
TEXT_XML . |
WILDCARD_TYPE
Constructor and Description |
---|
MediaType(MediaType other,
Charset charset)
Copy-constructor that copies the type, subtype and parameters of the given
MediaType , and allows to set the specified character set. |
MediaType(MediaType other,
Map<String,String> parameters)
Copy-constructor that copies the type and subtype of the given
MediaType ,
and allows for different parameters. |
MediaType(MimeType mimeType)
Create a new
MediaType for the given MimeType . |
MediaType(String type)
Create a new
MediaType for the given primary type. |
MediaType(String type,
String subtype)
Create a new
MediaType for the given primary type and subtype. |
MediaType(String type,
String subtype,
Charset charset)
Create a new
MediaType for the given type, subtype, and character set. |
MediaType(String type,
String subtype,
double qualityValue)
Create a new
MediaType for the given type, subtype, and quality value. |
MediaType(String type,
String subtype,
Map<String,String> parameters)
Create a new
MediaType for the given type, subtype, and parameters. |
Modifier and Type | Method and Description |
---|---|
static MediaType |
asMediaType(MimeType mimeType)
Re-create the given mime type as a media type.
|
static List<MediaType> |
asMediaTypes(List<MimeType> mimeTypes)
Re-create the given mime types as media types.
|
protected void |
checkParameters(String parameter,
String value) |
MediaType |
copyQualityValue(MediaType mediaType)
Return a replica of this instance with the quality value of the given
MediaType . |
double |
getQualityValue()
Return the quality factor, as indicated by a
q parameter, if any. |
boolean |
includes(MediaType other)
Indicate whether this
MediaType includes the given media type. |
boolean |
isCompatibleWith(MediaType other)
Indicate whether this
MediaType is compatible with the given media type. |
static MediaType |
parseMediaType(String mediaType)
Parse the given String into a single
MediaType . |
static List<MediaType> |
parseMediaTypes(List<String> mediaTypes)
Parse the given list of (potentially) comma-separated strings into a
list of
MediaType objects. |
static List<MediaType> |
parseMediaTypes(String mediaTypes)
Parse the comma-separated string into a list of
MediaType objects. |
MediaType |
removeQualityValue()
Return a replica of this instance with its quality value removed.
|
static void |
sortByQualityValue(List<MediaType> mediaTypes)
Sorts the given list of
MediaType objects by quality value. |
static void |
sortBySpecificity(List<MediaType> mediaTypes)
Sorts the given list of
MediaType objects by specificity. |
static void |
sortBySpecificityAndQuality(List<MediaType> mediaTypes)
Sorts the given list of
MediaType objects by specificity as the
primary criteria and quality value the secondary. |
static String |
toString(Collection<MediaType> mediaTypes)
Return a string representation of the given list of
MediaType objects. |
static MediaType |
valueOf(String value)
Parse the given String value into a
MediaType object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService . |
appendTo, compareTo, equals, equalsTypeAndSubtype, getCharset, getParameter, getParameters, getSubtype, getSubtypeSuffix, getType, hashCode, includes, isCompatibleWith, isConcrete, isPresentIn, isWildcardSubtype, isWildcardType, toString, unquote
public static final MediaType ALL
public static final String ALL_VALUE
ALL
.public static final MediaType APPLICATION_ATOM_XML
application/atom+xml
.public static final String APPLICATION_ATOM_XML_VALUE
APPLICATION_ATOM_XML
.public static final MediaType APPLICATION_CBOR
application/cbor
.public static final String APPLICATION_CBOR_VALUE
APPLICATION_CBOR
.public static final MediaType APPLICATION_FORM_URLENCODED
application/x-www-form-urlencoded
.public static final String APPLICATION_FORM_URLENCODED_VALUE
APPLICATION_FORM_URLENCODED
.public static final MediaType APPLICATION_GRAPHQL
application/graphql+json
.public static final String APPLICATION_GRAPHQL_VALUE
APPLICATION_GRAPHQL
.public static final MediaType APPLICATION_JSON
application/json
.public static final String APPLICATION_JSON_VALUE
APPLICATION_JSON
.APPLICATION_JSON_UTF8_VALUE
,
Constant Field Values@Deprecated public static final MediaType APPLICATION_JSON_UTF8
APPLICATION_JSON
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8
parameter.application/json;charset=UTF-8
.@Deprecated public static final String APPLICATION_JSON_UTF8_VALUE
APPLICATION_JSON_VALUE
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8
parameter.APPLICATION_JSON_UTF8
.public static final MediaType APPLICATION_OCTET_STREAM
application/octet-stream
.public static final String APPLICATION_OCTET_STREAM_VALUE
APPLICATION_OCTET_STREAM
.public static final MediaType APPLICATION_PDF
application/pdf
.public static final String APPLICATION_PDF_VALUE
APPLICATION_PDF
.public static final MediaType APPLICATION_PROBLEM_JSON
application/problem+json
.public static final String APPLICATION_PROBLEM_JSON_VALUE
APPLICATION_PROBLEM_JSON
.@Deprecated public static final MediaType APPLICATION_PROBLEM_JSON_UTF8
APPLICATION_PROBLEM_JSON
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8
parameter.application/problem+json
.@Deprecated public static final String APPLICATION_PROBLEM_JSON_UTF8_VALUE
APPLICATION_PROBLEM_JSON_VALUE
since major browsers like Chrome
now comply with the specification and interpret correctly UTF-8 special
characters without requiring a charset=UTF-8
parameter.APPLICATION_PROBLEM_JSON_UTF8
.public static final MediaType APPLICATION_PROBLEM_XML
application/problem+xml
.public static final String APPLICATION_PROBLEM_XML_VALUE
APPLICATION_PROBLEM_XML
.public static final MediaType APPLICATION_RSS_XML
application/rss+xml
.public static final String APPLICATION_RSS_XML_VALUE
APPLICATION_RSS_XML
.public static final MediaType APPLICATION_NDJSON
application/x-ndjson
.public static final String APPLICATION_NDJSON_VALUE
APPLICATION_NDJSON
.@Deprecated public static final MediaType APPLICATION_STREAM_JSON
APPLICATION_STREAM_JSON_VALUE
.application/stream+json
.@Deprecated public static final String APPLICATION_STREAM_JSON_VALUE
APPLICATION_NDJSON
as
a replacement or any other line-delimited JSON format (e.g. JSON Lines,
JSON Text Sequences).APPLICATION_STREAM_JSON
.public static final MediaType APPLICATION_XHTML_XML
application/xhtml+xml
.public static final String APPLICATION_XHTML_XML_VALUE
APPLICATION_XHTML_XML
.public static final MediaType APPLICATION_XML
application/xml
.public static final String APPLICATION_XML_VALUE
APPLICATION_XML
.public static final MediaType IMAGE_GIF
image/gif
.public static final String IMAGE_GIF_VALUE
IMAGE_GIF
.public static final MediaType IMAGE_JPEG
image/jpeg
.public static final String IMAGE_JPEG_VALUE
IMAGE_JPEG
.public static final MediaType IMAGE_PNG
image/png
.public static final String IMAGE_PNG_VALUE
IMAGE_PNG
.public static final MediaType MULTIPART_FORM_DATA
multipart/form-data
.public static final String MULTIPART_FORM_DATA_VALUE
MULTIPART_FORM_DATA
.public static final MediaType MULTIPART_MIXED
multipart/mixed
.public static final String MULTIPART_MIXED_VALUE
MULTIPART_MIXED
.public static final MediaType MULTIPART_RELATED
multipart/related
.public static final String MULTIPART_RELATED_VALUE
MULTIPART_RELATED
.public static final MediaType TEXT_EVENT_STREAM
text/event-stream
.public static final String TEXT_EVENT_STREAM_VALUE
TEXT_EVENT_STREAM
.public static final MediaType TEXT_HTML
text/html
.public static final String TEXT_HTML_VALUE
TEXT_HTML
.public static final MediaType TEXT_MARKDOWN
text/markdown
.public static final String TEXT_MARKDOWN_VALUE
TEXT_MARKDOWN
.public static final MediaType TEXT_PLAIN
text/plain
.public static final String TEXT_PLAIN_VALUE
TEXT_PLAIN
.public static final MediaType TEXT_XML
text/xml
.public static final String TEXT_XML_VALUE
TEXT_XML
.public static final Comparator<MediaType> QUALITY_VALUE_COMPARATOR
sortByQualityValue(List)
.public static final Comparator<MediaType> SPECIFICITY_COMPARATOR
sortBySpecificity(List)
.public MediaType(String type)
MediaType
for the given primary type.
The subtype is set to "*", parameters empty.
type
- the primary typeIllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype)
MediaType
for the given primary type and subtype.
The parameters are empty.
type
- the primary typesubtype
- the subtypeIllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype, Charset charset)
MediaType
for the given type, subtype, and character set.type
- the primary typesubtype
- the subtypecharset
- the character setIllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype, double qualityValue)
MediaType
for the given type, subtype, and quality value.type
- the primary typesubtype
- the subtypequalityValue
- the quality valueIllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(MediaType other, Charset charset)
MediaType
, and allows to set the specified character set.other
- the other media typecharset
- the character setIllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(MediaType other, @Nullable Map<String,String> parameters)
MediaType
,
and allows for different parameters.other
- the other media typeparameters
- the parameters, may be null
IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype, @Nullable Map<String,String> parameters)
MediaType
for the given type, subtype, and parameters.type
- the primary typesubtype
- the subtypeparameters
- the parameters, may be null
IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(MimeType mimeType)
MediaType
for the given MimeType
.
The type, subtype and parameters information is copied and MediaType
-specific
checks on parameters are performed.mimeType
- the MIME typeIllegalArgumentException
- if any of the parameters contain illegal charactersprotected void checkParameters(String parameter, String value)
checkParameters
in class MimeType
public double getQualityValue()
q
parameter, if any.
Defaults to 1.0
.public boolean includes(@Nullable MediaType other)
MediaType
includes the given media type.
For instance, text/*
includes text/plain
and text/html
,
and application/*+xml
includes application/soap+xml
, etc.
This method is not symmetric.
Simply calls MimeType.includes(MimeType)
but declared with a
MediaType
parameter for binary backwards compatibility.
other
- the reference media type with which to comparetrue
if this media type includes the given media type;
false
otherwisepublic boolean isCompatibleWith(@Nullable MediaType other)
MediaType
is compatible with the given media type.
For instance, text/*
is compatible with text/plain
,
text/html
, and vice versa. In effect, this method is similar to
includes(org.springframework.http.MediaType)
, except that it is symmetric.
Simply calls MimeType.isCompatibleWith(MimeType)
but declared with a
MediaType
parameter for binary backwards compatibility.
other
- the reference media type with which to comparetrue
if this media type is compatible with the given media type;
false
otherwisepublic MediaType copyQualityValue(MediaType mediaType)
MediaType
.public MediaType removeQualityValue()
public static MediaType valueOf(String value)
MediaType
object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService
.value
- the string to parseInvalidMediaTypeException
- if the media type value cannot be parsedparseMediaType(String)
public static MediaType parseMediaType(String mediaType)
MediaType
.mediaType
- the string to parseInvalidMediaTypeException
- if the media type value cannot be parsedpublic static List<MediaType> parseMediaTypes(@Nullable String mediaTypes)
MediaType
objects.
This method can be used to parse an Accept or Content-Type header.
mediaTypes
- the string to parseInvalidMediaTypeException
- if the media type value cannot be parsedpublic static List<MediaType> parseMediaTypes(@Nullable List<String> mediaTypes)
MediaType
objects.
This method can be used to parse an Accept or Content-Type header.
mediaTypes
- the string to parseInvalidMediaTypeException
- if the media type value cannot be parsedpublic static List<MediaType> asMediaTypes(List<MimeType> mimeTypes)
public static MediaType asMediaType(MimeType mimeType)
public static String toString(Collection<MediaType> mediaTypes)
MediaType
objects.
This method can be used to for an Accept
or Content-Type
header.
mediaTypes
- the media types to create a string representation forpublic static void sortBySpecificity(List<MediaType> mediaTypes)
MediaType
objects by specificity.
Given two media types:
For example:
audio/basic < audio/* < */*
audio/* < audio/*;q=0.7; audio/*;q=0.3
audio/basic;level=1 < audio/basic
audio/basic == text/html
audio/basic == audio/wave
mediaTypes
- the list of media types to be sortedpublic static void sortByQualityValue(List<MediaType> mediaTypes)
MediaType
objects by quality value.
Given two media types:
mediaTypes
- the list of media types to be sortedgetQualityValue()
public static void sortBySpecificityAndQuality(List<MediaType> mediaTypes)
MediaType
objects by specificity as the
primary criteria and quality value the secondary.sortBySpecificity(List)
,
sortByQualityValue(List)