@Immutable public final class ContentType extends java.lang.Object implements java.io.Serializable
This class makes no attempts to verify validity of the MIME type.
The input parameters of the create(String, String)
method, however, may not
contain characters <">, <;>, <,>
reserved by the HTTP specification.
Modifier and Type | Field and Description |
---|---|
static ContentType |
APPLICATION_ATOM_XML |
static ContentType |
APPLICATION_FORM_URLENCODED |
static ContentType |
APPLICATION_JSON |
static ContentType |
APPLICATION_OCTET_STREAM |
static ContentType |
APPLICATION_SVG_XML |
static ContentType |
APPLICATION_XHTML_XML |
static ContentType |
APPLICATION_XML |
static ContentType |
DEFAULT_BINARY |
static ContentType |
DEFAULT_TEXT |
static ContentType |
MULTIPART_FORM_DATA |
static ContentType |
TEXT_HTML |
static ContentType |
TEXT_PLAIN |
static ContentType |
TEXT_XML |
static ContentType |
WILDCARD |
Constructor and Description |
---|
ContentType(java.lang.String mimeType,
java.nio.charset.Charset charset) |
ContentType(java.lang.String mimeType,
java.nio.charset.Charset charset,
NameValuePair[] params) |
Modifier and Type | Method and Description |
---|---|
static ContentType |
create(java.lang.String mimeType)
Creates a new instance of
ContentType without a charset. |
static ContentType |
create(java.lang.String mimeType,
java.nio.charset.Charset charset)
Creates a new instance of
ContentType . |
static ContentType |
create(java.lang.String mimeType,
NameValuePair... params)
Creates a new instance of
ContentType with the given parameters. |
static ContentType |
create(java.lang.String mimeType,
java.lang.String charset)
Creates a new instance of
ContentType . |
static ContentType |
get(HttpEntity entity)
Extracts
Content-Type value from HttpEntity exactly as
specified by the Content-Type header of the entity. |
java.nio.charset.Charset |
getCharset() |
static ContentType |
getLenient(HttpEntity entity)
Extracts
Content-Type value from HttpEntity . |
static ContentType |
getLenientOrDefault(HttpEntity entity)
Extracts
Content-Type value from HttpEntity or returns the default value
DEFAULT_TEXT if not explicitly specified or incorrect (could not be parsed). |
java.lang.String |
getMimeType() |
static ContentType |
getOrDefault(HttpEntity entity)
Extracts
Content-Type value from HttpEntity or returns the default value
DEFAULT_TEXT if not explicitly specified. |
java.lang.String |
getParameter(java.lang.String name) |
static ContentType |
parse(java.lang.String s)
Parses textual representation of
Content-Type value. |
java.lang.String |
toString()
Generates textual representation of this content type which can be used as the value
of a
Content-Type header. |
ContentType |
withCharset(java.nio.charset.Charset charset)
Creates a new instance with this MIME type and the given Charset.
|
ContentType |
withCharset(java.lang.String charset)
Creates a new instance with this MIME type and the given Charset name.
|
ContentType |
withParameters(NameValuePair... params)
Creates a new instance with this MIME type and the given parameters.
|
public static final ContentType APPLICATION_ATOM_XML
public static final ContentType APPLICATION_FORM_URLENCODED
public static final ContentType APPLICATION_JSON
public static final ContentType APPLICATION_OCTET_STREAM
public static final ContentType APPLICATION_SVG_XML
public static final ContentType APPLICATION_XHTML_XML
public static final ContentType APPLICATION_XML
public static final ContentType MULTIPART_FORM_DATA
public static final ContentType TEXT_HTML
public static final ContentType TEXT_PLAIN
public static final ContentType TEXT_XML
public static final ContentType WILDCARD
public static final ContentType DEFAULT_TEXT
public static final ContentType DEFAULT_BINARY
ContentType(java.lang.String mimeType, java.nio.charset.Charset charset)
ContentType(java.lang.String mimeType, java.nio.charset.Charset charset, NameValuePair[] params)
public java.lang.String getMimeType()
public java.nio.charset.Charset getCharset()
public java.lang.String getParameter(java.lang.String name)
public java.lang.String toString()
Content-Type
header.toString
in class java.lang.Object
public static ContentType create(java.lang.String mimeType, java.nio.charset.Charset charset)
ContentType
.mimeType
- MIME type. It may not be null
or empty. It may not contain
characters <">, <;>, <,>
reserved by the HTTP specification.charset
- charset.public static ContentType create(java.lang.String mimeType)
ContentType
without a charset.mimeType
- MIME type. It may not be null
or empty. It may not contain
characters <">, <;>, <,>
reserved by the HTTP specification.public static ContentType create(java.lang.String mimeType, java.lang.String charset) throws java.nio.charset.UnsupportedCharsetException
ContentType
.mimeType
- MIME type. It may not be null
or empty. It may not contain
characters <">, <;>, <,>
reserved by the HTTP specification.charset
- charset. It may not contain characters <">, <;>, <,>
reserved by the HTTP
specification. This parameter is optional.java.nio.charset.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static ContentType create(java.lang.String mimeType, NameValuePair... params) throws java.nio.charset.UnsupportedCharsetException
ContentType
with the given parameters.mimeType
- MIME type. It may not be null
or empty. It may not contain
characters <">, <;>, <,>
reserved by the HTTP specification.params
- parameters.java.nio.charset.UnsupportedCharsetException
public static ContentType parse(java.lang.String s) throws ParseException, java.nio.charset.UnsupportedCharsetException
Content-Type
value.s
- textParseException
- if the given text does not represent a valid
Content-Type
value.java.nio.charset.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static ContentType get(HttpEntity entity) throws ParseException, java.nio.charset.UnsupportedCharsetException
Content-Type
value from HttpEntity
exactly as
specified by the Content-Type
header of the entity. Returns null
if not specified.entity
- HTTP entityParseException
- if the given text does not represent a valid
Content-Type
value.java.nio.charset.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static ContentType getLenient(HttpEntity entity)
Content-Type
value from HttpEntity
. Returns null
if not specified or incorrect (could not be parsed)..entity
- HTTP entitypublic static ContentType getOrDefault(HttpEntity entity) throws ParseException, java.nio.charset.UnsupportedCharsetException
Content-Type
value from HttpEntity
or returns the default value
DEFAULT_TEXT
if not explicitly specified.entity
- HTTP entityParseException
- if the given text does not represent a valid
Content-Type
value.java.nio.charset.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static ContentType getLenientOrDefault(HttpEntity entity) throws ParseException, java.nio.charset.UnsupportedCharsetException
Content-Type
value from HttpEntity
or returns the default value
DEFAULT_TEXT
if not explicitly specified or incorrect (could not be parsed).entity
- HTTP entityParseException
java.nio.charset.UnsupportedCharsetException
public ContentType withCharset(java.nio.charset.Charset charset)
charset
- charsetpublic ContentType withCharset(java.lang.String charset)
charset
- namejava.nio.charset.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic ContentType withParameters(NameValuePair... params) throws java.nio.charset.UnsupportedCharsetException
params
- java.nio.charset.UnsupportedCharsetException