Class MediaType
- java.lang.Object
-
- com.aspectran.web.support.http.MediaType
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<MediaType>
public class MediaType extends java.lang.Object implements java.lang.Comparable<MediaType>, java.io.Serializable
This class is a clone of org.springframework.http.MediaType
Represents an Internet Media Type, as defined in the HTTP specification.This class contain support for the q-parameters used in HTTP content negotiation.
- Author:
- Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sebastien Deleuze, Kazuki Shimizu
- See Also:
- HTTP 1.1: Semantics and Content, section 3.1.1.1, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MediaType.SpecificityComparator<T extends MediaType>
Comparator to sortMediaTypes
in order of specificity.
-
Field Summary
Fields Modifier and Type Field Description static MediaType
ALL
Public constant media type that includes all media ranges (i.e.static java.lang.String
ALL_VALUE
A String equivalent ofALL
.static MediaType
APPLICATION_APON
Public constant media type forapplication/apon
.static java.lang.String
APPLICATION_APON_VALUE
A String equivalent ofAPPLICATION_JSON
.static MediaType
APPLICATION_ATOM_XML
Public constant media type forapplication/atom+xml
.static java.lang.String
APPLICATION_ATOM_XML_VALUE
A String equivalent ofAPPLICATION_ATOM_XML
.static MediaType
APPLICATION_CBOR
Public constant media type forapplication/cbor
.static java.lang.String
APPLICATION_CBOR_VALUE
A String equivalent ofAPPLICATION_CBOR
.static MediaType
APPLICATION_FORM_URLENCODED
Public constant media type forapplication/x-www-form-urlencoded
.static java.lang.String
APPLICATION_FORM_URLENCODED_VALUE
A String equivalent ofAPPLICATION_FORM_URLENCODED
.static MediaType
APPLICATION_GRAPHQL
Public constant media type forapplication/graphql
.static java.lang.String
APPLICATION_GRAPHQL_VALUE
A String equivalent ofAPPLICATION_GRAPHQL
.static MediaType
APPLICATION_JSON
Public constant media type forapplication/json
.static java.lang.String
APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON
.static MediaType
APPLICATION_OCTET_STREAM
Public constant media type forapplication/octet-stream
.static java.lang.String
APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM
.static MediaType
APPLICATION_PDF
Public constant media type forapplication/pdf
.static java.lang.String
APPLICATION_PDF_VALUE
A String equivalent ofAPPLICATION_PDF
.static MediaType
APPLICATION_PROBLEM_JSON
Public constant media type forapplication/problem+json
.static java.lang.String
APPLICATION_PROBLEM_JSON_VALUE
A String equivalent ofAPPLICATION_PROBLEM_JSON
.static MediaType
APPLICATION_PROBLEM_XML
Public constant media type forapplication/problem+xml
.static java.lang.String
APPLICATION_PROBLEM_XML_VALUE
A String equivalent ofAPPLICATION_PROBLEM_XML
.static MediaType
APPLICATION_RSS_XML
Public constant media type forapplication/rss+xml
.static java.lang.String
APPLICATION_RSS_XML_VALUE
A String equivalent ofAPPLICATION_RSS_XML
.static MediaType
APPLICATION_STREAM_JSON
Public constant media type forapplication/stream+json
.static java.lang.String
APPLICATION_STREAM_JSON_VALUE
A String equivalent ofAPPLICATION_STREAM_JSON
.static MediaType
APPLICATION_XHTML_XML
Public constant media type forapplication/xhtml+xml
.static java.lang.String
APPLICATION_XHTML_XML_VALUE
A String equivalent ofAPPLICATION_XHTML_XML
.static MediaType
APPLICATION_XML
Public constant media type forapplication/xml
.static java.lang.String
APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML
.static MediaType
IMAGE_GIF
Public constant media type forimage/gif
.static java.lang.String
IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF
.static MediaType
IMAGE_JPEG
Public constant media type forimage/jpeg
.static java.lang.String
IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG
.static MediaType
IMAGE_PNG
Public constant media type forimage/png
.static java.lang.String
IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG
.static MediaType
MULTIPART_FORM_DATA
Public constant media type formultipart/form-data
.static java.lang.String
MULTIPART_FORM_DATA_VALUE
A String equivalent ofMULTIPART_FORM_DATA
.static MediaType
MULTIPART_MIXED
Public constant media type formultipart/mixed
.static java.lang.String
MULTIPART_MIXED_VALUE
A String equivalent ofMULTIPART_MIXED
.static MediaType
MULTIPART_RELATED
Public constant media type formultipart/related
.static java.lang.String
MULTIPART_RELATED_VALUE
A String equivalent ofMULTIPART_RELATED
.static java.lang.String
PARAM_CHARSET
static java.util.Comparator<MediaType>
QUALITY_VALUE_COMPARATOR
Comparator used bysortByQualityValue(List)
.static java.util.Comparator<MediaType>
SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List)
.static MediaType
TEXT_EVENT_STREAM
Public constant media type fortext/event-stream
.static java.lang.String
TEXT_EVENT_STREAM_VALUE
A String equivalent ofTEXT_EVENT_STREAM
.static MediaType
TEXT_HTML
Public constant media type fortext/html
.static java.lang.String
TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML
.static MediaType
TEXT_MARKDOWN
Public constant media type fortext/markdown
.static java.lang.String
TEXT_MARKDOWN_VALUE
A String equivalent ofTEXT_MARKDOWN
.static MediaType
TEXT_PLAIN
Public constant media type fortext/plain
.static java.lang.String
TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN
.static MediaType
TEXT_XML
Public constant media type fortext/xml
.static java.lang.String
TEXT_XML_VALUE
A String equivalent ofTEXT_XML
.static java.lang.String
WILDCARD_TYPE
-
Constructor Summary
Constructors Constructor Description MediaType(MediaType other, java.nio.charset.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, java.util.Map<java.lang.String,java.lang.String> parameters)
Copy-constructor that copies the type and subtype of the givenMediaType
, and allows for different parameter.MediaType(java.lang.String type)
Create a newMediaType
for the given primary type.MediaType(java.lang.String type, java.lang.String subtype)
Create a newMediaType
for the given primary type and subtype.MediaType(java.lang.String type, java.lang.String subtype, double qualityValue)
Create a newMediaType
for the given type, subtype, and quality value.MediaType(java.lang.String type, java.lang.String subtype, java.nio.charset.Charset charset)
Create a newMediaType
for the given type, subtype, and character set.MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)
Create a newMediaType
for the given type, subtype, and parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendTo(java.lang.StringBuilder builder)
int
compareTo(MediaType other)
Compares this Media Type to another alphabetically.MediaType
copyQualityValue(MediaType mediaType)
Return a replica of this instance with the quality value of the givenMediaType
.boolean
equals(java.lang.Object other)
boolean
equalsTypeAndSubtype(MediaType other)
Similar toequals(Object)
but based on the type and subtype only, i.e.java.nio.charset.Charset
getCharset()
Return the character set, as indicated by acharset
parameter, if any.java.lang.String
getParameter(java.lang.String name)
Return a generic parameter value, given a parameter name.java.util.Map<java.lang.String,java.lang.String>
getParameters()
Return all generic parameter values.double
getQualityValue()
Return the quality factor, as indicated by aq
parameter, if any.java.lang.String
getSubtype()
Return the subtype.java.lang.String
getType()
Return the primary type.int
hashCode()
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.boolean
isConcrete()
Indicates whether this MIME Type is concrete, i.e.boolean
isPresentIn(java.util.Collection<MediaType> MediaTypes)
UnlikeCollection.contains(Object)
which relies onequals(Object)
, this method only checks the type and the subtype, but otherwise ignores parameters.boolean
isWildcardSubtype()
Indicates whether the subtype is the wildcard character*
or the wildcard character followed by a suffix (e.g.boolean
isWildcardType()
Indicates whether the type is the wildcard character*
or not.static MediaType
parseMediaType(java.lang.String mediaType)
Parse the given String into a singleMediaType
.static java.util.List<MediaType>
parseMediaTypes(java.lang.String mediaTypes)
Parse the comma-separated string into a list ofMediaType
objects.static java.util.List<MediaType>
parseMediaTypes(java.util.List<java.lang.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(java.util.List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by quality value.static void
sortBySpecificity(java.util.List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity.static void
sortBySpecificityAndQuality(java.util.List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity as the primary criteria and quality value the secondary.java.lang.String
toString()
static java.lang.String
toString(java.util.Collection<MediaType> mediaTypes)
Return a string representation of the given list ofMediaType
objects.static MediaType
valueOf(java.lang.String value)
Parse the given String value into aMediaType
object, with this method name following the 'valueOf' naming convention.
-
-
-
Field Detail
-
ALL
public static final MediaType ALL
Public constant media type that includes all media ranges (i.e. "*/*").
-
ALL_VALUE
public static final java.lang.String ALL_VALUE
A String equivalent ofALL
.- See Also:
- Constant Field Values
-
APPLICATION_ATOM_XML
public static final MediaType APPLICATION_ATOM_XML
Public constant media type forapplication/atom+xml
.
-
APPLICATION_ATOM_XML_VALUE
public static final java.lang.String APPLICATION_ATOM_XML_VALUE
A String equivalent ofAPPLICATION_ATOM_XML
.- See Also:
- Constant Field Values
-
APPLICATION_CBOR
public static final MediaType APPLICATION_CBOR
Public constant media type forapplication/cbor
.
-
APPLICATION_CBOR_VALUE
public static final java.lang.String APPLICATION_CBOR_VALUE
A String equivalent ofAPPLICATION_CBOR
.- See Also:
- Constant Field Values
-
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 java.lang.String APPLICATION_FORM_URLENCODED_VALUE
A String equivalent ofAPPLICATION_FORM_URLENCODED
.- See Also:
- Constant Field Values
-
APPLICATION_GRAPHQL
public static final MediaType APPLICATION_GRAPHQL
Public constant media type forapplication/graphql
.
-
APPLICATION_GRAPHQL_VALUE
public static final java.lang.String APPLICATION_GRAPHQL_VALUE
A String equivalent ofAPPLICATION_GRAPHQL
.- See Also:
- Constant Field Values
-
APPLICATION_JSON
public static final MediaType APPLICATION_JSON
Public constant media type forapplication/json
.
-
APPLICATION_JSON_VALUE
public static final java.lang.String APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON
.- See Also:
- Constant Field Values
-
APPLICATION_APON
public static final MediaType APPLICATION_APON
Public constant media type forapplication/apon
.
-
APPLICATION_APON_VALUE
public static final java.lang.String APPLICATION_APON_VALUE
A String equivalent ofAPPLICATION_JSON
.- See Also:
- Constant Field Values
-
APPLICATION_OCTET_STREAM
public static final MediaType APPLICATION_OCTET_STREAM
Public constant media type forapplication/octet-stream
.
-
APPLICATION_OCTET_STREAM_VALUE
public static final java.lang.String APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM
.- See Also:
- Constant Field Values
-
APPLICATION_PDF
public static final MediaType APPLICATION_PDF
Public constant media type forapplication/pdf
.
-
APPLICATION_PDF_VALUE
public static final java.lang.String APPLICATION_PDF_VALUE
A String equivalent ofAPPLICATION_PDF
.- See Also:
- Constant Field Values
-
APPLICATION_PROBLEM_JSON
public static final MediaType APPLICATION_PROBLEM_JSON
Public constant media type forapplication/problem+json
.
-
APPLICATION_PROBLEM_JSON_VALUE
public static final java.lang.String APPLICATION_PROBLEM_JSON_VALUE
A String equivalent ofAPPLICATION_PROBLEM_JSON
.- See Also:
- Constant Field Values
-
APPLICATION_PROBLEM_XML
public static final MediaType APPLICATION_PROBLEM_XML
Public constant media type forapplication/problem+xml
.
-
APPLICATION_PROBLEM_XML_VALUE
public static final java.lang.String APPLICATION_PROBLEM_XML_VALUE
A String equivalent ofAPPLICATION_PROBLEM_XML
.- See Also:
- Constant Field Values
-
APPLICATION_RSS_XML
public static final MediaType APPLICATION_RSS_XML
Public constant media type forapplication/rss+xml
.
-
APPLICATION_RSS_XML_VALUE
public static final java.lang.String APPLICATION_RSS_XML_VALUE
A String equivalent ofAPPLICATION_RSS_XML
.- See Also:
- Constant Field Values
-
APPLICATION_STREAM_JSON
public static final MediaType APPLICATION_STREAM_JSON
Public constant media type forapplication/stream+json
.
-
APPLICATION_STREAM_JSON_VALUE
public static final java.lang.String APPLICATION_STREAM_JSON_VALUE
A String equivalent ofAPPLICATION_STREAM_JSON
.- See Also:
- Constant Field Values
-
APPLICATION_XHTML_XML
public static final MediaType APPLICATION_XHTML_XML
Public constant media type forapplication/xhtml+xml
.
-
APPLICATION_XHTML_XML_VALUE
public static final java.lang.String APPLICATION_XHTML_XML_VALUE
A String equivalent ofAPPLICATION_XHTML_XML
.- See Also:
- Constant Field Values
-
APPLICATION_XML
public static final MediaType APPLICATION_XML
Public constant media type forapplication/xml
.
-
APPLICATION_XML_VALUE
public static final java.lang.String APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML
.- See Also:
- Constant Field Values
-
IMAGE_GIF
public static final MediaType IMAGE_GIF
Public constant media type forimage/gif
.
-
IMAGE_GIF_VALUE
public static final java.lang.String IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF
.- See Also:
- Constant Field Values
-
IMAGE_JPEG
public static final MediaType IMAGE_JPEG
Public constant media type forimage/jpeg
.
-
IMAGE_JPEG_VALUE
public static final java.lang.String IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG
.- See Also:
- Constant Field Values
-
IMAGE_PNG
public static final MediaType IMAGE_PNG
Public constant media type forimage/png
.
-
IMAGE_PNG_VALUE
public static final java.lang.String IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG
.- See Also:
- Constant Field Values
-
MULTIPART_FORM_DATA
public static final MediaType MULTIPART_FORM_DATA
Public constant media type formultipart/form-data
.
-
MULTIPART_FORM_DATA_VALUE
public static final java.lang.String MULTIPART_FORM_DATA_VALUE
A String equivalent ofMULTIPART_FORM_DATA
.- See Also:
- Constant Field Values
-
MULTIPART_MIXED
public static final MediaType MULTIPART_MIXED
Public constant media type formultipart/mixed
.
-
MULTIPART_MIXED_VALUE
public static final java.lang.String MULTIPART_MIXED_VALUE
A String equivalent ofMULTIPART_MIXED
.- See Also:
- Constant Field Values
-
MULTIPART_RELATED
public static final MediaType MULTIPART_RELATED
Public constant media type formultipart/related
.
-
MULTIPART_RELATED_VALUE
public static final java.lang.String MULTIPART_RELATED_VALUE
A String equivalent ofMULTIPART_RELATED
.- See Also:
- Constant Field Values
-
TEXT_EVENT_STREAM
public static final MediaType TEXT_EVENT_STREAM
Public constant media type fortext/event-stream
.- See Also:
- Server-Sent Events W3C recommendation
-
TEXT_EVENT_STREAM_VALUE
public static final java.lang.String TEXT_EVENT_STREAM_VALUE
A String equivalent ofTEXT_EVENT_STREAM
.- See Also:
- Constant Field Values
-
TEXT_HTML
public static final MediaType TEXT_HTML
Public constant media type fortext/html
.
-
TEXT_HTML_VALUE
public static final java.lang.String TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML
.- See Also:
- Constant Field Values
-
TEXT_MARKDOWN
public static final MediaType TEXT_MARKDOWN
Public constant media type fortext/markdown
.
-
TEXT_MARKDOWN_VALUE
public static final java.lang.String TEXT_MARKDOWN_VALUE
A String equivalent ofTEXT_MARKDOWN
.- See Also:
- Constant Field Values
-
TEXT_PLAIN
public static final MediaType TEXT_PLAIN
Public constant media type fortext/plain
.
-
TEXT_PLAIN_VALUE
public static final java.lang.String TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN
.- See Also:
- Constant Field Values
-
TEXT_XML
public static final MediaType TEXT_XML
Public constant media type fortext/xml
.
-
TEXT_XML_VALUE
public static final java.lang.String TEXT_XML_VALUE
A String equivalent ofTEXT_XML
.- See Also:
- Constant Field Values
-
WILDCARD_TYPE
public static final java.lang.String WILDCARD_TYPE
- See Also:
- Constant Field Values
-
PARAM_CHARSET
public static final java.lang.String PARAM_CHARSET
- See Also:
- Constant Field Values
-
QUALITY_VALUE_COMPARATOR
public static final java.util.Comparator<MediaType> QUALITY_VALUE_COMPARATOR
Comparator used bysortByQualityValue(List)
.
-
SPECIFICITY_COMPARATOR
public static final java.util.Comparator<MediaType> SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List)
.
-
-
Constructor Detail
-
MediaType
public MediaType(java.lang.String type)
Create a newMediaType
for the given primary type.The subtype is set to "*", parameters empty.
- Parameters:
type
- the primary type- Throws:
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characters
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype)
Create a newMediaType
for the given primary type and subtype.The parameters are empty.
- Parameters:
type
- the primary typesubtype
- the subtype- Throws:
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characters
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype, java.nio.charset.Charset charset)
Create a newMediaType
for the given type, subtype, and character set.- Parameters:
type
- the primary typesubtype
- the subtypecharset
- the character set- Throws:
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characters
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype, double qualityValue)
Create a newMediaType
for the given type, subtype, and quality value.- Parameters:
type
- the primary typesubtype
- the subtypequalityValue
- the quality value- Throws:
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characters
-
MediaType
public MediaType(MediaType other, java.nio.charset.Charset charset)
Copy-constructor that copies the type, subtype and parameters of the givenMediaType
, and allows to set the specified character set.- Parameters:
other
- the other media typecharset
- the character set- Throws:
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characters
-
MediaType
public MediaType(MediaType other, @Nullable java.util.Map<java.lang.String,java.lang.String> parameters)
Copy-constructor that copies the type and subtype of the givenMediaType
, and allows for different parameter.- Parameters:
other
- the other media typeparameters
- the parameters, may benull
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characters
-
MediaType
public MediaType(java.lang.String type, java.lang.String subtype, @Nullable java.util.Map<java.lang.String,java.lang.String> parameters)
Create a newMediaType
for the given type, subtype, and parameters.- Parameters:
type
- the primary typesubtype
- the subtypeparameters
- the parameters, may benull
- Throws:
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characters
-
-
Method Detail
-
isWildcardType
public boolean isWildcardType()
Indicates whether the type is the wildcard character*
or not.- Returns:
- true if it is a wildcard character; Otherwise false
-
isWildcardSubtype
public boolean isWildcardSubtype()
Indicates whether the subtype is the wildcard character*
or the wildcard character followed by a suffix (e.g.*+xml
).- Returns:
- whether the subtype is a wildcard
-
isConcrete
public boolean isConcrete()
Indicates whether this MIME Type is concrete, i.e. whether neither the type nor the subtype is a wildcard character*
.- Returns:
- whether this MIME Type is concrete
-
getType
public java.lang.String getType()
Return the primary type.- Returns:
- the primary type
-
getSubtype
public java.lang.String getSubtype()
Return the subtype.- Returns:
- the subtype
-
getCharset
@Nullable public java.nio.charset.Charset getCharset()
Return the character set, as indicated by acharset
parameter, if any.- Returns:
- the character set, or
null
if not available
-
getParameter
@Nullable public java.lang.String getParameter(java.lang.String name)
Return a generic parameter value, given a parameter name.- Parameters:
name
- the parameter name- Returns:
- the parameter value, or
null
if not present
-
getParameters
public java.util.Map<java.lang.String,java.lang.String> getParameters()
Return all generic parameter values.- Returns:
- a read-only map (possibly empty, never
null
)
-
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
includes(MediaType)
but declared with aMediaType
parameter for binary backwards compatibility.- Parameters:
other
- the reference media type with which to compare- Returns:
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(com.aspectran.web.support.http.MediaType)
, except that it is symmetric.Simply calls
isCompatibleWith(MediaType)
but declared with aMediaType
parameter for binary backwards compatibility.- Parameters:
other
- the reference media type with which to compare- Returns:
true
if this media type is compatible with the given media type;false
otherwise
-
equalsTypeAndSubtype
public boolean equalsTypeAndSubtype(@Nullable MediaType other)
Similar toequals(Object)
but based on the type and subtype only, i.e. ignoring parameters.- Parameters:
other
- the other mime type to compare to- Returns:
- whether the two mime types have the same type and subtype
-
isPresentIn
public boolean isPresentIn(java.util.Collection<MediaType> MediaTypes)
UnlikeCollection.contains(Object)
which relies onequals(Object)
, this method only checks the type and the subtype, but otherwise ignores parameters.- Parameters:
MediaTypes
- the list of mime types to perform the check against- Returns:
- whether the list contains the given mime type
-
equals
public boolean equals(@Nullable java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
appendTo
protected void appendTo(java.lang.StringBuilder builder)
-
compareTo
public int compareTo(MediaType other)
Compares this Media Type to another alphabetically.- Specified by:
compareTo
in interfacejava.lang.Comparable<MediaType>
- Parameters:
other
- the Media Type to compare to
-
getQualityValue
public double getQualityValue()
Return the quality factor, as indicated by aq
parameter, if any. Defaults to1.0
.- Returns:
- the quality factor as double value
-
copyQualityValue
public MediaType copyQualityValue(MediaType mediaType)
Return a replica of this instance with the quality value of the givenMediaType
.- Parameters:
mediaType
- the media type- Returns:
- 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.- Returns:
- the same instance if the media type doesn't contain a quality value, or a new one otherwise
-
parseMediaType
public static MediaType parseMediaType(java.lang.String mediaType)
Parse the given String into a singleMediaType
.- Parameters:
mediaType
- the string to parse- Returns:
- the media type
- Throws:
InvalidMediaTypeException
- if the media type value cannot be parsed
-
parseMediaTypes
public static java.util.List<MediaType> parseMediaTypes(@Nullable java.lang.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.
- Parameters:
mediaTypes
- the string to parse- Returns:
- the list of media types
- Throws:
InvalidMediaTypeException
- if the media type value cannot be parsed
-
parseMediaTypes
public static java.util.List<MediaType> parseMediaTypes(@Nullable java.util.List<java.lang.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.
- Parameters:
mediaTypes
- the string to parse- Returns:
- the list of media types
- Throws:
InvalidMediaTypeException
- if the media type value cannot be parsed
-
toString
public static java.lang.String toString(java.util.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.- Parameters:
mediaTypes
- the media types to create a string representation for- Returns:
- the string representation
-
sortBySpecificity
public static void sortBySpecificity(java.util.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
- Parameters:
mediaTypes
- the list of media types to be sorted- See Also:
- HTTP 1.1: Semantics and Content, section 5.3.2
-
sortByQualityValue
public static void sortByQualityValue(java.util.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.
- Parameters:
mediaTypes
- the list of media types to be sorted- See Also:
getQualityValue()
-
sortBySpecificityAndQuality
public static void sortBySpecificityAndQuality(java.util.List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity as the primary criteria and quality value the secondary.- Parameters:
mediaTypes
- the list of media types to sort- See Also:
sortBySpecificity(List)
,sortByQualityValue(List)
-
valueOf
public static MediaType valueOf(java.lang.String value)
Parse the given String value into aMediaType
object, with this method name following the 'valueOf' naming convention.- Parameters:
value
- the string to parse- Returns:
- the media type
- Throws:
InvalidMediaTypeException
- if the media type value cannot be parsed- See Also:
parseMediaType(String)
-
-