public class MediaType
extends java.lang.Object
MediaTypes are immutable. The setter methods (e.g.
setType(String) and setSubtype(String)) return new
MediaType objects with the requested part changed and all other parts
copied.
Media types are defined in RFC 2046.
| Constructor and Description |
|---|
MediaType(java.lang.String mediaType)
Creates a new media type by parsing the given string.
|
MediaType(java.lang.String type,
java.lang.String subtype,
java.util.Map<java.lang.String,java.lang.String> parameters)
Creates a new media type.
|
MediaType(java.lang.String type,
java.lang.String subtype,
java.lang.String... parameters)
Creates a new media type.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
getCharsetRobust(java.lang.String expectedMimeType) |
static java.lang.String |
getCharsetRobustOrUTF(java.lang.String expectedMimeType) |
java.lang.String |
getParameter(java.lang.String name)
Returns the value of the parameter with the given name.
|
java.util.LinkedHashMap<java.lang.String,java.lang.String> |
getParameters() |
java.lang.String |
getPlainType()
Get the base type without any parameters
|
java.lang.String |
getSubtype()
Returns the subtype of this media type.
|
java.lang.String |
getType()
Returns the top-level type of this media type.
|
MediaType |
removeParameter(java.lang.String name)
Creates a new media type that has the same top-level type, subtype, and
parameters as this media type but has the parameter with the given name
removed.
|
MediaType |
setParameter(java.lang.String name,
java.lang.String value)
Creates a new media type that has the same top-level type, subtype, and
parameters as this media type but has the parameter with the given name
changed to the given value.
|
MediaType |
setSubtype(java.lang.String subtype)
Creates a new media type that has the same top-level type and parameters
as this media type and the given subtype as subtype.
|
MediaType |
setType(java.lang.String type)
Creates a new media type that has the same subtype and parameters as this
media type and the given type as top-level type.
|
java.lang.String |
toString() |
public MediaType(java.lang.String mediaType)
throws java.lang.NullPointerException,
java.net.MalformedURLException
mediaType - The media type to parsejava.lang.NullPointerException - if mediaType is nulljava.net.MalformedURLException - if mediaType is incorrectly formatted, i.e. does not
contain a slash, or a parameter does not contain an equals
signpublic MediaType(java.lang.String type,
java.lang.String subtype,
java.lang.String... parameters)
throws java.lang.IllegalArgumentException
type - The top-level typesubtype - The subtypeparameters - The parameters in key-value pairs, in the order key1,
value1, key2, value2, …java.lang.IllegalArgumentException - if an invalid number of parameters is given (i.e. the number
of parameters is odd)public MediaType(java.lang.String type,
java.lang.String subtype,
java.util.Map<java.lang.String,java.lang.String> parameters)
type - The top-level typesubtype - The subtypeparameters - The parameters of the media typepublic java.lang.String getType()
public MediaType setType(java.lang.String type)
type - The top-level type of the new media typepublic java.lang.String getSubtype()
public MediaType setSubtype(java.lang.String subtype)
subtype - The subtype of the new media typepublic java.lang.String getParameter(java.lang.String name)
name - The name of the parameternull if the media type
does not have a parameter with the given name)public MediaType setParameter(java.lang.String name, java.lang.String value)
name - The name of the parameter to changevalue - The new value of the parameter. Null = delete parameter.public MediaType removeParameter(java.lang.String name)
name - The name of the parameter to removepublic java.lang.String toString()
toString in class java.lang.Objectpublic static java.lang.String getCharsetRobust(java.lang.String expectedMimeType)
public static java.lang.String getCharsetRobustOrUTF(java.lang.String expectedMimeType)
public java.util.LinkedHashMap<java.lang.String,java.lang.String> getParameters()
public java.lang.String getPlainType()