类 MediaType
- 所有已实现的接口:
Serializable,Comparable<cn.taketoday.util.MimeType>
MimeType that adds support for quality parameters as
defined in the HTTP specification.- 从以下版本开始:
- 2.1.7 2019-12-08 20:02
- 作者:
- Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sebastien Deleuze, Kazuki Shimizu, Sam Brannen, Harry Yang
- 另请参阅:
-
嵌套类概要
从类继承的嵌套类/接口 cn.taketoday.util.MimeType
cn.taketoday.util.MimeType.SpecificityComparator<T extends cn.taketoday.util.MimeType> -
字段概要
字段修饰符和类型字段说明static final MediaTypePublic constant media type that includes all media ranges (i.estatic final StringA String equivalent ofALL.static final MediaTypePublic constant media type forapplication/atom+xml.static final StringA String equivalent ofAPPLICATION_ATOM_XML.static final MediaTypePublic constant media type forapplication/cbor.static final StringA String equivalent ofAPPLICATION_CBOR.static final MediaTypePublic constant media type forapplication/x-www-form-urlencoded.static final StringA String equivalent ofAPPLICATION_FORM_URLENCODED.static final MediaTypePublic constant media type forapplication/json.static final Stringstatic final StringA String equivalent ofAPPLICATION_JSON.static final MediaTypePublic constant media type forapplication/x-ndjson.static final StringA String equivalent ofAPPLICATION_NDJSON.static final MediaTypePublic constant media type forapplication/octet-stream.static final StringA String equivalent ofAPPLICATION_OCTET_STREAM.static final MediaTypePublic constant media type forapplication/pdf.static final StringA String equivalent ofAPPLICATION_PDF.static final MediaTypePublic constant media type forapplication/problem+json.static final StringA String equivalent ofAPPLICATION_PROBLEM_JSON.static final MediaTypePublic constant media type forapplication/problem+xml.static final StringA String equivalent ofAPPLICATION_PROBLEM_XML.static final MediaTypePublic constant media type forapplication/rss+xml.static final StringA String equivalent ofAPPLICATION_RSS_XML.static final MediaTypePublic constant media type forapplication/stream+json.static final StringA String equivalent ofAPPLICATION_STREAM_JSON.static final MediaTypePublic constant media type forapplication/xhtml+xml.static final StringA String equivalent ofAPPLICATION_XHTML_XML.static final MediaTypePublic constant media type forapplication/xml.static final StringA String equivalent ofAPPLICATION_XML.static final MediaTypePublic constant media type forimage/gif.static final StringA String equivalent ofIMAGE_GIF.static final MediaTypePublic constant media type forimage/jpeg.static final StringA String equivalent ofIMAGE_JPEG.static final MediaTypePublic constant media type forimage/png.static final StringA String equivalent ofIMAGE_PNG.static final MediaTypePublic constant media type formultipart/form-data.static final StringA String equivalent ofMULTIPART_FORM_DATA.static final MediaTypePublic constant media type formultipart/mixed.static final StringA String equivalent ofMULTIPART_MIXED.static final MediaTypePublic constant media type formultipart/related.static final StringA String equivalent ofMULTIPART_RELATED.private static final Stringstatic final Comparator<MediaType>Comparator used bysortByQualityValue(List).private static final longstatic final Comparator<MediaType>Comparator used bysortBySpecificity(List).static final MediaTypePublic constant media type fortext/event-stream.static final StringA String equivalent ofTEXT_EVENT_STREAM.static final MediaTypePublic constant media type fortext/html.static final StringA String equivalent ofTEXT_HTML.static final MediaTypePublic constant media type fortext/markdown.static final StringA String equivalent ofTEXT_MARKDOWN.static final MediaTypePublic constant media type fortext/plain.static final StringA String equivalent ofTEXT_PLAIN.static final MediaTypePublic constant media type fortext/xml.static final StringA String equivalent ofTEXT_XML.从类继承的字段 cn.taketoday.util.MimeType
WILDCARD_TYPE -
构造器概要
构造器构造器说明Copy-constructor that copies the type, subtype and parameters of the givenMediaType, and allows to set the specified character set.Copy-constructor that copies the type and subtype of the givenMediaType, and allows for different parameters.Create a newMediaTypefor the given primary type.Create a newMediaTypefor the given primary type and subtype.Create a newMediaTypefor the given type, subtype, and quality value.Create a newMediaTypefor the given type, subtype, and character set.Create a newMediaTypefor the given type, subtype, and parameters. -
方法概要
修饰符和类型方法说明static MediaTypeasMediaType(cn.taketoday.util.MimeType mimeType) Re-create the given mime type as a media type.asMediaTypes(List<cn.taketoday.util.MimeType> mimeTypes) Re-create the given mime types as media types.protected voidcheckParameters(String attribute, String value) copyQualityValue(MediaType mediaType) Return a replica of this instance with the quality value of the givenMediaType.static MediaTypefromFileName(String filename) Determine a media type for the given file name, if possible.static MediaTypefromResource(cn.taketoday.core.io.Resource resource) Determine a media type for the given resource, if possible.doubleReturn the quality factor, as indicated by aqparameter, if any.booleanIndicate whether thisMediaTypeincludes the given media type.booleanisCompatibleWith(MediaType other) Indicate whether thisMediaTypeis compatible with the given media type.booleanisLessSpecific(cn.taketoday.util.MimeType other) Indicates whether thisMediaTypemore specific than the given type.booleanisMoreSpecific(cn.taketoday.util.MimeType other) Indicates whether thisMediaTypemore specific than the given type.static MediaTypeparseMediaType(String mediaType) Parse the given String into a singleMediaType.parseMediaTypes(String mediaTypes) Parse the comma-separated string into a list ofMediaTypeobjects.parseMediaTypes(List<String> mediaTypes) Parse the given list of (potentially) comma-separated strings into a list ofMediaTypeobjects.Return a replica of this instance with its quality value removed.static voidsortByQualityValue(List<MediaType> mediaTypes) Sorts the given list ofMediaTypeobjects by quality value.static voidsortBySpecificity(List<MediaType> mediaTypes) Sorts the given list ofMediaTypeobjects by specificity.static voidsortBySpecificityAndQuality(List<MediaType> mediaTypes) Sorts the given list ofMediaTypeobjects by specificity as the primary criteria and quality value the secondary.static StringtoString(Collection<MediaType> mediaTypes) Return a string representation of the given list ofMediaTypeobjects.static MediaTypeParse the given String value into aMediaTypeobject从类继承的方法 cn.taketoday.util.MimeType
appendTo, compareTo, equals, equalsTypeAndSubtype, getCharset, getParameter, getParameters, getSubtype, getSubtypeSuffix, getType, hashCode, includes, isCompatibleWith, isConcrete, isPresentIn, isWildcardSubtype, isWildcardType, toString, unquote
-
字段详细资料
-
serialVersionUID
private static final long serialVersionUID- 另请参阅:
-
ALL
Public constant media type that includes all media ranges (i.e. "*/*"). -
ALL_VALUE
A String equivalent ofALL.- 另请参阅:
-
APPLICATION_ATOM_XML
Public constant media type forapplication/atom+xml. -
APPLICATION_ATOM_XML_VALUE
A String equivalent ofAPPLICATION_ATOM_XML.- 另请参阅:
-
APPLICATION_CBOR
Public constant media type forapplication/cbor. -
APPLICATION_CBOR_VALUE
A String equivalent ofAPPLICATION_CBOR.- 另请参阅:
-
APPLICATION_FORM_URLENCODED
Public constant media type forapplication/x-www-form-urlencoded. -
APPLICATION_FORM_URLENCODED_VALUE
A String equivalent ofAPPLICATION_FORM_URLENCODED.- 另请参阅:
-
APPLICATION_JSON
Public constant media type forapplication/json. -
APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON. -
APPLICATION_JSON_UTF8_VALUE
- 另请参阅:
-
APPLICATION_OCTET_STREAM
Public constant media type forapplication/octet-stream. -
APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM.- 另请参阅:
-
APPLICATION_PDF
Public constant media type forapplication/pdf. -
APPLICATION_PDF_VALUE
A String equivalent ofAPPLICATION_PDF.- 另请参阅:
-
APPLICATION_PROBLEM_JSON
Public constant media type forapplication/problem+json.* -
APPLICATION_PROBLEM_JSON_VALUE
A String equivalent ofAPPLICATION_PROBLEM_JSON.- 另请参阅:
-
APPLICATION_PROBLEM_XML
Public constant media type forapplication/problem+xml. -
APPLICATION_PROBLEM_XML_VALUE
A String equivalent ofAPPLICATION_PROBLEM_XML.- 另请参阅:
-
APPLICATION_RSS_XML
Public constant media type forapplication/rss+xml. -
APPLICATION_RSS_XML_VALUE
A String equivalent ofAPPLICATION_RSS_XML.- 另请参阅:
-
APPLICATION_NDJSON
Public constant media type forapplication/x-ndjson. -
APPLICATION_NDJSON_VALUE
A String equivalent ofAPPLICATION_NDJSON.- 另请参阅:
-
APPLICATION_STREAM_JSON
Public constant media type forapplication/stream+json. -
APPLICATION_STREAM_JSON_VALUE
A String equivalent ofAPPLICATION_STREAM_JSON.- 另请参阅:
-
APPLICATION_XHTML_XML
Public constant media type forapplication/xhtml+xml. -
APPLICATION_XHTML_XML_VALUE
A String equivalent ofAPPLICATION_XHTML_XML.- 另请参阅:
-
APPLICATION_XML
Public constant media type forapplication/xml. -
APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML.- 另请参阅:
-
IMAGE_GIF
Public constant media type forimage/gif. -
IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF.- 另请参阅:
-
IMAGE_JPEG
Public constant media type forimage/jpeg. -
IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG.- 另请参阅:
-
IMAGE_PNG
Public constant media type forimage/png. -
IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG.- 另请参阅:
-
MULTIPART_FORM_DATA
Public constant media type formultipart/form-data. -
MULTIPART_FORM_DATA_VALUE
A String equivalent ofMULTIPART_FORM_DATA.- 另请参阅:
-
MULTIPART_MIXED
Public constant media type formultipart/mixed. -
MULTIPART_MIXED_VALUE
A String equivalent ofMULTIPART_MIXED.- 另请参阅:
-
MULTIPART_RELATED
Public constant media type formultipart/related.- 从以下版本开始:
- 4.0
-
MULTIPART_RELATED_VALUE
A String equivalent ofMULTIPART_RELATED.- 从以下版本开始:
- 4.0
- 另请参阅:
-
TEXT_EVENT_STREAM
Public constant media type fortext/event-stream. -
TEXT_EVENT_STREAM_VALUE
A String equivalent ofTEXT_EVENT_STREAM.- 另请参阅:
-
TEXT_HTML
Public constant media type fortext/html. -
TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML.- 另请参阅:
-
TEXT_MARKDOWN
Public constant media type fortext/markdown. -
TEXT_MARKDOWN_VALUE
A String equivalent ofTEXT_MARKDOWN.- 另请参阅:
-
TEXT_PLAIN
Public constant media type fortext/plain. -
TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN.- 另请参阅:
-
TEXT_XML
Public constant media type fortext/xml. -
TEXT_XML_VALUE
A String equivalent ofTEXT_XML.- 另请参阅:
-
PARAM_QUALITY_FACTOR
- 另请参阅:
-
QUALITY_VALUE_COMPARATOR
Comparator used bysortByQualityValue(List). -
SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List).
-
-
构造器详细资料
-
MediaType
Create a newMediaTypefor 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
Create a newMediaTypefor 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
Create a newMediaTypefor 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
Create a newMediaTypefor 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
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
-
MediaType
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
Create a newMediaTypefor 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
- 覆盖:
checkParameters在类中cn.taketoday.util.MimeType
-
getQualityValue
public double getQualityValue()Return the quality factor, as indicated by aqparameter, if any. Defaults to1.0.- 返回:
- the quality factor as double value
-
includes
Indicate whether thisMediaTypeincludes the given media type.For instance,
text/*includestext/plainandtext/html, andapplication/*+xmlincludesapplication/soap+xml, etc. This method is not symmetric.Simply calls
MimeType.includes(MimeType)but declared with aMediaTypeparameter for binary backwards compatibility.- 参数:
other- the reference media type with which to compare- 返回:
trueif this media type includes the given media type;falseotherwise
-
isCompatibleWith
Indicate whether thisMediaTypeis 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(cn.taketoday.http.MediaType), except that it is symmetric.Simply calls
MimeType.isCompatibleWith(MimeType)but declared with aMediaTypeparameter for binary backwards compatibility.- 参数:
other- the reference media type with which to compare- 返回:
trueif this media type is compatible with the given media type;falseotherwise
-
copyQualityValue
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
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
Parse the given String value into aMediaTypeobject- 参数:
value- the string to parse- 抛出:
InvalidMediaTypeException- if the media type value cannot be parsed- 另请参阅:
-
parseMediaType
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
Parse the comma-separated string into a list ofMediaTypeobjects.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
Parse the given list of (potentially) comma-separated strings into a list ofMediaTypeobjects.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
-
asMediaTypes
Re-create the given mime types as media types. -
asMediaType
Re-create the given mime type as a media type. -
toString
Return a string representation of the given list ofMediaTypeobjects.This method can be used to for an
AcceptorContent-Typeheader.- 参数:
mediaTypes- the media types to create a string representation for- 返回:
- the string representation
-
isMoreSpecific
public boolean isMoreSpecific(cn.taketoday.util.MimeType other) Indicates whether thisMediaTypemore specific than the given type.- if this media type has a quality factor higher than the other,
then this method returns
true. - if this media type has a quality factor lower than the other,
then this method returns
false. - if this mime type has a wildcard type,
and the other does not, then this method returns
false. - if this mime type does not have a wildcard type,
and the other does, then this method returns
true. - if this mime type has a wildcard type,
and the other does not, then this method returns
false. - if this mime type does not have a wildcard type,
and the other does, then this method returns
true. - if the two mime types have identical type and subtype, then the mime type with the most parameters is more specific than the other.
- Otherwise, this method returns
false.
- 覆盖:
isMoreSpecific在类中cn.taketoday.util.MimeType- 参数:
other- theMimeTypeto be compared- 返回:
- the result of the comparison
- 从以下版本开始:
- 4.0
- 另请参阅:
- if this media type has a quality factor higher than the other,
then this method returns
-
isLessSpecific
public boolean isLessSpecific(cn.taketoday.util.MimeType other) Indicates whether thisMediaTypemore specific than the given type.- if this media type has a quality factor higher than the other,
then this method returns
false. - if this media type has a quality factor lower than the other,
then this method returns
true. - if this mime type has a wildcard type,
and the other does not, then this method returns
true. - if this mime type does not have a wildcard type,
and the other does, then this method returns
false. - if this mime type has a wildcard type,
and the other does not, then this method returns
true. - if this mime type does not have a wildcard type,
and the other does, then this method returns
false. - if the two mime types have identical type and subtype, then the mime type with the least parameters is less specific than the other.
- Otherwise, this method returns
false.
- 覆盖:
isLessSpecific在类中cn.taketoday.util.MimeType- 参数:
other- theMimeTypeto be compared- 返回:
- the result of the comparison
- 从以下版本开始:
- 4.0
- 另请参阅:
- if this media type has a quality factor higher than the other,
then this method returns
-
sortBySpecificity
Sorts the given list ofMediaTypeobjects 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- 另请参阅:
-
sortByQualityValue
Sorts the given list ofMediaTypeobjects 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- 另请参阅:
-
sortBySpecificityAndQuality
Sorts the given list ofMediaTypeobjects by specificity as the primary criteria and quality value the secondary. -
fromResource
Determine a media type for the given resource, if possible.- 参数:
resource- the resource to introspect- 返回:
- the corresponding media type, or
nullif none found
-
fromFileName
Determine a media type for the given file name, if possible.- 参数:
filename- the file name plus extension- 返回:
- the corresponding media type, or
nullif none found
-