public class MediaType extends java.lang.Object implements AcceptPredicate<MediaType>
| Modifier and Type | Field and Description |
|---|---|
static MediaType |
APPLICATION_ATOM_XML
A
MediaType constant representing application/atom+xml media type. |
static MediaType |
APPLICATION_FORM_URLENCODED
A
MediaType constant representing application/x-www-form-urlencoded media type. |
static MediaType |
APPLICATION_JSON
A
MediaType constant representing application/json media type. |
static MediaType |
APPLICATION_OCTET_STREAM
A
MediaType constant representing application/octet-stream media type. |
static MediaType |
APPLICATION_SVG_XML
A
MediaType constant representing application/svg+xml media type. |
static MediaType |
APPLICATION_XHTML_XML
A
MediaType constant representing application/xhtml+xml media type. |
static MediaType |
APPLICATION_XML
A
MediaType constant representing application/xml media type. |
static java.lang.String |
CHARSET_PARAMETER
The media type "charset" parameter name.
|
static java.util.function.Predicate<MediaType> |
JSON_PREDICATE
|
static MediaType |
MULTIPART_FORM_DATA
A
MediaType constant representing multipart/form-data media type. |
static MediaType |
TEXT_HTML
A
MediaType constant representing text/html media type. |
static MediaType |
TEXT_PLAIN
A
MediaType constant representing text/plain media type. |
static MediaType |
TEXT_XML
A
MediaType constant representing text/xml media type. |
static MediaType |
WILDCARD
A
MediaType constant representing wildcard media type. |
static java.util.function.Predicate<MediaType> |
XML_PREDICATE
|
QUALITY_FACTOR_PARAMETER, WILDCARD_VALUE| 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.Optional<java.lang.String> |
getCharset()
Gets
Optional value of charset parameter. |
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 |
hasSuffix(java.lang.String suffix)
Tests if this media type has provided Structured Syntax
suffix (RFC 6839). |
boolean |
isWildcardSubtype()
Checks if the subtype is a wildcard.
|
boolean |
isWildcardType()
Checks if the primary type is a wildcard.
|
static MediaType |
parse(java.lang.String input)
Parses a media type from its string representation.
|
double |
qualityFactor()
Gets quality factor parameter ("q") as a double value.
|
boolean |
test(MediaType other)
Check if this media type is compatible with another media type.
|
java.lang.String |
toString()
Convert the media type to a string suitable for use as the value of a corresponding HTTP header.
|
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
public static final MediaType WILDCARD
MediaType constant representing wildcard media type.public static final MediaType APPLICATION_XML
MediaType constant representing application/xml media type.public static final MediaType APPLICATION_ATOM_XML
MediaType constant representing application/atom+xml media type.public static final MediaType APPLICATION_XHTML_XML
MediaType constant representing application/xhtml+xml media type.public static final MediaType APPLICATION_SVG_XML
MediaType constant representing application/svg+xml media type.public static final MediaType APPLICATION_JSON
MediaType constant representing application/json media type.public static final MediaType APPLICATION_FORM_URLENCODED
MediaType constant representing application/x-www-form-urlencoded media type.public static final MediaType MULTIPART_FORM_DATA
MediaType constant representing multipart/form-data media type.public static final MediaType APPLICATION_OCTET_STREAM
MediaType constant representing application/octet-stream media type.public static final MediaType TEXT_PLAIN
MediaType constant representing text/plain media type.public static final MediaType TEXT_XML
MediaType constant representing text/xml media type.public static final MediaType TEXT_HTML
MediaType constant representing text/html media type.public static final java.util.function.Predicate<MediaType> XML_PREDICATE
public static final java.util.function.Predicate<MediaType> JSON_PREDICATE
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
AcceptPredicate.WILDCARD_VALUE.subtype - the subtype, null is equivalent to
AcceptPredicate.WILDCARD_VALUE.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
AcceptPredicate.WILDCARD_VALUEsubtype - the subtype, null is equivalent to
AcceptPredicate.WILDCARD_VALUEpublic 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 AcceptPredicate.WILDCARD_VALUEsubtype - the subtype, null is equivalent to AcceptPredicate.WILDCARD_VALUEcharset - 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 AcceptPredicate.WILDCARD_VALUE instead.public static MediaType parse(java.lang.String input)
input - the input string representing a media typeMediaType instancejava.lang.IllegalArgumentException - if the input is not parsablejava.lang.NullPointerException - if the input is nullpublic 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 java.util.Optional<java.lang.String> getCharset()
Optional value of charset parameter.public double qualityFactor()
AcceptPredicate1.0qualityFactor in interface AcceptPredicate<MediaType>public boolean test(MediaType other)
test in interface java.util.function.Predicate<MediaType>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.Objectobj - the object to compare to.public int hashCode()
Note that the 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.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean hasSuffix(java.lang.String suffix)
suffix (RFC 6839).
suffix - Suffix with or without '+' prefix. If null or empty then returns true if this media type
has ANY suffix.true if media type has specified suffix or has any suffix if parameter is null or empty.Copyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.