@Contract(threading=IMMUTABLE) public final class ContentType extends Object implements 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 | Method and Description |
---|---|
static ContentType |
create(String mimeType)
Creates a new instance of
ContentType without a charset. |
static ContentType |
create(String mimeType,
Charset charset)
Creates a new instance of
ContentType . |
static ContentType |
create(String mimeType,
NameValuePair... params)
Creates a new instance of
ContentType with the given parameters. |
static ContentType |
create(String mimeType,
String charset)
Creates a new instance of
ContentType . |
static ContentType |
getByMimeType(String mimeType)
Deprecated.
Do not use. This method was made public by mistake.
|
Charset |
getCharset() |
Charset |
getCharset(Charset defaultCharset)
Gets this Charset if it's non-null, otherwise, return the given
defaultCharset . |
static Charset |
getCharset(ContentType contentType,
Charset defaultCharset)
Gets a ContentType's Charset if neither are null, otherwise, return the given
defaultCharset . |
String |
getMimeType() |
String |
getParameter(String name)
Gets the named parameter's value.
|
boolean |
isSameMimeType(ContentType contentType) |
static ContentType |
parse(CharSequence s)
Parses textual representation of
Content-Type value. |
static ContentType |
parseLenient(CharSequence s)
Parses textual representation of
Content-Type value ignoring invalid charsets. |
String |
toString()
Generates textual representation of this content type which can be used as the value
of a
Content-Type header. |
ContentType |
withCharset(Charset charset)
Creates a new instance with this MIME type and the given Charset.
|
ContentType |
withCharset(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_NDJSON
application/x-ndjson
.public static final ContentType APPLICATION_OCTET_STREAM
public static final ContentType APPLICATION_PDF
application/pdf
.public static final ContentType APPLICATION_SOAP_XML
public static final ContentType APPLICATION_SVG_XML
public static final ContentType APPLICATION_XHTML_XML
public static final ContentType APPLICATION_XML
public static final ContentType APPLICATION_PROBLEM_JSON
application/problem+json
.public static final ContentType APPLICATION_PROBLEM_XML
application/problem+xml
.public static final ContentType APPLICATION_RSS_XML
application/rss+xml
.public static final ContentType IMAGE_BMP
public static final ContentType IMAGE_GIF
public static final ContentType IMAGE_JPEG
public static final ContentType IMAGE_PNG
public static final ContentType IMAGE_SVG
public static final ContentType IMAGE_TIFF
public static final ContentType IMAGE_WEBP
public static final ContentType MULTIPART_FORM_DATA
public static final ContentType MULTIPART_MIXED
multipart/mixed
.public static final ContentType MULTIPART_RELATED
multipart/related
.public static final ContentType TEXT_HTML
public static final ContentType TEXT_MARKDOWN
text/markdown
.public static final ContentType TEXT_PLAIN
public static final ContentType TEXT_XML
public static final ContentType TEXT_EVENT_STREAM
text/event-stream
.public static final ContentType WILDCARD
public static final ContentType DEFAULT_TEXT
public static final ContentType DEFAULT_BINARY
public String getMimeType()
public Charset getCharset()
public Charset getCharset(Charset defaultCharset)
defaultCharset
.defaultCharset
- A default Charset.defaultCharset
.public String getParameter(String name)
name
- The parameter name.public String toString()
Content-Type
header.public static ContentType create(String mimeType, 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(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(String mimeType, String charset) throws 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.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static ContentType create(String mimeType, NameValuePair... params) throws 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.UnsupportedCharsetException
- If no support for a named Charset is available
in this instance of the Java virtual machine.public static ContentType parse(CharSequence s) throws UnsupportedCharsetException
Content-Type
value.s
- textContent-Type
value or null.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic static ContentType parseLenient(CharSequence s) throws UnsupportedCharsetException
Content-Type
value ignoring invalid charsets.s
- textContent-Type
value or null.UnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machine@Deprecated public static ContentType getByMimeType(String mimeType)
Content-Type
for the given MIME type.mimeType
- MIME typenull
if not known.public static Charset getCharset(ContentType contentType, Charset defaultCharset)
defaultCharset
.contentType
- the ContentType to test and query.defaultCharset
- a default Charset.defaultCharset
.public ContentType withCharset(Charset charset)
charset
- charsetpublic ContentType withCharset(String charset)
charset
- nameUnsupportedCharsetException
- Thrown when the named charset is not available in
this instance of the Java virtual machinepublic ContentType withParameters(NameValuePair... params) throws UnsupportedCharsetException
params
- parameters.UnsupportedCharsetException
- If no support for a named Charset is available
in this instance of the Java virtual machine.public boolean isSameMimeType(ContentType contentType)
Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.