public class MediaType
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPLICATION_ATOM_XML
A
String constant representing "application/atom+xml" media type. |
static MediaType |
APPLICATION_ATOM_XML_TYPE
A
MediaType constant representing "application/atom+xml" media type. |
static java.lang.String |
APPLICATION_FORM_URLENCODED
A
String constant representing "application/x-www-form-urlencoded" media type. |
static MediaType |
APPLICATION_FORM_URLENCODED_TYPE
A
MediaType constant representing "application/x-www-form-urlencoded" media type. |
static java.lang.String |
APPLICATION_JSON
A
String constant representing "application/json" media type. |
static java.lang.String |
APPLICATION_JSON_PATCH_JSON
String representation of "application/json-patch+json" media type.. |
static MediaType |
APPLICATION_JSON_PATCH_JSON_TYPE
A
MediaType constant representing "application/json-patch+json" media type. |
static MediaType |
APPLICATION_JSON_TYPE
A
MediaType constant representing "application/json" media type. |
static java.lang.String |
APPLICATION_OCTET_STREAM
A
String constant representing "application/octet-stream" media type. |
static MediaType |
APPLICATION_OCTET_STREAM_TYPE
A
MediaType constant representing "application/octet-stream" media type. |
static java.lang.String |
APPLICATION_SVG_XML
A
String constant representing "application/svg+xml" media type. |
static MediaType |
APPLICATION_SVG_XML_TYPE
A
MediaType constant representing "application/svg+xml" media type. |
static java.lang.String |
APPLICATION_XHTML_XML
A
String constant representing "application/xhtml+xml" media type. |
static MediaType |
APPLICATION_XHTML_XML_TYPE
A
MediaType constant representing "application/xhtml+xml" media type. |
static java.lang.String |
APPLICATION_XML
A
String constant representing "application/xml" media type. |
static MediaType |
APPLICATION_XML_TYPE
A
MediaType constant representing "application/xml" media type. |
static java.lang.String |
CHARSET_PARAMETER
The media type
charset parameter name. |
static java.lang.String |
MEDIA_TYPE_WILDCARD
The value of a type or subtype wildcard "*".
|
static java.lang.String |
MULTIPART_FORM_DATA
A
String constant representing "multipart/form-data" media type. |
static MediaType |
MULTIPART_FORM_DATA_TYPE
A
MediaType constant representing "multipart/form-data" media type. |
static java.lang.String |
SERVER_SENT_EVENTS
String representation of Server sent events media type. |
static MediaType |
SERVER_SENT_EVENTS_TYPE
Server sent events media type.
|
static java.lang.String |
TEXT_HTML
A
String constant representing "text/html" media type. |
static MediaType |
TEXT_HTML_TYPE
A
MediaType constant representing "text/html" media type. |
static java.lang.String |
TEXT_PLAIN
A
String constant representing "text/plain" media type. |
static MediaType |
TEXT_PLAIN_TYPE
A
MediaType constant representing "text/plain" media type. |
static java.lang.String |
TEXT_XML
A
String constant representing "text/xml" media type. |
static MediaType |
TEXT_XML_TYPE
A
MediaType constant representing "text/xml" media type. |
static java.lang.String |
WILDCARD
A
String constant representing wildcard "*/*" media type . |
static MediaType |
WILDCARD_TYPE
|
Constructor and Description |
---|
MediaType()
Creates a new instance of
MediaType , both type and subtype are wildcards. |
MediaType(java.lang.String type,
java.lang.String subtype)
Creates a new instance of
MediaType with the supplied type and subtype. |
MediaType(java.lang.String type,
java.lang.String subtype,
java.util.Map<java.lang.String,java.lang.String> parameters)
Creates a new instance of
MediaType with the supplied type, subtype and
parameters. |
MediaType(java.lang.String type,
java.lang.String subtype,
java.lang.String charset)
Creates a new instance of
MediaType with the supplied type, subtype and
"charset" parameter. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Compares
obj to this media type to see if they are the same by comparing
type, subtype and parameters. |
java.util.Map<java.lang.String,java.lang.String> |
getParameters()
Getter for a read-only parameter map.
|
java.lang.String |
getSubtype()
Getter for subtype.
|
java.lang.String |
getType()
Getter for primary type.
|
int |
hashCode()
Generate a hash code from the type, subtype and parameters.
|
boolean |
isCompatible(MediaType other)
Check if this media type is compatible with another media type.
|
boolean |
isWildcardSubtype()
Checks if the subtype is a wildcard.
|
boolean |
isWildcardType()
Checks if the primary type is a wildcard.
|
java.lang.String |
toString()
Convert the media type to a string suitable for use as the value of a
corresponding HTTP header.
|
static MediaType |
valueOf(java.lang.String type)
Creates a new instance of
MediaType by parsing the supplied string. |
MediaType |
withCharset(java.lang.String charset)
Create a new
MediaType instance with the same type, subtype and parameters
copied from the original instance and the supplied "charset" parameter. |
public static final java.lang.String CHARSET_PARAMETER
charset
parameter name.public static final java.lang.String MEDIA_TYPE_WILDCARD
public static final java.lang.String WILDCARD
String
constant representing wildcard "*/*" media type .public static final MediaType WILDCARD_TYPE
public static final java.lang.String APPLICATION_XML
String
constant representing "application/xml" media type.public static final MediaType APPLICATION_XML_TYPE
MediaType
constant representing "application/xml" media type.public static final java.lang.String APPLICATION_ATOM_XML
String
constant representing "application/atom+xml" media type.public static final MediaType APPLICATION_ATOM_XML_TYPE
MediaType
constant representing "application/atom+xml" media type.public static final java.lang.String APPLICATION_XHTML_XML
String
constant representing "application/xhtml+xml" media type.public static final MediaType APPLICATION_XHTML_XML_TYPE
MediaType
constant representing "application/xhtml+xml" media type.public static final java.lang.String APPLICATION_SVG_XML
String
constant representing "application/svg+xml" media type.public static final MediaType APPLICATION_SVG_XML_TYPE
MediaType
constant representing "application/svg+xml" media type.public static final java.lang.String APPLICATION_JSON
String
constant representing "application/json" media type.public static final MediaType APPLICATION_JSON_TYPE
MediaType
constant representing "application/json" media type.public static final java.lang.String APPLICATION_FORM_URLENCODED
String
constant representing "application/x-www-form-urlencoded" media type.public static final MediaType APPLICATION_FORM_URLENCODED_TYPE
MediaType
constant representing "application/x-www-form-urlencoded" media type.public static final java.lang.String MULTIPART_FORM_DATA
String
constant representing "multipart/form-data" media type.public static final MediaType MULTIPART_FORM_DATA_TYPE
MediaType
constant representing "multipart/form-data" media type.public static final java.lang.String APPLICATION_OCTET_STREAM
String
constant representing "application/octet-stream" media type.public static final MediaType APPLICATION_OCTET_STREAM_TYPE
MediaType
constant representing "application/octet-stream" media type.public static final java.lang.String TEXT_PLAIN
String
constant representing "text/plain" media type.public static final MediaType TEXT_PLAIN_TYPE
MediaType
constant representing "text/plain" media type.public static final java.lang.String TEXT_XML
String
constant representing "text/xml" media type.public static final MediaType TEXT_XML_TYPE
MediaType
constant representing "text/xml" media type.public static final java.lang.String TEXT_HTML
String
constant representing "text/html" media type.public static final MediaType TEXT_HTML_TYPE
MediaType
constant representing "text/html" media type.public static final java.lang.String SERVER_SENT_EVENTS
String
representation of Server sent events media type. (""text/event-stream"").public static final MediaType SERVER_SENT_EVENTS_TYPE
public static final java.lang.String APPLICATION_JSON_PATCH_JSON
String
representation of "application/json-patch+json" media type..public static final MediaType APPLICATION_JSON_PATCH_JSON_TYPE
MediaType
constant representing "application/json-patch+json" media type.public MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)
MediaType
with the supplied type, subtype and
parameters.type
- the primary type, null
is equivalent to
MEDIA_TYPE_WILDCARD
.subtype
- the subtype, null
is equivalent to
MEDIA_TYPE_WILDCARD
.parameters
- a map of media type parameters, null
is the same as an
empty map.public MediaType(java.lang.String type, java.lang.String subtype)
MediaType
with the supplied type and subtype.type
- the primary type, null
is equivalent to
MEDIA_TYPE_WILDCARD
subtype
- the subtype, null
is equivalent to
MEDIA_TYPE_WILDCARD
public MediaType(java.lang.String type, java.lang.String subtype, java.lang.String charset)
MediaType
with the supplied type, subtype and
"charset" parameter.type
- the primary type, null
is equivalent to
MEDIA_TYPE_WILDCARD
subtype
- the subtype, null
is equivalent to
MEDIA_TYPE_WILDCARD
charset
- the "charset" parameter value. If null
or empty
the "charset" parameter will not be set.public MediaType()
MediaType
, both type and subtype are wildcards.
Consider using the constant WILDCARD_TYPE
instead.public static MediaType valueOf(java.lang.String type)
MediaType
by parsing the supplied string.type
- the media type string.java.lang.IllegalArgumentException
- if the supplied string cannot be parsed
or is null
.public java.lang.String getType()
public boolean isWildcardType()
public java.lang.String getSubtype()
public boolean isWildcardSubtype()
public java.util.Map<java.lang.String,java.lang.String> getParameters()
public MediaType withCharset(java.lang.String charset)
MediaType
instance with the same type, subtype and parameters
copied from the original instance and the supplied "charset" parameter.public boolean isCompatible(MediaType other)
other
- the media type to compare with.public boolean equals(java.lang.Object obj)
obj
to this media type to see if they are the same by comparing
type, subtype and parameters. Note that the case-sensitivity of parameter
values is dependent on the semantics of the parameter name, see
HTTP/1.1.
This method assumes that values are case-sensitive.
Note that the equals(...)
implementation does not perform
a class equality check (this.getClass() == obj.getClass()
). Therefore
any class that extends from MediaType
class and needs to override
one of the equals(...)
and hashCode()
methods must
always override both methods to ensure the contract between
Object.equals(java.lang.Object)
and Object.hashCode()
does
not break.equals
in class java.lang.Object
obj
- the object to compare to.public int hashCode()
equals(java.lang.Object)
implementation does not perform
a class equality check (this.getClass() == obj.getClass()
). Therefore
any class that extends from MediaType
class and needs to override
one of the equals(Object)
and hashCode()
methods must
always override both methods to ensure the contract between
Object.equals(java.lang.Object)
and Object.hashCode()
does
not break.hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object