public class MediaType extends Object
| Constructor and Description |
|---|
MediaType(String type,
String subtype)
Creates a new instance of
MediaType with the supplied type and subtype. |
MediaType(String type,
String subtype,
Map<String,String> parameters)
Creates a new instance of
MediaType with the supplied type, subtype and
parameters. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Compares
obj to this media type to see if they are the same by comparing
type, subtype and parameters. |
String |
getFullType()
Convert the media type to a string without parameters.
|
String |
getParameter(String name) |
boolean |
getParameterBoolean(String name,
boolean defaultValue) |
Integer |
getParameterInteger(String name) |
Map<String,String> |
getParameters()
Getter for a read-only parameter map.
|
String |
getSubtype()
Getter for subtype.
|
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.
|
static boolean |
quoted(String str) |
String |
toString()
Convert the media type to a string suitable for use as the value of a
corresponding HTTP header.
|
static MediaType |
valueOf(String type)
Creates a new instance of
MediaType by parsing the supplied string. |
MediaType |
withoutParameters()
Get an instance with same type and sub-type but without parameters.
|
MediaType |
withoutParameters(String... names)
Get an instance with same type and sub-type and parameters, but with
given parameters removed.
|
MediaType |
withParameter(String name,
String value)
Get an instance with same type, sub-type and parameters with an
additional parameter as given.
|
MediaType |
withParameters(Map<String,String> additionalParameters)
Get an instance with same type, sub-type and parameters with
additional parameters as given.
|
public MediaType(String type, String subtype, Map<String,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(String type, String subtype)
MediaType with the supplied type and subtype.type - the primary type, null is equivalent to
MEDIA_TYPE_WILDCARDsubtype - the subtype, null is equivalent to
MEDIA_TYPE_WILDCARDpublic static MediaType valueOf(String type)
MediaType by parsing the supplied string.type - the media type string.IllegalArgumentException - if the supplied string cannot be parsed
or is null.public String getType()
public boolean isWildcardType()
public String getSubtype()
public boolean isWildcardSubtype()
public Map<String,String> getParameters()
public MediaType withoutParameters()
public MediaType withoutParameters(String... names)
public MediaType withParameter(String name, String value)
public MediaType withParameters(Map<String,String> additionalParameters)
public boolean isCompatible(MediaType other)
other - the media type to compare with.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()
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 String getFullType()
public static boolean quoted(String str)
public boolean getParameterBoolean(String name, boolean defaultValue)
Copyright © 2013–2019 mklinger GmbH. All rights reserved.