public final class MediaType extends Object implements Serializable
* character is treated as a
wildcard and is used to represent any acceptable type or subtype value. All
values for type, subtype, parameter attributes or parameter values must be
valid according to RFCs 2045 and 2046. All portions of the media type that
are case-insensitive (type, subtype, parameter attributes) are normalized to
lowercase. Parameters' values are not modified except for the charset
parameter which is normalised to uppercase. Instances of this class are
immutable.| Modifier and Type | Field and Description |
|---|---|
static MediaType |
ANY_APPLICATION_TYPE
application/* |
static MediaType |
ANY_AUDIO_TYPE
audio/* |
static MediaType |
ANY_IMAGE_TYPE
image/* |
static MediaType |
ANY_TEXT_TYPE
text/* |
static MediaType |
ANY_TYPE
*/* |
static MediaType |
ANY_VIDEO_TYPE
video/* |
static MediaType |
CSS
text/css |
static MediaType |
GIF
image/gif |
static MediaType |
HTML
text/html |
static MediaType |
JPEG
image/jpeg |
static MediaType |
JSON
application/json |
static MediaType |
OCTET_STREAM
application/octet-stream |
static MediaType |
PLAIN_TEXT
text/plain |
static MediaType |
PNG
image/png |
static MediaType |
XML
application/xml |
| Modifier and Type | Method and Description |
|---|---|
Charset |
charset()
Returns the value of the charset parameter if it is specified, or
null otherwise. |
static MediaType |
create(String type,
String subtype)
Creates a new
MediaType with the given type and subtype. |
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
hasWildcard()
Returns whether the type or the subtype of this media type is the
wildcard.
|
boolean |
is(MediaType range)
Returns whether this media type is within the specified media range.
|
Map<String,String> |
parameters()
Returns the parameters of this media type.
|
static MediaType |
parse(String input)
Parses a
MediaType from its String representation. |
String |
subtype()
Returns the media subtype.
|
String |
toString() |
String |
type()
Returns the top-level media type.
|
MediaType |
withCharset(Charset charset)
Returns a new
MediaType instance similar to this one but with
the charset parameter set to the name of
the given charset. |
MediaType |
withoutParameter(String attribute)
Returns a new
MediaType instance similar to this one but
without the specified parameter. |
MediaType |
withoutParameters()
Returns a new
MediaType instance with the same type and
subtype as this instance but without any parameters. |
MediaType |
withParameter(String attribute,
String value)
Returns a new
MediaType instance similar to this one but with
the specified parameter set to the given value. |
MediaType |
withParameters(Map<String,String> parameters)
Returns a new
MediaType instance having the same type and
subtype as this one but whose parameters is the "union" of this
instances' parameters with the given ones (the given parameters have
precedence over this instance's parameters). |
public static final MediaType ANY_TYPE
*/*public static final MediaType ANY_TEXT_TYPE
text/*public static final MediaType ANY_IMAGE_TYPE
image/*public static final MediaType ANY_AUDIO_TYPE
audio/*public static final MediaType ANY_VIDEO_TYPE
video/*public static final MediaType ANY_APPLICATION_TYPE
application/*public static final MediaType JPEG
image/jpegpublic static final MediaType PNG
image/pngpublic static final MediaType GIF
image/gifpublic static final MediaType CSS
text/csspublic static final MediaType HTML
text/htmlpublic static final MediaType PLAIN_TEXT
text/plainpublic static final MediaType JSON
application/jsonpublic static final MediaType XML
application/xmlpublic static final MediaType OCTET_STREAM
application/octet-streampublic static MediaType parse(String input)
MediaType from its String representation.input - the input String to be parsed.MediaType instance.NullPointerException - if input is null.IllegalArgumentException - if input can't be parsed or
if a wildcard is used for the type, but not for the subtype.public static MediaType create(String type, String subtype)
MediaType with the given type and subtype.type - the type.subtype - the subtype.MediaType instance.NullPointerException - if one of the arguments is null.IllegalArgumentException - if type or subtype is invalid or if
a wildcard is used for the type, but not for the subtype.public String type()
public String subtype()
public Map<String,String> parameters()
Map
is immutable.public boolean hasWildcard()
public Charset charset()
null otherwise.null
otherwise.IllegalCharsetNameException - if the charset is illegal.UnsupportedCharsetException - if the charset is not supported.public MediaType withCharset(Charset charset)
MediaType instance similar to this one but with
the charset parameter set to the name of
the given charset.charset - the charset.MediaType.NullPointerException - if charset is null.public MediaType withParameter(String attribute, String value)
MediaType instance similar to this one but with
the specified parameter set to the given value.attribute - the attribute of the parameter to add.value - the value of the parameter to add.MediaType.NullPointerException - if one of the arguments is null.IllegalArgumentException - if attribute is invalid.public MediaType withParameters(Map<String,String> parameters)
MediaType instance having the same type and
subtype as this one but whose parameters is the "union" of this
instances' parameters with the given ones (the given parameters have
precedence over this instance's parameters).parameters - the parameters.MediaType.NullPointerException - if parameters is null or
if it contains the null key or a null value.IllegalArgumentException - if parameters contains an
invalid attribute.public MediaType withoutParameter(String attribute)
MediaType instance similar to this one but
without the specified parameter.attribute - the attribute of the parameter to remove.MediaType.NullPointerException - if attribute is null.public MediaType withoutParameters()
MediaType instance with the same type and
subtype as this instance but without any parameters.MediaType.public boolean is(MediaType range)
true if the type of range is the
wildcard or is equal to the type of this instance, and, if the
subtype of range is the wildcard or is equal to the subtype
of this instance, and, if all the parameters present in range
are also present in this instance.range - the range to check this media type against.NullPointerException - if range is null.Copyright © 2012–2015. All rights reserved.