Package io.micronaut.http
Class MediaType
java.lang.Object
io.micronaut.http.MediaType
- All Implemented Interfaces:
CharSequence
Represents a media type.
See https://www.iana.org/assignments/media-types/media-types.xhtml and https://tools.ietf.org/html/rfc2046
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
A wildcard media type representing all types.static final MediaType
A wildcard media type representing all types.static final String
Atom: application/atom+xml.static final MediaType
Atom: application/atom+xml.static final String
Form encoded data: application/x-www-form-urlencoded.static final MediaType
Form encoded data: application/x-www-form-urlencoded.static final String
GraphQL: application/graphql.static final MediaType
GraphQL: application/graphql.static final String
HAL JSON: application/hal+json.static final MediaType
HAL JSON: application/hal+json.static final String
HAL XML: application/hal+xml.static final MediaType
HAL XML: application/hal+xml.static final String
JSON: application/json.static final String
JSON Feed: application/feed+json.static final MediaType
JSON Feed: application/feed+json.static final String
JSON GitHub: application/vnd.github+json.static final MediaType
JSON GitHub: application/vnd.github+json.static final String
JSON Feed: application/problem+json.static final MediaType
JSON Feed: application/problem+json.static final String
JSON Stream: application/x-json-stream.static final MediaType
JSON Stream: application/x-json-stream.static final MediaType
JSON: application/json.static final String
BINARY: application/octet-stream.static final MediaType
BINARY: application/octet-stream.static final String
PDF: application/pdf.static final MediaType
PDF: application/pdf.static final String
VND Error: application/vnd.error+json.static final MediaType
VND Error: application/vnd.error+json.static final String
XHTML: application/xhtml+xml.static final MediaType
XHTML: application/xhtml+xml.static final String
XML: application/xml.static final MediaType
XML: application/xml.static final String
YAML: application/x-yaml.static final MediaType
YAML: application/x-yaml.static final String
Parameter"charset"
.static final MediaType[]
Default empty media type array.protected final String
static final String
Default file extension used for JSON.static final String
Default file extension used for PDF.static final String
File extension for Microsoft Excel's workbook files in use between 97-2003.static final String
File extension used for Microsoft Excel Open XML Spreadsheet (XLSX).static final String
Default file extension used for XML.static final MediaType
Shortcut forAPPLICATION_FORM_URLENCODED_TYPE
.static final String
Gif Image: image/gif.static final MediaType
Gif Image: image/gif.static final String
Jpeg Image: image/jpeg.static final MediaType
Jpeg Image: image/jpeg.static final String
Png Image: image/png.static final MediaType
Png Image: image/png.static final String
Webp Image: image/webp.static final MediaType
Webp Image: image/webp.static final String
Microsoft Excel's workbook files in use between 97-2003.static final String
XML: Microsoft Excel Open XML Spreadsheet (XLSX).static final MediaType
XML: Microsoft Excel Open XML Spreadsheet (XLSX).static final MediaType
Microsoft Excel's workbook files in use between 97-2003.static final String
Multi part form data: multipart/form-data.static final MediaType
Multi part form data: multipart/form-data.protected final String
protected final Map<CharSequence,
String> static final String
Parameter"q"
.protected final String
static final String
CSV: text/csv.static final MediaType
CSV: text/csv.static final String
Server Sent Event: text/event-stream.static final MediaType
Server Sent Event: text/event-stream.static final String
HTML: text/html.static final MediaType
HTML: text/html.static final String
JSON: text/json.static final MediaType
JSON: text/json.static final String
Plain Text: text/plain.static final MediaType
Plain Text: text/plain.static final String
XML: text/xml.static final MediaType
XML: text/xml.protected final String
static final String
Parameter"v"
. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new media type for the given string.Constructs a new media type for the given string and extension.Constructs a new media type for the given string and extension.Constructs a new media type for the given string and parameters. -
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) boolean
forExtension
(String extension) Resolve theMediaType
for the given file extension.static MediaType
forFilename
(String filename) Resolve theMediaType
for the given file name.getName()
getType()
int
hashCode()
boolean
static boolean
isTextBased
(String contentType) int
length()
boolean
Determine if this requested content type can be satisfied by a given content type.static MediaType
of
(CharSequence mediaType) Create a newMediaType
from the given text.static MediaType[]
of
(CharSequence... mediaType) Create a newMediaType
from the given text.static MediaType
Create a new or get aMediaType
from the given text.orderedOf
(CharSequence... values) Returns the ordered media types for the given values.orderedOf
(List<? extends CharSequence> values) Returns the ordered media types for the given values.subSequence
(int start, int end) toString()
void
Validate this media type for sending as an HTTP header.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
EXTENSION_JSON
Default file extension used for JSON.- See Also:
-
EXTENSION_XML
Default file extension used for XML.- See Also:
-
EXTENSION_PDF
Default file extension used for PDF.- See Also:
-
EXTENSION_XLSX
File extension used for Microsoft Excel Open XML Spreadsheet (XLSX).- See Also:
-
EXTENSION_XLS
File extension for Microsoft Excel's workbook files in use between 97-2003.- See Also:
-
EMPTY_ARRAY
Default empty media type array. -
ALL
A wildcard media type representing all types.- See Also:
-
ALL_TYPE
A wildcard media type representing all types. -
APPLICATION_FORM_URLENCODED
Form encoded data: application/x-www-form-urlencoded.- See Also:
-
APPLICATION_FORM_URLENCODED_TYPE
Form encoded data: application/x-www-form-urlencoded. -
FORM
Shortcut forAPPLICATION_FORM_URLENCODED_TYPE
. -
MULTIPART_FORM_DATA
Multi part form data: multipart/form-data.- See Also:
-
MULTIPART_FORM_DATA_TYPE
Multi part form data: multipart/form-data. -
TEXT_HTML
HTML: text/html.- See Also:
-
TEXT_HTML_TYPE
HTML: text/html. -
TEXT_CSV
CSV: text/csv.- See Also:
-
TEXT_CSV_TYPE
CSV: text/csv. -
APPLICATION_XHTML
XHTML: application/xhtml+xml.- See Also:
-
APPLICATION_XHTML_TYPE
XHTML: application/xhtml+xml. -
APPLICATION_XML
XML: application/xml.- See Also:
-
APPLICATION_XML_TYPE
XML: application/xml. -
APPLICATION_JSON_GITHUB
JSON GitHub: application/vnd.github+json.- See Also:
-
APPLICATION_JSON_GITHUB_TYPE
JSON GitHub: application/vnd.github+json. -
APPLICATION_JSON_FEED
JSON Feed: application/feed+json.- See Also:
-
APPLICATION_JSON_FEED_TYPE
JSON Feed: application/feed+json. -
APPLICATION_JSON_PROBLEM
JSON Feed: application/problem+json.- See Also:
-
APPLICATION_JSON_PROBLEM_TYPE
JSON Feed: application/problem+json. -
APPLICATION_JSON
JSON: application/json.- See Also:
-
APPLICATION_JSON_TYPE
JSON: application/json. -
APPLICATION_YAML
YAML: application/x-yaml.- See Also:
-
APPLICATION_YAML_TYPE
YAML: application/x-yaml. -
MICROSOFT_EXCEL_OPEN_XML
XML: Microsoft Excel Open XML Spreadsheet (XLSX).- See Also:
-
MICROSOFT_EXCEL_OPEN_XML_TYPE
XML: Microsoft Excel Open XML Spreadsheet (XLSX). -
MICROSOFT_EXCEL
Microsoft Excel's workbook files in use between 97-2003.- See Also:
-
MICROSOFT_EXCEL_TYPE
Microsoft Excel's workbook files in use between 97-2003. -
TEXT_XML
XML: text/xml.- See Also:
-
TEXT_XML_TYPE
XML: text/xml. -
TEXT_JSON
JSON: text/json.- See Also:
-
TEXT_JSON_TYPE
JSON: text/json. -
TEXT_PLAIN
Plain Text: text/plain.- See Also:
-
TEXT_PLAIN_TYPE
Plain Text: text/plain. -
APPLICATION_HAL_JSON
HAL JSON: application/hal+json.- See Also:
-
APPLICATION_HAL_JSON_TYPE
HAL JSON: application/hal+json. -
APPLICATION_HAL_XML
HAL XML: application/hal+xml.- See Also:
-
APPLICATION_HAL_XML_TYPE
HAL XML: application/hal+xml. -
APPLICATION_ATOM_XML
Atom: application/atom+xml.- See Also:
-
APPLICATION_ATOM_XML_TYPE
Atom: application/atom+xml. -
APPLICATION_VND_ERROR
VND Error: application/vnd.error+json.- See Also:
-
APPLICATION_VND_ERROR_TYPE
VND Error: application/vnd.error+json. -
TEXT_EVENT_STREAM
Server Sent Event: text/event-stream.- See Also:
-
TEXT_EVENT_STREAM_TYPE
Server Sent Event: text/event-stream. -
APPLICATION_JSON_STREAM
JSON Stream: application/x-json-stream.- See Also:
-
APPLICATION_JSON_STREAM_TYPE
JSON Stream: application/x-json-stream. -
APPLICATION_OCTET_STREAM
BINARY: application/octet-stream.- See Also:
-
APPLICATION_OCTET_STREAM_TYPE
BINARY: application/octet-stream. -
APPLICATION_GRAPHQL
GraphQL: application/graphql.- See Also:
-
APPLICATION_GRAPHQL_TYPE
GraphQL: application/graphql. -
APPLICATION_PDF
PDF: application/pdf.- See Also:
-
APPLICATION_PDF_TYPE
PDF: application/pdf. -
IMAGE_PNG
Png Image: image/png.- See Also:
-
IMAGE_PNG_TYPE
Png Image: image/png. -
IMAGE_JPEG
Jpeg Image: image/jpeg.- See Also:
-
IMAGE_JPEG_TYPE
Jpeg Image: image/jpeg. -
IMAGE_GIF
Gif Image: image/gif.- See Also:
-
IMAGE_GIF_TYPE
Gif Image: image/gif. -
IMAGE_WEBP
Webp Image: image/webp.- See Also:
-
IMAGE_WEBP_TYPE
Webp Image: image/webp. -
CHARSET_PARAMETER
Parameter"charset"
.- See Also:
-
Q_PARAMETER
Parameter"q"
.- See Also:
-
V_PARAMETER
Parameter"v"
.- See Also:
-
name
-
subtype
-
type
-
extension
-
parameters
-
-
Constructor Details
-
MediaType
Constructs a new media type for the given string.- Parameters:
name
- The name of the media type. For example application/json
-
MediaType
Constructs a new media type for the given string and parameters.- Parameters:
name
- The name of the media type. For example application/jsonparams
- The parameters
-
MediaType
Constructs a new media type for the given string and extension.- Parameters:
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 subtype
-
MediaType
Constructs a new media type for the given string and extension.- Parameters:
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 parameters
-
-
Method Details
-
of
Create a new or get aMediaType
from the given text.- Parameters:
mediaType
- The text- Returns:
- The
MediaType
-
matches
Determine if this requested content type can be satisfied by a given content type. e.g. text/* will be satisfied by test/html.- Parameters:
expectedContentType
- Content type to match against- Returns:
- if successful match
-
getName
- Returns:
- The name of the mime type without any parameters
-
getType
- Returns:
- The type of the media type. For example for application/hal+json this would return "application"
-
getSubtype
- Returns:
- The subtype. For example for application/hal+json this would return "hal+json"
-
getExtension
- Returns:
- The extension. For example for application/hal+json this would return "json"
-
getParameters
- Returns:
- The parameters to the media type
-
getQuality
- Returns:
- The quality of the Mime type
-
getQualityAsNumber
- Returns:
- The quality in BigDecimal form
-
getVersion
- Returns:
- The version of the Mime type
-
getCharset
- Returns:
- The charset of the media type if specified
-
length
public int length()- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) - Specified by:
charAt
in interfaceCharSequence
-
subSequence
- Specified by:
subSequence
in interfaceCharSequence
-
isTextBased
public boolean isTextBased()- Returns:
- Whether the media type is text based
-
isTextBased
- Parameters:
contentType
- The content type- Returns:
- Whether the content type is text based
-
validate
Validate this media type for sending as an HTTP header. This is an optimization to only run the validation once if possible. If the validation function does not throw, future calls to this method will not call the validation function again.- Parameters:
r
- Validation function
-
toString
- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-
equals
Only the name is matched. Parameters are not included.
-
hashCode
public int hashCode() -
orderedOf
Returns the ordered media types for the given values.- Parameters:
values
- The values- Returns:
- The media types.
- Since:
- 1.3.3
-
orderedOf
Returns the ordered media types for the given values.- Parameters:
values
- The values- Returns:
- The media types.
- Since:
- 1.3.3
-
of
Create a newMediaType
from the given text.- Parameters:
mediaType
- The text- Returns:
- The
MediaType
-
of
Create a newMediaType
from the given text.- Parameters:
mediaType
- The text- Returns:
- The
MediaType
-
fromType
-
forExtension
Resolve theMediaType
for the given file extension.- Parameters:
extension
- The file extension- Returns:
- The
MediaType
-
forFilename
Resolve theMediaType
for the given file name. Defaults to text/plain.- Parameters:
filename
- The file name- Returns:
- The
MediaType
-