public class MediaType
extends java.lang.Object
implements java.lang.CharSequence
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ALL
A wildcard media type representing all types.
|
static MediaType |
ALL_TYPE
A wildcard media type representing all types.
|
static java.lang.String |
APPLICATION_ATOM_XML
Atom: application/atom+xml.
|
static MediaType |
APPLICATION_ATOM_XML_TYPE
Atom: application/atom+xml.
|
static java.lang.String |
APPLICATION_FORM_URLENCODED
Form encoded data: application/x-www-form-urlencoded.
|
static MediaType |
APPLICATION_FORM_URLENCODED_TYPE
Form encoded data: application/x-www-form-urlencoded.
|
static java.lang.String |
APPLICATION_GRAPHQL
GraphQL: application/graphql.
|
static MediaType |
APPLICATION_GRAPHQL_TYPE
GraphQL: application/graphql.
|
static java.lang.String |
APPLICATION_HAL_JSON
HAL JSON: application/hal+json.
|
static MediaType |
APPLICATION_HAL_JSON_TYPE
HAL JSON: application/hal+json.
|
static java.lang.String |
APPLICATION_HAL_XML
HAL XML: application/hal+xml.
|
static MediaType |
APPLICATION_HAL_XML_TYPE
HAL XML: application/hal+xml.
|
static java.lang.String |
APPLICATION_JSON
JSON: application/json.
|
static java.lang.String |
APPLICATION_JSON_STREAM
JSON Stream: application/x-json-stream.
|
static MediaType |
APPLICATION_JSON_STREAM_TYPE
JSON Stream: application/x-json-stream.
|
static MediaType |
APPLICATION_JSON_TYPE
JSON: application/json.
|
static java.lang.String |
APPLICATION_OCTET_STREAM
BINARY: application/octet-stream.
|
static MediaType |
APPLICATION_OCTET_STREAM_TYPE
BINARY: application/octet-stream.
|
static java.lang.String |
APPLICATION_VND_ERROR
VND Error: application/vnd.error+json.
|
static MediaType |
APPLICATION_VND_ERROR_TYPE
VND Error: application/vnd.error+json.
|
static java.lang.String |
APPLICATION_XHTML
XHTML: application/xhtml+xml.
|
static MediaType |
APPLICATION_XHTML_TYPE
XHTML: application/xhtml+xml.
|
static java.lang.String |
APPLICATION_XML
XML: application/xml.
|
static MediaType |
APPLICATION_XML_TYPE
XML: application/xml.
|
static java.lang.String |
APPLICATION_YAML
YAML: application/x-yaml.
|
static MediaType |
APPLICATION_YAML_TYPE
YAML: application/x-yaml.
|
static java.lang.String |
CHARSET_PARAMETER
Parameter
"charset" . |
static MediaType[] |
EMPTY_ARRAY
Default empty media type array.
|
protected java.lang.String |
extension |
static java.lang.String |
EXTENSION_JSON
Default file extension used for JSON.
|
static java.lang.String |
EXTENSION_XML
Default file extension used for XML.
|
static MediaType |
FORM
Short cut for
APPLICATION_FORM_URLENCODED_TYPE . |
static java.lang.String |
IMAGE_GIF
Gif Image: image/gif.
|
static MediaType |
IMAGE_GIF_TYPE
Gif Image: image/gif.
|
static java.lang.String |
IMAGE_JPEG
Jpeg Image: image/jpeg.
|
static MediaType |
IMAGE_JPEG_TYPE
Jpeg Image: image/jpeg.
|
static java.lang.String |
IMAGE_PNG
Png Image: image/png.
|
static MediaType |
IMAGE_PNG_TYPE
Png Image: image/png.
|
static java.lang.String |
IMAGE_WEBP
Webp Image: image/webp.
|
static MediaType |
IMAGE_WEBP_TYPE
Webp Image: image/webp.
|
static java.lang.String |
MULTIPART_FORM_DATA
Multi part form data: multipart/form-data.
|
static MediaType |
MULTIPART_FORM_DATA_TYPE
Multi part form data: multipart/form-data.
|
protected java.lang.String |
name |
protected java.util.Map<java.lang.CharSequence,java.lang.String> |
parameters |
static java.lang.String |
Q_PARAMETER
Parameter
"q" . |
protected java.lang.String |
subtype |
static java.lang.String |
TEXT_EVENT_STREAM
Server Sent Event: text/event-stream.
|
static MediaType |
TEXT_EVENT_STREAM_TYPE
Server Sent Event: text/event-stream.
|
static java.lang.String |
TEXT_HTML
HTML: text/html.
|
static MediaType |
TEXT_HTML_TYPE
HTML: text/html.
|
static java.lang.String |
TEXT_JSON
JSON: text/json.
|
static MediaType |
TEXT_JSON_TYPE
JSON: text/json.
|
static java.lang.String |
TEXT_PLAIN
Plain Text: text/plain.
|
static MediaType |
TEXT_PLAIN_TYPE
Plain Text: text/plain.
|
static java.lang.String |
TEXT_XML
XML: text/xml.
|
static MediaType |
TEXT_XML_TYPE
XML: text/xml.
|
protected java.lang.String |
type |
static java.lang.String |
V_PARAMETER
Parameter
"v" . |
Constructor and Description |
---|
MediaType(java.lang.String name)
Constructs a new media type for the given string.
|
MediaType(java.lang.String name,
java.util.Map<java.lang.String,java.lang.String> params)
Constructs a new media type for the given string and parameters.
|
MediaType(java.lang.String name,
java.lang.String extension)
Constructs a new media type for the given string and extension.
|
MediaType(java.lang.String name,
java.lang.String extension,
java.util.Map<java.lang.String,java.lang.String> params)
Constructs a new media type for the given string and extension.
|
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index) |
boolean |
equals(java.lang.Object o) |
static java.util.Optional<MediaType> |
forExtension(java.lang.String extension)
Resolve the
MediaType for the given file extension. |
static MediaType |
forFilename(java.lang.String filename)
Resolve the
MediaType for the given file name. |
static java.util.Optional<MediaType> |
fromType(java.lang.Class<?> type)
|
java.util.Optional<java.nio.charset.Charset> |
getCharset() |
java.lang.String |
getExtension() |
java.lang.String |
getName() |
OptionalValues<java.lang.String> |
getParameters() |
java.lang.String |
getQuality() |
java.math.BigDecimal |
getQualityAsNumber() |
java.lang.String |
getSubtype() |
java.lang.String |
getType() |
java.lang.String |
getVersion() |
int |
hashCode() |
boolean |
isTextBased() |
static boolean |
isTextBased(java.lang.String contentType) |
int |
length() |
boolean |
matches(MediaType expectedContentType)
Determine if this requested content type can be satisfied by a given content type.
|
static MediaType[] |
of(java.lang.CharSequence... mediaType)
Create a new
MediaType from the given text. |
static MediaType |
of(java.lang.CharSequence mediaType)
Create a new
MediaType from the given text. |
static java.util.List<MediaType> |
orderedOf(java.lang.CharSequence... values)
Returns the ordered media types for the given values.
|
static java.util.List<MediaType> |
orderedOf(java.util.List<? extends java.lang.CharSequence> values)
Returns the ordered media types for the given values.
|
java.lang.CharSequence |
subSequence(int start,
int end) |
java.lang.String |
toString() |
public static final java.lang.String EXTENSION_JSON
public static final java.lang.String EXTENSION_XML
public static final MediaType[] EMPTY_ARRAY
public static final java.lang.String ALL
public static final MediaType ALL_TYPE
public static final java.lang.String APPLICATION_FORM_URLENCODED
public static final MediaType APPLICATION_FORM_URLENCODED_TYPE
public static final MediaType FORM
APPLICATION_FORM_URLENCODED_TYPE
.public static final java.lang.String MULTIPART_FORM_DATA
public static final MediaType MULTIPART_FORM_DATA_TYPE
public static final java.lang.String TEXT_HTML
public static final MediaType TEXT_HTML_TYPE
public static final java.lang.String APPLICATION_XHTML
public static final MediaType APPLICATION_XHTML_TYPE
public static final java.lang.String APPLICATION_XML
public static final MediaType APPLICATION_XML_TYPE
public static final java.lang.String APPLICATION_JSON
public static final MediaType APPLICATION_JSON_TYPE
public static final java.lang.String APPLICATION_YAML
public static final MediaType APPLICATION_YAML_TYPE
public static final java.lang.String TEXT_XML
public static final MediaType TEXT_XML_TYPE
public static final java.lang.String TEXT_JSON
public static final MediaType TEXT_JSON_TYPE
public static final java.lang.String TEXT_PLAIN
public static final MediaType TEXT_PLAIN_TYPE
public static final java.lang.String APPLICATION_HAL_JSON
public static final MediaType APPLICATION_HAL_JSON_TYPE
public static final java.lang.String APPLICATION_HAL_XML
public static final MediaType APPLICATION_HAL_XML_TYPE
public static final java.lang.String APPLICATION_ATOM_XML
public static final MediaType APPLICATION_ATOM_XML_TYPE
public static final java.lang.String APPLICATION_VND_ERROR
public static final MediaType APPLICATION_VND_ERROR_TYPE
public static final java.lang.String TEXT_EVENT_STREAM
public static final MediaType TEXT_EVENT_STREAM_TYPE
public static final java.lang.String APPLICATION_JSON_STREAM
public static final MediaType APPLICATION_JSON_STREAM_TYPE
public static final java.lang.String APPLICATION_OCTET_STREAM
public static final MediaType APPLICATION_OCTET_STREAM_TYPE
public static final java.lang.String APPLICATION_GRAPHQL
public static final MediaType APPLICATION_GRAPHQL_TYPE
public static final java.lang.String IMAGE_PNG
public static final MediaType IMAGE_PNG_TYPE
public static final java.lang.String IMAGE_JPEG
public static final MediaType IMAGE_JPEG_TYPE
public static final java.lang.String IMAGE_GIF
public static final MediaType IMAGE_GIF_TYPE
public static final java.lang.String IMAGE_WEBP
public static final MediaType IMAGE_WEBP_TYPE
public static final java.lang.String CHARSET_PARAMETER
"charset"
.public static final java.lang.String Q_PARAMETER
"q"
.public static final java.lang.String V_PARAMETER
"v"
.protected final java.lang.String name
protected final java.lang.String subtype
protected final java.lang.String type
protected final java.lang.String extension
protected final java.util.Map<java.lang.CharSequence,java.lang.String> parameters
public MediaType(java.lang.String name)
name
- The name of the media type. For example application/jsonpublic MediaType(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> params)
name
- The name of the media type. For example application/jsonparams
- The parameterspublic MediaType(java.lang.String name, java.lang.String extension)
name
- The name of the media type. For example application/jsonextension
- The extension of the file using this media type if it differs from the subtypepublic MediaType(java.lang.String name, java.lang.String extension, java.util.Map<java.lang.String,java.lang.String> params)
name
- The name of the media type. For example application/jsonextension
- The extension of the file using this media type if it differs from the subtypeparams
- The parameterspublic boolean matches(@Nonnull MediaType expectedContentType)
expectedContentType
- Content type to match againstpublic java.lang.String getName()
public java.lang.String getType()
public java.lang.String getSubtype()
public java.lang.String getExtension()
public OptionalValues<java.lang.String> getParameters()
public java.lang.String getQuality()
public java.math.BigDecimal getQualityAsNumber()
public java.lang.String getVersion()
public java.util.Optional<java.nio.charset.Charset> getCharset()
public int length()
length
in interface java.lang.CharSequence
public char charAt(int index)
charAt
in interface java.lang.CharSequence
public java.lang.CharSequence subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
public boolean isTextBased()
public static boolean isTextBased(java.lang.String contentType)
contentType
- The content typepublic java.lang.String toString()
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
Only the name is matched. Parameters are not included.
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public static java.util.List<MediaType> orderedOf(java.lang.CharSequence... values)
values
- The valuespublic static java.util.List<MediaType> orderedOf(java.util.List<? extends java.lang.CharSequence> values)
values
- The valuespublic static MediaType of(java.lang.CharSequence mediaType)
MediaType
from the given text.mediaType
- The textMediaType
public static MediaType[] of(java.lang.CharSequence... mediaType)
MediaType
from the given text.mediaType
- The textMediaType
public static java.util.Optional<MediaType> fromType(java.lang.Class<?> type)
type
- The typeOptional
MediaType
public static java.util.Optional<MediaType> forExtension(java.lang.String extension)
MediaType
for the given file extension.extension
- The file extensionMediaType