类 MediaType
- java.lang.Object
- org.springframework.util.MimeType
- org.springframework.http.MediaType
- 所有已实现的接口:
Serializable
,Comparable<MimeType>
public class MediaType extends MimeType implements Serializable
A subclass ofMimeType
that adds support for quality parameters as defined in the HTTP specification.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sebastien Deleuze, Kazuki Shimizu, Sam Brannen
- 另请参阅:
- HTTP 1.1: Semantics and Content, section 3.1.1.1, 序列化表格
嵌套类概要
从类继承的嵌套类/接口 org.springframework.util.MimeType
MimeType.SpecificityComparator<T extends MimeType>
字段概要
字段 修饰符和类型 字段 说明 static MediaType
ALL
Public constant media type that includes all media ranges (i.estatic String
ALL_VALUE
A String equivalent ofALL
.static MediaType
APPLICATION_ATOM_XML
Public constant media type forapplication/atom+xml
.static String
APPLICATION_ATOM_XML_VALUE
A String equivalent ofAPPLICATION_ATOM_XML
.static MediaType
APPLICATION_CBOR
Public constant media type forapplication/cbor
.static String
APPLICATION_CBOR_VALUE
A String equivalent ofAPPLICATION_CBOR
.static MediaType
APPLICATION_FORM_URLENCODED
Public constant media type forapplication/x-www-form-urlencoded
.static String
APPLICATION_FORM_URLENCODED_VALUE
A String equivalent ofAPPLICATION_FORM_URLENCODED
.static MediaType
APPLICATION_JSON
Public constant media type forapplication/json
.static MediaType
APPLICATION_JSON_UTF8
已过时。as of 5.2 in favor ofAPPLICATION_JSON
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.static String
APPLICATION_JSON_UTF8_VALUE
已过时。as of 5.2 in favor ofAPPLICATION_JSON_VALUE
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.static String
APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON
.static MediaType
APPLICATION_OCTET_STREAM
Public constant media type forapplication/octet-stream
.static String
APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM
.static MediaType
APPLICATION_PDF
Public constant media type forapplication/pdf
.static String
APPLICATION_PDF_VALUE
A String equivalent ofAPPLICATION_PDF
.static MediaType
APPLICATION_PROBLEM_JSON
Public constant media type forapplication/problem+json
.static MediaType
APPLICATION_PROBLEM_JSON_UTF8
已过时。as of 5.2 in favor ofAPPLICATION_PROBLEM_JSON
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.static String
APPLICATION_PROBLEM_JSON_UTF8_VALUE
已过时。as of 5.2 in favor ofAPPLICATION_PROBLEM_JSON_VALUE
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.static String
APPLICATION_PROBLEM_JSON_VALUE
A String equivalent ofAPPLICATION_PROBLEM_JSON
.static MediaType
APPLICATION_PROBLEM_XML
Public constant media type forapplication/problem+xml
.static String
APPLICATION_PROBLEM_XML_VALUE
A String equivalent ofAPPLICATION_PROBLEM_XML
.static MediaType
APPLICATION_RSS_XML
Public constant media type forapplication/rss+xml
.static String
APPLICATION_RSS_XML_VALUE
A String equivalent ofAPPLICATION_RSS_XML
.static MediaType
APPLICATION_STREAM_JSON
Public constant media type forapplication/stream+json
.static String
APPLICATION_STREAM_JSON_VALUE
A String equivalent ofAPPLICATION_STREAM_JSON
.static MediaType
APPLICATION_XHTML_XML
Public constant media type forapplication/xhtml+xml
.static String
APPLICATION_XHTML_XML_VALUE
A String equivalent ofAPPLICATION_XHTML_XML
.static MediaType
APPLICATION_XML
Public constant media type forapplication/xml
.static String
APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML
.static MediaType
IMAGE_GIF
Public constant media type forimage/gif
.static String
IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF
.static MediaType
IMAGE_JPEG
Public constant media type forimage/jpeg
.static String
IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG
.static MediaType
IMAGE_PNG
Public constant media type forimage/png
.static String
IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG
.static MediaType
MULTIPART_FORM_DATA
Public constant media type formultipart/form-data
.static String
MULTIPART_FORM_DATA_VALUE
A String equivalent ofMULTIPART_FORM_DATA
.static MediaType
MULTIPART_MIXED
Public constant media type formultipart/mixed
.static String
MULTIPART_MIXED_VALUE
A String equivalent ofMULTIPART_MIXED
.static MediaType
MULTIPART_RELATED
Public constant media type formultipart/related
.static String
MULTIPART_RELATED_VALUE
A String equivalent ofMULTIPART_RELATED
.static Comparator<MediaType>
QUALITY_VALUE_COMPARATOR
Comparator used bysortByQualityValue(List)
.static Comparator<MediaType>
SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List)
.static MediaType
TEXT_EVENT_STREAM
Public constant media type fortext/event-stream
.static String
TEXT_EVENT_STREAM_VALUE
A String equivalent ofTEXT_EVENT_STREAM
.static MediaType
TEXT_HTML
Public constant media type fortext/html
.static String
TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML
.static MediaType
TEXT_MARKDOWN
Public constant media type fortext/markdown
.static String
TEXT_MARKDOWN_VALUE
A String equivalent ofTEXT_MARKDOWN
.static MediaType
TEXT_PLAIN
Public constant media type fortext/plain
.static String
TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN
.static MediaType
TEXT_XML
Public constant media type fortext/xml
.static String
TEXT_XML_VALUE
A String equivalent ofTEXT_XML
.从类继承的字段 org.springframework.util.MimeType
WILDCARD_TYPE
构造器概要
构造器 构造器 说明 MediaType(String type)
Create a newMediaType
for the given primary type.MediaType(String type, String subtype)
Create a newMediaType
for the given primary type and subtype.MediaType(String type, String subtype, double qualityValue)
Create a newMediaType
for the given type, subtype, and quality value.MediaType(String type, String subtype, Charset charset)
Create a newMediaType
for the given type, subtype, and character set.MediaType(String type, String subtype, Map<String,String> parameters)
Create a newMediaType
for the given type, subtype, and parameters.MediaType(MediaType other, Charset charset)
Copy-constructor that copies the type, subtype and parameters of the givenMediaType
, 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 givenMediaType
, and allows for different parameters.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 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 givenMediaType
.double
getQualityValue()
Return the quality factor, as indicated by aq
parameter, if any.boolean
includes(MediaType other)
Indicate whether thisMediaType
includes the given media type.boolean
isCompatibleWith(MediaType other)
Indicate whether thisMediaType
is compatible with the given media type.static MediaType
parseMediaType(String mediaType)
Parse the given String into a singleMediaType
.static List<MediaType>
parseMediaTypes(String mediaTypes)
Parse the comma-separated string into a list ofMediaType
objects.static List<MediaType>
parseMediaTypes(List<String> mediaTypes)
Parse the given list of (potentially) comma-separated strings into a list ofMediaType
objects.MediaType
removeQualityValue()
Return a replica of this instance with its quality value removed.static void
sortByQualityValue(List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by quality value.static void
sortBySpecificity(List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity.static void
sortBySpecificityAndQuality(List<MediaType> mediaTypes)
Sorts the given list ofMediaType
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 ofMediaType
objects.static MediaType
valueOf(String value)
Parse the given String value into aMediaType
object, with this method name following the 'valueOf' naming convention (as supported byConversionService
.从类继承的方法 org.springframework.util.MimeType
appendTo, compareTo, equals, equalsTypeAndSubtype, getCharset, getParameter, getParameters, getSubtype, getType, hashCode, includes, isCompatibleWith, isConcrete, isPresentIn, isWildcardSubtype, isWildcardType, toString, unquote
字段详细资料
ALL
public static final MediaType ALL
Public constant media type that includes all media ranges (i.e. "*/*").
APPLICATION_ATOM_XML
public static final MediaType APPLICATION_ATOM_XML
Public constant media type forapplication/atom+xml
.
APPLICATION_ATOM_XML_VALUE
public static final String APPLICATION_ATOM_XML_VALUE
A String equivalent ofAPPLICATION_ATOM_XML
.- 另请参阅:
- 常量字段值
APPLICATION_CBOR
public static final MediaType APPLICATION_CBOR
Public constant media type forapplication/cbor
.- 从以下版本开始:
- 5.2
APPLICATION_CBOR_VALUE
public static final String APPLICATION_CBOR_VALUE
A String equivalent ofAPPLICATION_CBOR
.- 从以下版本开始:
- 5.2
- 另请参阅:
- 常量字段值
APPLICATION_FORM_URLENCODED
public static final MediaType APPLICATION_FORM_URLENCODED
Public constant media type forapplication/x-www-form-urlencoded
.
APPLICATION_FORM_URLENCODED_VALUE
public static final String APPLICATION_FORM_URLENCODED_VALUE
A String equivalent ofAPPLICATION_FORM_URLENCODED
.- 另请参阅:
- 常量字段值
APPLICATION_JSON
public static final MediaType APPLICATION_JSON
Public constant media type forapplication/json
.
APPLICATION_JSON_VALUE
public static final String APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON
.
APPLICATION_JSON_UTF8
@Deprecated public static final MediaType APPLICATION_JSON_UTF8
已过时。as of 5.2 in favor ofAPPLICATION_JSON
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.Public constant media type forapplication/json;charset=UTF-8
.
APPLICATION_JSON_UTF8_VALUE
@Deprecated public static final String APPLICATION_JSON_UTF8_VALUE
已过时。as of 5.2 in favor ofAPPLICATION_JSON_VALUE
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.A String equivalent ofAPPLICATION_JSON_UTF8
.- 另请参阅:
- 常量字段值
APPLICATION_OCTET_STREAM
public static final MediaType APPLICATION_OCTET_STREAM
Public constant media type forapplication/octet-stream
.
APPLICATION_OCTET_STREAM_VALUE
public static final String APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM
.- 另请参阅:
- 常量字段值
APPLICATION_PDF
public static final MediaType APPLICATION_PDF
Public constant media type forapplication/pdf
.- 从以下版本开始:
- 4.3
APPLICATION_PDF_VALUE
public static final String APPLICATION_PDF_VALUE
A String equivalent ofAPPLICATION_PDF
.- 从以下版本开始:
- 4.3
- 另请参阅:
- 常量字段值
APPLICATION_PROBLEM_JSON
public static final MediaType APPLICATION_PROBLEM_JSON
Public constant media type forapplication/problem+json
.- 从以下版本开始:
- 5.0
- 另请参阅:
- Problem Details for HTTP APIs, 6.1. application/problem+json
APPLICATION_PROBLEM_JSON_VALUE
public static final String APPLICATION_PROBLEM_JSON_VALUE
A String equivalent ofAPPLICATION_PROBLEM_JSON
.- 从以下版本开始:
- 5.0
- 另请参阅:
- 常量字段值
APPLICATION_PROBLEM_JSON_UTF8
@Deprecated public static final MediaType APPLICATION_PROBLEM_JSON_UTF8
已过时。as of 5.2 in favor ofAPPLICATION_PROBLEM_JSON
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.Public constant media type forapplication/problem+json
.- 从以下版本开始:
- 5.0
- 另请参阅:
- Problem Details for HTTP APIs, 6.1. application/problem+json
APPLICATION_PROBLEM_JSON_UTF8_VALUE
@Deprecated public static final String APPLICATION_PROBLEM_JSON_UTF8_VALUE
已过时。as of 5.2 in favor ofAPPLICATION_PROBLEM_JSON_VALUE
since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring acharset=UTF-8
parameter.A String equivalent ofAPPLICATION_PROBLEM_JSON_UTF8
.- 从以下版本开始:
- 5.0
- 另请参阅:
- 常量字段值
APPLICATION_PROBLEM_XML
public static final MediaType APPLICATION_PROBLEM_XML
Public constant media type forapplication/problem+xml
.- 从以下版本开始:
- 5.0
- 另请参阅:
- Problem Details for HTTP APIs, 6.2. application/problem+xml
APPLICATION_PROBLEM_XML_VALUE
public static final String APPLICATION_PROBLEM_XML_VALUE
A String equivalent ofAPPLICATION_PROBLEM_XML
.- 从以下版本开始:
- 5.0
- 另请参阅:
- 常量字段值
APPLICATION_RSS_XML
public static final MediaType APPLICATION_RSS_XML
Public constant media type forapplication/rss+xml
.- 从以下版本开始:
- 4.3.6
APPLICATION_RSS_XML_VALUE
public static final String APPLICATION_RSS_XML_VALUE
A String equivalent ofAPPLICATION_RSS_XML
.- 从以下版本开始:
- 4.3.6
- 另请参阅:
- 常量字段值
APPLICATION_STREAM_JSON
public static final MediaType APPLICATION_STREAM_JSON
Public constant media type forapplication/stream+json
.- 从以下版本开始:
- 5.0
APPLICATION_STREAM_JSON_VALUE
public static final String APPLICATION_STREAM_JSON_VALUE
A String equivalent ofAPPLICATION_STREAM_JSON
.- 从以下版本开始:
- 5.0
- 另请参阅:
- 常量字段值
APPLICATION_XHTML_XML
public static final MediaType APPLICATION_XHTML_XML
Public constant media type forapplication/xhtml+xml
.
APPLICATION_XHTML_XML_VALUE
public static final String APPLICATION_XHTML_XML_VALUE
A String equivalent ofAPPLICATION_XHTML_XML
.- 另请参阅:
- 常量字段值
APPLICATION_XML
public static final MediaType APPLICATION_XML
Public constant media type forapplication/xml
.
APPLICATION_XML_VALUE
public static final String APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML
.- 另请参阅:
- 常量字段值
IMAGE_GIF_VALUE
public static final String IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF
.- 另请参阅:
- 常量字段值
IMAGE_JPEG
public static final MediaType IMAGE_JPEG
Public constant media type forimage/jpeg
.
IMAGE_JPEG_VALUE
public static final String IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG
.- 另请参阅:
- 常量字段值
IMAGE_PNG_VALUE
public static final String IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG
.- 另请参阅:
- 常量字段值
MULTIPART_FORM_DATA
public static final MediaType MULTIPART_FORM_DATA
Public constant media type formultipart/form-data
.
MULTIPART_FORM_DATA_VALUE
public static final String MULTIPART_FORM_DATA_VALUE
A String equivalent ofMULTIPART_FORM_DATA
.- 另请参阅:
- 常量字段值
MULTIPART_MIXED
public static final MediaType MULTIPART_MIXED
Public constant media type formultipart/mixed
.- 从以下版本开始:
- 5.2
MULTIPART_MIXED_VALUE
public static final String MULTIPART_MIXED_VALUE
A String equivalent ofMULTIPART_MIXED
.- 从以下版本开始:
- 5.2
- 另请参阅:
- 常量字段值
MULTIPART_RELATED
public static final MediaType MULTIPART_RELATED
Public constant media type formultipart/related
.- 从以下版本开始:
- 5.2.5
MULTIPART_RELATED_VALUE
public static final String MULTIPART_RELATED_VALUE
A String equivalent ofMULTIPART_RELATED
.- 从以下版本开始:
- 5.2.5
- 另请参阅:
- 常量字段值
TEXT_EVENT_STREAM
public static final MediaType TEXT_EVENT_STREAM
Public constant media type fortext/event-stream
.- 从以下版本开始:
- 4.3.6
- 另请参阅:
- Server-Sent Events W3C recommendation
TEXT_EVENT_STREAM_VALUE
public static final String TEXT_EVENT_STREAM_VALUE
A String equivalent ofTEXT_EVENT_STREAM
.- 从以下版本开始:
- 4.3.6
- 另请参阅:
- 常量字段值
TEXT_HTML_VALUE
public static final String TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML
.- 另请参阅:
- 常量字段值
TEXT_MARKDOWN
public static final MediaType TEXT_MARKDOWN
Public constant media type fortext/markdown
.- 从以下版本开始:
- 4.3
TEXT_MARKDOWN_VALUE
public static final String TEXT_MARKDOWN_VALUE
A String equivalent ofTEXT_MARKDOWN
.- 从以下版本开始:
- 4.3
- 另请参阅:
- 常量字段值
TEXT_PLAIN
public static final MediaType TEXT_PLAIN
Public constant media type fortext/plain
.
TEXT_PLAIN_VALUE
public static final String TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN
.- 另请参阅:
- 常量字段值
TEXT_XML_VALUE
public static final String TEXT_XML_VALUE
A String equivalent ofTEXT_XML
.- 另请参阅:
- 常量字段值
QUALITY_VALUE_COMPARATOR
public static final Comparator<MediaType> QUALITY_VALUE_COMPARATOR
Comparator used bysortByQualityValue(List)
.
SPECIFICITY_COMPARATOR
public static final Comparator<MediaType> SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List)
.
构造器详细资料
MediaType
public MediaType(String type)
Create a newMediaType
for the given primary type.The subtype is set to "*", parameters empty.
- 参数:
type
- the primary type- 抛出:
IllegalArgumentException
- if any of the parameters contain illegal characters
MediaType
public MediaType(String type, String subtype)
Create a newMediaType
for the given primary type and subtype.The parameters are empty.
- 参数:
type
- the primary typesubtype
- the subtype- 抛出:
IllegalArgumentException
- if any of the parameters contain illegal characters
MediaType
public MediaType(String type, String subtype, Charset charset)
Create a newMediaType
for the given type, subtype, and character set.- 参数:
type
- the primary typesubtype
- the subtypecharset
- the character set- 抛出:
IllegalArgumentException
- if any of the parameters contain illegal characters
MediaType
public MediaType(String type, String subtype, double qualityValue)
Create a newMediaType
for the given type, subtype, and quality value.- 参数:
type
- the primary typesubtype
- the subtypequalityValue
- the quality value- 抛出:
IllegalArgumentException
- if any of the parameters contain illegal characters
MediaType
public MediaType(MediaType other, Charset charset)
Copy-constructor that copies the type, subtype and parameters of the givenMediaType
, and allows to set the specified character set.- 参数:
other
- the other media typecharset
- the character set- 抛出:
IllegalArgumentException
- if any of the parameters contain illegal characters- 从以下版本开始:
- 4.3
MediaType
public MediaType(MediaType other, @Nullable Map<String,String> parameters)
Copy-constructor that copies the type and subtype of the givenMediaType
, and allows for different parameters.- 参数:
other
- the other media typeparameters
- the parameters, may benull
- 抛出:
IllegalArgumentException
- if any of the parameters contain illegal characters
MediaType
public MediaType(String type, String subtype, @Nullable Map<String,String> parameters)
Create a newMediaType
for the given type, subtype, and parameters.- 参数:
type
- the primary typesubtype
- the subtypeparameters
- the parameters, may benull
- 抛出:
IllegalArgumentException
- if any of the parameters contain illegal characters
方法详细资料
checkParameters
protected void checkParameters(String parameter, String value)
- 覆盖:
checkParameters
在类中MimeType
getQualityValue
public double getQualityValue()
Return the quality factor, as indicated by aq
parameter, if any. Defaults to1.0
.- 返回:
- the quality factor as double value
includes
public boolean includes(@Nullable MediaType other)
Indicate whether thisMediaType
includes the given media type.For instance,
text/*
includestext/plain
andtext/html
, andapplication/*+xml
includesapplication/soap+xml
, etc. This method is not symmetric.Simply calls
MimeType.includes(MimeType)
but declared with aMediaType
parameter for binary backwards compatibility.- 参数:
other
- the reference media type with which to compare- 返回:
true
if this media type includes the given media type;false
otherwise
isCompatibleWith
public boolean isCompatibleWith(@Nullable MediaType other)
Indicate whether thisMediaType
is compatible with the given media type.For instance,
text/*
is compatible withtext/plain
,text/html
, and vice versa. In effect, this method is similar toincludes(org.springframework.http.MediaType)
, except that it is symmetric.Simply calls
MimeType.isCompatibleWith(MimeType)
but declared with aMediaType
parameter for binary backwards compatibility.- 参数:
other
- the reference media type with which to compare- 返回:
true
if this media type is compatible with the given media type;false
otherwise
copyQualityValue
public MediaType copyQualityValue(MediaType mediaType)
Return a replica of this instance with the quality value of the givenMediaType
.- 返回:
- the same instance if the given MediaType doesn't have a quality value, or a new one otherwise
removeQualityValue
public MediaType removeQualityValue()
Return a replica of this instance with its quality value removed.- 返回:
- the same instance if the media type doesn't contain a quality value, or a new one otherwise
valueOf
public static MediaType valueOf(String value)
Parse the given String value into aMediaType
object, with this method name following the 'valueOf' naming convention (as supported byConversionService
.- 参数:
value
- the string to parse- 抛出:
InvalidMediaTypeException
- if the media type value cannot be parsed- 另请参阅:
parseMediaType(String)
parseMediaType
public static MediaType parseMediaType(String mediaType)
Parse the given String into a singleMediaType
.- 参数:
mediaType
- the string to parse- 返回:
- the media type
- 抛出:
InvalidMediaTypeException
- if the media type value cannot be parsed
parseMediaTypes
public static List<MediaType> parseMediaTypes(@Nullable String mediaTypes)
Parse the comma-separated string into a list ofMediaType
objects.This method can be used to parse an Accept or Content-Type header.
- 参数:
mediaTypes
- the string to parse- 返回:
- the list of media types
- 抛出:
InvalidMediaTypeException
- if the media type value cannot be parsed
parseMediaTypes
public static List<MediaType> parseMediaTypes(@Nullable List<String> mediaTypes)
Parse the given list of (potentially) comma-separated strings into a list ofMediaType
objects.This method can be used to parse an Accept or Content-Type header.
- 参数:
mediaTypes
- the string to parse- 返回:
- the list of media types
- 抛出:
InvalidMediaTypeException
- if the media type value cannot be parsed- 从以下版本开始:
- 4.3.2
asMediaTypes
public static List<MediaType> asMediaTypes(List<MimeType> mimeTypes)
Re-create the given mime types as media types.- 从以下版本开始:
- 5.0
asMediaType
public static MediaType asMediaType(MimeType mimeType)
Re-create the given mime type as a media type.- 从以下版本开始:
- 5.0
toString
public static String toString(Collection<MediaType> mediaTypes)
Return a string representation of the given list ofMediaType
objects.This method can be used to for an
Accept
orContent-Type
header.- 参数:
mediaTypes
- the media types to create a string representation for- 返回:
- the string representation
sortBySpecificity
public static void sortBySpecificity(List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity.Given two media types:
- if either media type has a wildcard type, then the media type without the wildcard is ordered before the other.
- if the two media types have different types, then they are considered equal and remain their current order.
- if either media type has a wildcard subtype, then the media type without the wildcard is sorted before the other.
- if the two media types have different subtypes, then they are considered equal and remain their current order.
- if the two media types have different quality value, then the media type with the highest quality value is ordered before the other.
- if the two media types have a different amount of 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- 另请参阅:
- HTTP 1.1: Semantics and Content, section 5.3.2
sortByQualityValue
public static void sortByQualityValue(List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by quality value.Given two media types:
- if the two media types have different quality value, then the media type with the highest quality value is ordered before the other.
- if either media type has a wildcard type, then the media type without the wildcard is ordered before the other.
- if the two media types have different types, then they are considered equal and remain their current order.
- if either media type has a wildcard subtype, then the media type without the wildcard is sorted before the other.
- if the two media types have different subtypes, then they are considered equal and remain their current order.
- if the two media types have a different amount of parameters, then the media type with the most parameters is ordered before the other.
- 参数:
mediaTypes
- the list of media types to be sorted- 另请参阅:
getQualityValue()
sortBySpecificityAndQuality
public static void sortBySpecificityAndQuality(List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity as the primary criteria and quality value the secondary.