public class MediaType extends MimeType implements java.io.Serializable
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 java.lang.String |
ALL_VALUE
A String equivalent of
MediaType#ALL. |
static MediaType |
APPLICATION_ATOM_XML
Public constant media type for
application/atom+xml. |
static java.lang.String |
APPLICATION_ATOM_XML_VALUE
A String equivalent of
APPLICATION_ATOM_XML. |
static MediaType |
APPLICATION_FORM_URLENCODED
Public constant media type for
application/x-www-form-urlencoded. |
static java.lang.String |
APPLICATION_FORM_URLENCODED_VALUE
A String equivalent of
APPLICATION_FORM_URLENCODED. |
static MediaType |
APPLICATION_JSON
Public constant media type for
application/json. |
static MediaType |
APPLICATION_JSON_UTF8
Public constant media type for
application/json;charset=UTF-8. |
static java.lang.String |
APPLICATION_JSON_UTF8_VALUE
A String equivalent of
APPLICATION_JSON_UTF8. |
static java.lang.String |
APPLICATION_JSON_VALUE
A String equivalent of
MediaType#APPLICATION_JSON. |
static MediaType |
APPLICATION_OCTET_STREAM
Public constant media type for
application/octet-stream. |
static java.lang.String |
APPLICATION_OCTET_STREAM_VALUE
A String equivalent of
APPLICATION_OCTET_STREAM. |
static MediaType |
APPLICATION_PDF
Public constant media type for
application/pdf. |
static java.lang.String |
APPLICATION_PDF_VALUE
A String equivalent of
APPLICATION_PDF. |
static MediaType |
APPLICATION_RSS_XML
Public constant media type for
application/rss+xml. |
static java.lang.String |
APPLICATION_RSS_XML_VALUE
A String equivalent of
APPLICATION_RSS_XML. |
static MediaType |
APPLICATION_XHTML_XML
Public constant media type for
application/xhtml+xml. |
static java.lang.String |
APPLICATION_XHTML_XML_VALUE
A String equivalent of
APPLICATION_XHTML_XML. |
static MediaType |
APPLICATION_XML
Public constant media type for
application/xml. |
static MediaType |
APPLICATION_XML_UTF8
Public constant media type for
application/xml. |
static java.lang.String |
APPLICATION_XML_UTF8_VALUE
A String equivalent of
APPLICATION_XML. |
static java.lang.String |
APPLICATION_XML_VALUE
A String equivalent of
APPLICATION_XML. |
static MediaType |
IMAGE_GIF
Public constant media type for
image/gif. |
static java.lang.String |
IMAGE_GIF_VALUE
A String equivalent of
IMAGE_GIF. |
static MediaType |
IMAGE_JPEG
Public constant media type for
image/jpeg. |
static java.lang.String |
IMAGE_JPEG_VALUE
A String equivalent of
IMAGE_JPEG. |
static MediaType |
IMAGE_PNG
Public constant media type for
image/png. |
static java.lang.String |
IMAGE_PNG_VALUE
A String equivalent of
IMAGE_PNG. |
static MediaType |
MULTIPART_FORM_DATA
Public constant media type for
multipart/form-data. |
static java.lang.String |
MULTIPART_FORM_DATA_VALUE
A String equivalent of
MULTIPART_FORM_DATA. |
static java.util.Comparator<MediaType> |
QUALITY_VALUE_COMPARATOR
Comparator used by
sortByQualityValue(List). |
static java.util.Comparator<MediaType> |
SPECIFICITY_COMPARATOR
Comparator used by
sortBySpecificity(List). |
static MediaType |
TEXT_EVENT_STREAM
Public constant media type for
text/event-stream. |
static java.lang.String |
TEXT_EVENT_STREAM_VALUE
A String equivalent of
TEXT_EVENT_STREAM. |
static MediaType |
TEXT_HTML
Public constant media type for
text/html. |
static java.lang.String |
TEXT_HTML_VALUE
A String equivalent of
TEXT_HTML. |
static MediaType |
TEXT_MARKDOWN
Public constant media type for
text/markdown. |
static java.lang.String |
TEXT_MARKDOWN_VALUE
A String equivalent of
TEXT_MARKDOWN. |
static MediaType |
TEXT_PLAIN
Public constant media type for
text/plain. |
static java.lang.String |
TEXT_PLAIN_VALUE
A String equivalent of
TEXT_PLAIN. |
static MediaType |
TEXT_XML
Public constant media type for
text/xml. |
static java.lang.String |
TEXT_XML_VALUE
A String equivalent of
TEXT_XML. |
WILDCARD_TYPE| Constructor and Description |
|---|
MediaType(MediaType other,
java.nio.charset.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,
java.util.Map<java.lang.String,java.lang.String> parameters)
Copy-constructor that copies the type and subtype of the given
MediaType, and allows for different
parameter. |
MediaType(java.lang.String type)
Create a new
MediaType for the given primary type. |
MediaType(java.lang.String type,
java.lang.String subtype)
Create a new
MediaType for the given primary type and subtype. |
MediaType(java.lang.String type,
java.lang.String subtype,
java.nio.charset.Charset charset)
Create a new
MediaType for the given type, subtype, and character set. |
MediaType(java.lang.String type,
java.lang.String subtype,
double qualityValue)
Create a new
MediaType for the given type, subtype, and quality value. |
MediaType(java.lang.String type,
java.lang.String subtype,
java.util.Map<java.lang.String,java.lang.String> parameters)
Create a new
MediaType for the given type, subtype, and parameters. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
checkParameters(java.lang.String attribute,
java.lang.String value) |
MediaType |
copyQualityValue(MediaType mediaType)
Return a replica of this instance with the quality value of the given MediaType.
|
static MediaType |
getFileMediaType(java.lang.String fileName)
Get the
MediaType of the file. |
double |
getQualityValue()
Return the quality value, as indicated by a
q parameter, if any. |
static java.lang.String |
getUrlExtension(java.lang.String url)
Get he extension by url.
|
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(java.lang.String mediaType)
Parse the given String into a single
MediaType. |
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 of
MediaType objects. |
static java.util.List<MediaType> |
parseMediaTypes(java.lang.String mediaTypes)
Parse the given 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(java.util.List<MediaType> mediaTypes)
Sorts the given list of
MediaType objects by quality value. |
static void |
sortBySpecificity(java.util.List<MediaType> mediaTypes)
Sorts the given list of
MediaType objects by specificity. |
static void |
sortBySpecificityAndQuality(java.util.List<MediaType> mediaTypes)
Sorts the given list of
MediaType objects by specificity as the primary criteria and quality value the
secondary. |
static MediaType |
valueOf(java.lang.String value)
Parse the given String value into a
MediaType object, with this method name following the 'valueOf'
naming convention. |
appendTo, compareTo, equals, equalsExcludeParameter, getCharset, getParameter, getParameters, getSubtype, getType, hashCode, includes, isCompatibleWith, isConcrete, isWildcardSubtype, isWildcardType, toString, toString, unquotepublic static final MediaType ALL
public static final java.lang.String ALL_VALUE
MediaType#ALL.public static final MediaType APPLICATION_JSON
application/json.APPLICATION_JSON_UTF8public static final java.lang.String APPLICATION_JSON_VALUE
MediaType#APPLICATION_JSON.APPLICATION_JSON_UTF8_VALUE,
Constant Field Valuespublic static final MediaType APPLICATION_JSON_UTF8
application/json;charset=UTF-8.public static final java.lang.String APPLICATION_JSON_UTF8_VALUE
APPLICATION_JSON_UTF8.public static final MediaType APPLICATION_XML
application/xml.public static final java.lang.String APPLICATION_XML_VALUE
APPLICATION_XML.public static final MediaType APPLICATION_XML_UTF8
application/xml.public static final java.lang.String APPLICATION_XML_UTF8_VALUE
APPLICATION_XML.public static final MediaType APPLICATION_ATOM_XML
application/atom+xml.public static final java.lang.String APPLICATION_ATOM_XML_VALUE
APPLICATION_ATOM_XML.public static final MediaType APPLICATION_FORM_URLENCODED
application/x-www-form-urlencoded.public static final java.lang.String APPLICATION_FORM_URLENCODED_VALUE
APPLICATION_FORM_URLENCODED.public static final MediaType APPLICATION_OCTET_STREAM
application/octet-stream.public static final java.lang.String APPLICATION_OCTET_STREAM_VALUE
APPLICATION_OCTET_STREAM.public static final MediaType APPLICATION_RSS_XML
application/rss+xml.public static final java.lang.String APPLICATION_RSS_XML_VALUE
APPLICATION_RSS_XML.public static final MediaType APPLICATION_XHTML_XML
application/xhtml+xml.public static final java.lang.String APPLICATION_XHTML_XML_VALUE
APPLICATION_XHTML_XML.public static final MediaType APPLICATION_PDF
application/pdf.public static final java.lang.String APPLICATION_PDF_VALUE
APPLICATION_PDF.public static final MediaType IMAGE_GIF
image/gif.public static final java.lang.String IMAGE_GIF_VALUE
IMAGE_GIF.public static final MediaType IMAGE_JPEG
image/jpeg.public static final java.lang.String IMAGE_JPEG_VALUE
IMAGE_JPEG.public static final MediaType IMAGE_PNG
image/png.public static final java.lang.String IMAGE_PNG_VALUE
IMAGE_PNG.public static final MediaType MULTIPART_FORM_DATA
multipart/form-data.public static final java.lang.String MULTIPART_FORM_DATA_VALUE
MULTIPART_FORM_DATA.public static final MediaType TEXT_EVENT_STREAM
text/event-stream.public static final java.lang.String TEXT_EVENT_STREAM_VALUE
TEXT_EVENT_STREAM.public static final MediaType TEXT_HTML
text/html.public static final java.lang.String TEXT_HTML_VALUE
TEXT_HTML.public static final MediaType TEXT_MARKDOWN
text/markdown.public static final java.lang.String TEXT_MARKDOWN_VALUE
TEXT_MARKDOWN.public static final MediaType TEXT_PLAIN
text/plain.public static final java.lang.String TEXT_PLAIN_VALUE
TEXT_PLAIN.public static final MediaType TEXT_XML
text/xml.public static final java.lang.String TEXT_XML_VALUE
TEXT_XML.public static final java.util.Comparator<MediaType> QUALITY_VALUE_COMPARATOR
sortByQualityValue(List).public static final java.util.Comparator<MediaType> SPECIFICITY_COMPARATOR
sortBySpecificity(List).public MediaType(java.lang.String type)
MediaType for the given primary type. The subtype is set to "*", parameters empty.
type - the primary type.java.lang.IllegalArgumentException - if any of the parameters contain illegal characters.public MediaType(java.lang.String type,
java.lang.String subtype)
MediaType for the given primary type and subtype.
The parameters are empty.
type - the primary type.subtype - the subtype.java.lang.IllegalArgumentException - if any of the parameters contain illegal characters.public MediaType(java.lang.String type,
java.lang.String subtype,
java.nio.charset.Charset charset)
MediaType for the given type, subtype, and character set.type - the primary type.subtype - the subtype.charset - the character set.java.lang.IllegalArgumentException - if any of the parameters contain illegal characters.public MediaType(java.lang.String type,
java.lang.String subtype,
double qualityValue)
MediaType for the given type, subtype, and quality value.type - the primary type.subtype - the subtype.qualityValue - the quality value.java.lang.IllegalArgumentException - if any of the parameters contain illegal characters.public MediaType(MediaType other, java.nio.charset.Charset charset)
MediaType, and allows to set
the specified character set.other - the other media type.charset - the character set.java.lang.IllegalArgumentException - if any of the parameters contain illegal characters.public MediaType(MediaType other, java.util.Map<java.lang.String,java.lang.String> parameters)
MediaType, and allows for different
parameter.other - the other media type.parameters - the parameters, may be null.java.lang.IllegalArgumentException - if any of the parameters contain illegal characters.public MediaType(java.lang.String type,
java.lang.String subtype,
java.util.Map<java.lang.String,java.lang.String> parameters)
MediaType for the given type, subtype, and parameters.type - the primary type.subtype - the subtype.parameters - the parameters, may be null.java.lang.IllegalArgumentException - if any of the parameters contain illegal characters.protected void checkParameters(java.lang.String attribute,
java.lang.String value)
checkParameters in class MimeTypepublic double getQualityValue()
q parameter, if any. Defaults to 1.0.public boolean includes(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.
other - the reference media type with which to compare.true if this media type includes the given media type; false otherwise.public boolean isCompatibleWith(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(MediaType), except that it is symmetric.
other - the reference media type with which to compare.true if this media type is compatible with the given media type; false otherwise.public MediaType copyQualityValue(MediaType mediaType)
public MediaType removeQualityValue()
public static MediaType valueOf(java.lang.String value)
MediaType object, with this method name following the 'valueOf'
naming convention.value - the string to parse.InvalidMediaTypeException - if the media type value cannot be parsed.parseMediaType(String)public static MediaType parseMediaType(java.lang.String mediaType)
MediaType.mediaType - the string to parse.InvalidMediaTypeException - if the media type value cannot be parsed.public static java.util.List<MediaType> parseMediaTypes(java.lang.String mediaTypes)
MediaType objects.
This method can be used to parse an Accept or Content-Type header.
mediaTypes - the string to parse.InvalidMediaTypeException - if the media type value cannot be parsed.public static java.util.List<MediaType> parseMediaTypes(java.util.List<java.lang.String> mediaTypes)
MediaType objects.
This method can be used to parse an Accept or Content-Type header.
mediaTypes - the string to parse.InvalidMediaTypeException - if the media type value cannot be parsed.public static void sortBySpecificity(java.util.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 sorted.public static void sortByQualityValue(java.util.List<MediaType> mediaTypes)
MediaType objects by quality value.
Given two media types:
mediaTypes - the list of media types to be sorted.public static void sortBySpecificityAndQuality(java.util.List<MediaType> mediaTypes)
MediaType objects by specificity as the primary criteria and quality value the
secondary.public static MediaType getFileMediaType(java.lang.String fileName)
MediaType of the file.fileName - file name.MediaType, cannot be null.public static java.lang.String getUrlExtension(java.lang.String url)
url - url.