public class ContentType extends Object
A ContentType contains type, subtype, and parameters. The type, subtype, and parameter names are all converted to lower case.
The Content-Type header is originally defined in RFC2045. This implementation follows RFC2616 §14.17 Content-Type.
This class is immutable.
Modifier and Type | Field and Description |
---|---|
static ContentType |
text_plain_US_ASCII
ContentType of
"text/plain;charset=US-ASCII" . |
static ContentType |
text_plain_ISO88591
ContentType of
"text/plain;charset=ISO-8859-1" . |
static ContentType |
text_plain_UTF_8
ContentType of
"text/plain;charset=UTF-8" . |
static ContentType |
text_html_UTF_8
ContentType of
"text/html;charset=UTF-8" . |
static ContentType |
application_octet_stream
ContentType of
""application/octet-stream"" . |
Constructor and Description |
---|
ContentType(String type,
String subtype)
Create a ContentType, with no parameters.
|
ContentType(String type,
String subtype,
String parameterName,
String parameterValue)
Create a ContentType, with a single parameter.
|
ContentType(String type,
String subtype,
Map<String,String> parameters)
Create a ContentType.
|
Instance Methods | |
---|---|
String |
type()
The type, in lower case.
|
String |
subtype()
The subtype, in lower case.
|
String |
types()
The type and subtype, joined by "/".
|
Map<String,String> |
params()
The parameters as a Map.
|
String |
param(String name)
Get the value of the parameter with the name.
|
String |
toString()
The string form of this ContentType, for example,
"text/html;charset=UTF-8" . |
Static Method | |
ContentType |
parse(String contentTypeString)
Parse a string into a ContentType.
|
public static final ContentType text_plain_US_ASCII
"text/plain;charset=US-ASCII"
.public static final ContentType text_plain_ISO88591
"text/plain;charset=ISO-8859-1"
.public static final ContentType text_plain_UTF_8
"text/plain;charset=UTF-8"
.public static final ContentType text_html_UTF_8
"text/html;charset=UTF-8"
.public static final ContentType application_octet_stream
""application/octet-stream""
.public ContentType(String type, String subtype)
public String type()
CAUTION: This does not include the subtype. For both type and subtype, see types()
.
public String subtype()
public String types()
public Map<String,String> params()
The returned Map is immutable with only lower-case keys.
public String param(String name)
The name should be in lower-case.
public String toString()
"text/html;charset=UTF-8"
.public static ContentType parse(String contentTypeString) throws IllegalArgumentException
Example input string: "application/x-www-form-urlencoded"
IllegalArgumentException
- if the input string is not a valid Content-Type value.