public class MediaType extends Object implements CharSequence
Modifier and Type | Field and Description |
---|---|
static String |
ALL
A wildcard media type representing all types.
|
static MediaType |
ALL_TYPE
A wildcard media type representing all types.
|
static String |
APPLICATION_ATOM_XML
Atom: application/atom+xml.
|
static MediaType |
APPLICATION_ATOM_XML_TYPE
Atom: application/atom+xml.
|
static 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 String |
APPLICATION_GRAPHQL
GraphQL: application/graphql.
|
static MediaType |
APPLICATION_GRAPHQL_TYPE
GraphQL: application/graphql.
|
static String |
APPLICATION_HAL_JSON
HAL JSON: application/hal+json.
|
static MediaType |
APPLICATION_HAL_JSON_TYPE
HAL JSON: application/hal+json.
|
static String |
APPLICATION_HAL_XML
HAL XML: application/hal+xml.
|
static MediaType |
APPLICATION_HAL_XML_TYPE
HAL XML: application/hal+xml.
|
static String |
APPLICATION_JSON
JSON: application/json.
|
static 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 String |
APPLICATION_OCTET_STREAM
BINARY: application/octet-stream.
|
static MediaType |
APPLICATION_OCTET_STREAM_TYPE
BINARY: application/octet-stream.
|
static String |
APPLICATION_VND_ERROR
VND Error: application/vnd.error+json.
|
static MediaType |
APPLICATION_VND_ERROR_TYPE
VND Error: application/vnd.error+json.
|
static String |
APPLICATION_XHTML
XHTML: application/xhtml+xml.
|
static MediaType |
APPLICATION_XHTML_TYPE
XHTML: application/xhtml+xml.
|
static String |
APPLICATION_XML
XML: application/xml.
|
static MediaType |
APPLICATION_XML_TYPE
XML: application/xml.
|
static String |
APPLICATION_YAML
YAML: application/x-yaml.
|
static MediaType |
APPLICATION_YAML_TYPE
YAML: application/x-yaml.
|
static String |
CHARSET_PARAMETER
Parameter
"charset" . |
static MediaType[] |
EMPTY_ARRAY
Default empty media type array.
|
protected String |
extension |
static String |
EXTENSION_JSON
Default file extension used for JSON.
|
static String |
EXTENSION_XML
Default file extension used for XML.
|
static MediaType |
FORM
Short cut for
APPLICATION_FORM_URLENCODED_TYPE . |
static String |
IMAGE_GIF
Gif Image: image/gif.
|
static MediaType |
IMAGE_GIF_TYPE
Gif Image: image/gif.
|
static String |
IMAGE_JPEG
Jpeg Image: image/jpeg.
|
static MediaType |
IMAGE_JPEG_TYPE
Jpeg Image: image/jpeg.
|
static String |
IMAGE_PNG
Png Image: image/png.
|
static MediaType |
IMAGE_PNG_TYPE
Png Image: image/png.
|
static String |
IMAGE_WEBP
Webp Image: image/webp.
|
static MediaType |
IMAGE_WEBP_TYPE
Webp Image: image/webp.
|
static 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 String |
name |
protected Map<CharSequence,String> |
parameters |
static String |
Q_PARAMETER
Parameter
"q" . |
protected String |
subtype |
static String |
TEXT_EVENT_STREAM
Server Sent Event: text/event-stream.
|
static MediaType |
TEXT_EVENT_STREAM_TYPE
Server Sent Event: text/event-stream.
|
static String |
TEXT_HTML
HTML: text/html.
|
static MediaType |
TEXT_HTML_TYPE
HTML: text/html.
|
static String |
TEXT_JSON
JSON: text/json.
|
static MediaType |
TEXT_JSON_TYPE
JSON: text/json.
|
static String |
TEXT_PLAIN
Plain Text: text/plain.
|
static MediaType |
TEXT_PLAIN_TYPE
Plain Text: text/plain.
|
static String |
TEXT_XML
XML: text/xml.
|
static MediaType |
TEXT_XML_TYPE
XML: text/xml.
|
protected String |
type |
static String |
V_PARAMETER
Parameter
"v" . |
Constructor and Description |
---|
MediaType(String name)
Constructs a new media type for the given string.
|
MediaType(String name,
Map<String,String> params)
Constructs a new media type for the given string and parameters.
|
MediaType(String name,
String extension)
Constructs a new media type for the given string and extension.
|
MediaType(String name,
String extension,
Map<String,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(Object o) |
static Optional<MediaType> |
forExtension(String extension)
Resolve the
MediaType for the given file extension. |
static MediaType |
forFilename(String filename)
Resolve the
MediaType for the given file name. |
static Optional<MediaType> |
fromType(Class<?> type)
|
Optional<Charset> |
getCharset() |
String |
getExtension() |
String |
getName() |
OptionalValues<String> |
getParameters() |
String |
getQuality() |
BigDecimal |
getQualityAsNumber() |
String |
getSubtype() |
String |
getType() |
String |
getVersion() |
int |
hashCode() |
boolean |
isTextBased() |
static boolean |
isTextBased(String contentType) |
int |
length() |
static MediaType[] |
of(CharSequence... mediaType)
Create a new
MediaType from the given text. |
static MediaType |
of(CharSequence mediaType)
Create a new
MediaType from the given text. |
CharSequence |
subSequence(int start,
int end) |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
chars, codePoints
public static final String EXTENSION_JSON
public static final String EXTENSION_XML
public static final MediaType[] EMPTY_ARRAY
public static final String ALL
public static final MediaType ALL_TYPE
public static final String APPLICATION_FORM_URLENCODED
public static final MediaType APPLICATION_FORM_URLENCODED_TYPE
public static final MediaType FORM
APPLICATION_FORM_URLENCODED_TYPE
.public static final String MULTIPART_FORM_DATA
public static final MediaType MULTIPART_FORM_DATA_TYPE
public static final String TEXT_HTML
public static final MediaType TEXT_HTML_TYPE
public static final String APPLICATION_XHTML
public static final MediaType APPLICATION_XHTML_TYPE
public static final String APPLICATION_XML
public static final MediaType APPLICATION_XML_TYPE
public static final String APPLICATION_JSON
public static final MediaType APPLICATION_JSON_TYPE
public static final String APPLICATION_YAML
public static final MediaType APPLICATION_YAML_TYPE
public static final String TEXT_XML
public static final MediaType TEXT_XML_TYPE
public static final String TEXT_JSON
public static final MediaType TEXT_JSON_TYPE
public static final String TEXT_PLAIN
public static final MediaType TEXT_PLAIN_TYPE
public static final String APPLICATION_HAL_JSON
public static final MediaType APPLICATION_HAL_JSON_TYPE
public static final String APPLICATION_HAL_XML
public static final MediaType APPLICATION_HAL_XML_TYPE
public static final String APPLICATION_ATOM_XML
public static final MediaType APPLICATION_ATOM_XML_TYPE
public static final String APPLICATION_VND_ERROR
public static final MediaType APPLICATION_VND_ERROR_TYPE
public static final String TEXT_EVENT_STREAM
public static final MediaType TEXT_EVENT_STREAM_TYPE
public static final String APPLICATION_JSON_STREAM
public static final MediaType APPLICATION_JSON_STREAM_TYPE
public static final String APPLICATION_OCTET_STREAM
public static final MediaType APPLICATION_OCTET_STREAM_TYPE
public static final String APPLICATION_GRAPHQL
public static final MediaType APPLICATION_GRAPHQL_TYPE
public static final String IMAGE_PNG
public static final MediaType IMAGE_PNG_TYPE
public static final String IMAGE_JPEG
public static final MediaType IMAGE_JPEG_TYPE
public static final String IMAGE_GIF
public static final MediaType IMAGE_GIF_TYPE
public static final String IMAGE_WEBP
public static final MediaType IMAGE_WEBP_TYPE
public static final String CHARSET_PARAMETER
"charset"
.public static final String Q_PARAMETER
"q"
.public static final String V_PARAMETER
"v"
.protected final String name
protected final String subtype
protected final String type
protected final String extension
protected final Map<CharSequence,String> parameters
public MediaType(String name)
name
- The name of the media type. For example application/jsonpublic MediaType(String name, Map<String,String> params)
name
- The name of the media type. For example application/jsonparams
- The parameterspublic MediaType(String name, 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(String name, String extension, Map<String,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 String getName()
public String getType()
public String getSubtype()
public String getExtension()
public OptionalValues<String> getParameters()
public String getQuality()
public BigDecimal getQualityAsNumber()
public String getVersion()
public Optional<Charset> getCharset()
public int length()
length
in interface CharSequence
public char charAt(int index)
charAt
in interface CharSequence
public CharSequence subSequence(int start, int end)
subSequence
in interface CharSequence
public boolean isTextBased()
public static boolean isTextBased(String contentType)
contentType
- The content typepublic String toString()
toString
in interface CharSequence
toString
in class Object
public boolean equals(Object o)
Only the name is matched. Parameters are not included.
public static MediaType of(CharSequence mediaType)
MediaType
from the given text.mediaType
- The textMediaType
public static MediaType[] of(CharSequence... mediaType)
MediaType
from the given text.mediaType
- The textMediaType
public static Optional<MediaType> forExtension(String extension)
MediaType
for the given file extension.extension
- The file extensionMediaType