java.lang.Object | |
↳ | org.springframework.http.MediaType |
Represents an Internet Media Type, as defined in the HTTP specification.
Consists of a type
and a subtype
.
Also has functionality to parse media types from a string using parseMediaType(String)
,
or multiple comma-separated media types using parseMediaTypes(String)
.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
ALL | Public constant media type that includes all media ranges (i.e. | ||||||||||
APPLICATION_ATOM_XML | Public constant media type for application/atom+xml . |
||||||||||
APPLICATION_FORM_URLENCODED | Public constant media type for application/x-www-form-urlencoded . |
||||||||||
APPLICATION_JSON | Public constant media type for application/json . |
||||||||||
APPLICATION_OCTET_STREAM | Public constant media type for application/octet-stream . |
||||||||||
APPLICATION_XHTML_XML | Public constant media type for application/xhtml+xml . |
||||||||||
APPLICATION_XML | Public constant media type for application/xml . |
||||||||||
IMAGE_GIF | Public constant media type for image/gif . |
||||||||||
IMAGE_JPEG | Public constant media type for image/jpeg . |
||||||||||
IMAGE_PNG | Public constant media type for image/png . |
||||||||||
MULTIPART_FORM_DATA | Public constant media type for multipart/form-data . |
||||||||||
TEXT_HTML | Public constant media type for text/html . |
||||||||||
TEXT_PLAIN | Public constant media type for text/plain . |
||||||||||
TEXT_XML | Public constant media type for text/xml . |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a new
MediaType for the given primary type. | |||||||||||
Create a new
MediaType for the given primary type and subtype. | |||||||||||
Create a new
MediaType for the given type, subtype, and character set. | |||||||||||
Create a new
MediaType for the given type, subtype, and quality value. | |||||||||||
Copy-constructor that copies the type and subtype of the given
MediaType ,
and allows for different parameter. | |||||||||||
Create a new
MediaType for the given type, subtype, and parameters. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compares this
MediaType to another alphabetically. | |||||||||||
Return the character set, as indicated by a
charset parameter, if any. | |||||||||||
Return a generic parameter value, given a parameter name.
| |||||||||||
Return the quality value, as indicated by a
q parameter, if any. | |||||||||||
Return the subtype.
| |||||||||||
Return the primary type.
| |||||||||||
Indicate whether this
MediaType includes the given media type. | |||||||||||
Indicate whether this
MediaType is compatible with the given media type. | |||||||||||
Indicate whether the
subtype is the wildcard character * or not. | |||||||||||
Indicate whether the
type is the wildcard character * or not. | |||||||||||
Parse the given String into a single
MediaType . | |||||||||||
Parse the given, comma-seperated string into a list of
MediaType objects. | |||||||||||
Sorts the given list of
MediaType objects by quality value. | |||||||||||
Sorts the given list of
MediaType objects by specificity. | |||||||||||
Return a string representation of the given list of
MediaType objects. | |||||||||||
Parse the given String value into a
MediaType object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Comparable
|
Public constant media type that includes all media ranges (i.e. */*
).
Public constant media type for application/atom+xml
.
Public constant media type for application/x-www-form-urlencoded
.
Public constant media type for application/octet-stream
.
Public constant media type for application/xhtml+xml
.
Public constant media type for multipart/form-data
.
type | the primary type |
---|
IllegalArgumentException | if any of the parameters contain illegal characters |
---|
Create a new MediaType
for the given primary type and subtype.
The parameters are empty.
type | the primary type |
---|---|
subtype | the subtype |
IllegalArgumentException | if any of the parameters contain illegal characters |
---|
Create a new MediaType
for the given type, subtype, and character set.
type | the primary type |
---|---|
subtype | the subtype |
charSet | the character set |
IllegalArgumentException | if any of the parameters contain illegal characters |
---|
Create a new MediaType
for the given type, subtype, and quality value.
type | the primary type |
---|---|
subtype | the subtype |
qualityValue | the quality value |
IllegalArgumentException | if any of the parameters contain illegal characters |
---|
Copy-constructor that copies the type and subtype of the given MediaType
,
and allows for different parameter.
other | the other media type |
---|---|
parameters | the parameters, may be null |
IllegalArgumentException | if any of the parameters contain illegal characters |
---|
Create a new MediaType
for the given type, subtype, and parameters.
type | the primary type |
---|---|
subtype | the subtype |
parameters | the parameters, may be null |
IllegalArgumentException | if any of the parameters contain illegal characters |
---|
Compares this MediaType
to another alphabetically.
other | media type to compare to |
---|
Return the character set, as indicated by a charset
parameter, if any.
null
if not available
Return a generic parameter value, given a parameter name.
name | the parameter name |
---|
null
if not present
Return the quality value, as indicated by a q
parameter, if any.
Defaults to 1.0
.
Indicate whether this MediaType
includes the given media type.
For instance, text/*
includes text/plain
, text/html
, and application/*+xml
includes application/soap+xml
, etc. This method is non-symmetic.
other | the reference media type with which to compare |
---|
true
if this media type includes the given media type; false
otherwise
Indicate whether this 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(MediaType)
, except that it's symmetric.
other | the reference media type with which to compare |
---|
true
if this media type is compatible with the given media type; false
otherwise
Indicate whether the subtype
is the wildcard character *
or not.
*
Parse the given String into a single MediaType
.
mediaType | the string to parse |
---|
IllegalArgumentException | if the string cannot be parsed |
---|
Parse the given, comma-seperated string into a list of MediaType
objects.
This method can be used to parse an Accept or Content-Type header.
mediaTypes | the string to parse |
---|
IllegalArgumentException | if the string cannot be parsed |
---|
Sorts the given list of MediaType
objects by quality value.
Given two media types:
quality value
, then the media type
with the highest quality value is ordered before the other.wildcard type
, then the media type without the
wildcard is ordered before the other.types
, then they are considered equal and
remain their current order.wildcard subtype
, then the media type without
the wildcard is sorted before the other.subtypes
, then they are considered equal
and remain their current order.parameters
, then the
media type with the most parameters is ordered before the other.mediaTypes | the list of media types to be sorted |
---|
Sorts the given list of MediaType
objects by specificity.
Given two media types:
wildcard type
, then the media type without the
wildcard is ordered before the other.types
, then they are considered equal and
remain their current order.wildcard subtype
, then the media type without
the wildcard is sorted before the other.subtypes
, then they are considered equal
and remain their current order.quality value
, then the media type
with the highest quality value is ordered before the other.parameters
, then the
media type with the most parameters is ordered before the other.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 sorted |
---|
Return a string representation of the given list of MediaType
objects.
This method can be used to for an Accept
or Content-Type
header.
mediaTypes | the string to parse |
---|
IllegalArgumentException | if the String cannot be parsed |
---|
Parse the given String value into a MediaType
object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService
.