public final class MediaType extends Object implements AcceptPredicate<MediaType>
| Modifier and Type | Class and Description |
|---|---|
static class |
MediaType.Builder
A fluent API builder to create instances of
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 String |
CHARSET_PARAMETER
The media type "charset" parameter name.
|
static 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 Predicate<MediaType> |
XML_PREDICATE
|
QUALITY_FACTOR_PARAMETER, WILDCARD_VALUE| Modifier and Type | Method and Description |
|---|---|
static MediaType.Builder |
builder()
A fluent API builder for creating customized Media type instances.
|
Optional<String> |
charset()
Gets
Optional value of charset parameter. |
static MediaType |
create(String type,
String subtype)
Creates a new instance of
MediaType with the supplied type and subtype. |
boolean |
equals(Object obj)
Compares
obj to this media type to see if they are the same by comparing
type, subtype and parameters. |
int |
hashCode()
Generate a hash code from the type, subtype and parameters.
|
boolean |
hasSuffix(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.
|
Map<String,String> |
parameters()
Getter for a read-only parameter map.
|
static MediaType |
parse(String input)
Parses a media type from its string representation.
|
double |
qualityFactor()
Gets quality factor parameter ("q") as a double value.
|
String |
subtype()
Getter for subtype.
|
boolean |
test(MediaType other)
Check if this media type is compatible with another media type.
|
String |
toString()
Convert the media type to a string suitable for use as the value of a corresponding HTTP header.
|
String |
type()
Getter for primary type.
|
MediaType |
withCharset(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 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 MediaType create(String type, 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 static MediaType parse(String input)
input - the input string representing a media typeMediaType instanceIllegalArgumentException - if the input is not parsableNullPointerException - if the input is nullpublic static MediaType.Builder builder()
public String type()
public boolean isWildcardType()
public String subtype()
public boolean isWildcardSubtype()
public Map<String,String> parameters()
public MediaType withCharset(String charset)
MediaType instance with the same type, subtype and parameters
copied from the original instance and the supplied "charset" parameter.public Optional<String> charset()
Optional value of charset parameter.public double qualityFactor()
AcceptPredicate1.0qualityFactor in interface AcceptPredicate<MediaType>public boolean test(MediaType other)
public boolean equals(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.
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.
public String toString()
public boolean hasSuffix(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–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.