Package org.apache.hc.core5.http
Class ContentType
java.lang.Object
org.apache.hc.core5.http.ContentType
- All Implemented Interfaces:
Serializable
@Contract(threading=IMMUTABLE)
public final class ContentType
extends Object
implements Serializable
Content type information consisting of a MIME type and an optional charset.
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.
- Since:
- 4.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypePublic constant media type forapplication/x-ndjson.static final ContentTypestatic final ContentTypePublic constant media type forapplication/pdf.static final ContentTypePublic constant media type forapplication/problem+json.static final ContentTypePublic constant media type forapplication/problem+xml.static final ContentTypePublic constant media type forapplication/rss+xml.static final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypeprivate final Charsetprivate static final StringParam that representcharsetconstant.private static final Map<String, ContentType> Deprecated.To be removed in 6.0static final ContentTypestatic final ContentTypeprivate static final NameValuePair[]An empty immutableNameValuePairarray.static final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypeprivate final Stringstatic final ContentTypestatic final ContentTypePublic constant media type formultipart/mixed.static final ContentTypePublic constant media type formultipart/related.private final NameValuePair[]private static final longstatic final ContentTypePublic constant media type fortext/event-stream.static final ContentTypestatic final ContentTypePublic constant media type fortext/markdown.static final ContentTypestatic final ContentTypestatic final ContentType -
Constructor Summary
ConstructorsConstructorDescriptionContentType(String mimeType, Charset charset) ContentType(String mimeType, Charset charset, NameValuePair[] params) -
Method Summary
Modifier and TypeMethodDescriptionstatic ContentTypeCreates a new instance ofContentTypewithout a charset.static ContentTypeCreates a new instance ofContentType.static ContentTypeCreates a new instance ofContentType.static ContentTypecreate(String mimeType, NameValuePair... params) Creates a new instance ofContentTypewith the given parameters.private static ContentTypecreate(String mimeType, NameValuePair[] params, boolean strict) private static ContentTypecreate(HeaderElement helem, boolean strict) static ContentTypegetByMimeType(String mimeType) Deprecated.Do not use.getCharset(Charset defaultCharset) Gets this Charset if it's non-null, otherwise, return the givendefaultCharset.static CharsetgetCharset(ContentType contentType, Charset defaultCharset) Gets a ContentType's Charset if neither are null, otherwise, return the givendefaultCharset.getParameter(String name) booleanisSameMimeType(ContentType contentType) static ContentTypeParses textual representation ofContent-Typevalue.private static ContentTypeparse(CharSequence s, boolean strict) static ContentTypeParses textual representation ofContent-Typevalue ignoring invalid charsets.toString()Generates textual representation of this content type which can be used as the value of aContent-Typeheader.private static booleanwithCharset(String charset) Creates a new instance with this MIME type and the given Charset name.withCharset(Charset charset) Creates a new instance with this MIME type and the given Charset.withParameters(NameValuePair... params) Creates a new instance with this MIME type and the given parameters.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
CHARSET
Param that representcharsetconstant.- See Also:
-
APPLICATION_ATOM_XML
-
APPLICATION_FORM_URLENCODED
-
APPLICATION_JSON
-
APPLICATION_NDJSON
Public constant media type forapplication/x-ndjson.- Since:
- 5.1
-
APPLICATION_OCTET_STREAM
-
APPLICATION_PDF
Public constant media type forapplication/pdf.- Since:
- 5.1
-
APPLICATION_SOAP_XML
-
APPLICATION_SVG_XML
-
APPLICATION_XHTML_XML
-
APPLICATION_XML
-
APPLICATION_PROBLEM_JSON
Public constant media type forapplication/problem+json.- Since:
- 5.1
- See Also:
-
APPLICATION_PROBLEM_XML
Public constant media type forapplication/problem+xml.- Since:
- 5.1
- See Also:
-
APPLICATION_RSS_XML
Public constant media type forapplication/rss+xml.- Since:
- 5.1
-
IMAGE_BMP
-
IMAGE_GIF
-
IMAGE_JPEG
-
IMAGE_PNG
-
IMAGE_SVG
-
IMAGE_TIFF
-
IMAGE_WEBP
-
MULTIPART_FORM_DATA
-
MULTIPART_MIXED
Public constant media type formultipart/mixed.- Since:
- 5.1
-
MULTIPART_RELATED
Public constant media type formultipart/related.- Since:
- 5.1
-
TEXT_HTML
-
TEXT_MARKDOWN
Public constant media type fortext/markdown.- Since:
- 5.1
-
TEXT_PLAIN
-
TEXT_XML
-
TEXT_EVENT_STREAM
Public constant media type fortext/event-stream.- Since:
- 5.1
- See Also:
-
WILDCARD
-
EMPTY_NAME_VALUE_PAIR_ARRAY
An empty immutableNameValuePairarray. -
CONTENT_TYPE_MAP
Deprecated.To be removed in 6.0 -
DEFAULT_TEXT
-
DEFAULT_BINARY
-
mimeType
-
charset
-
params
-
-
Constructor Details
-
ContentType
-
ContentType
ContentType(String mimeType, Charset charset, NameValuePair[] params)
-
-
Method Details
-
getMimeType
-
getCharset
-
getCharset
Gets this Charset if it's non-null, otherwise, return the givendefaultCharset.- Parameters:
defaultCharset- A default Charset.- Returns:
- this Charset if it's non-null, or the given
defaultCharset. - Since:
- 5.2
-
getParameter
- Since:
- 4.3
-
toString
Generates textual representation of this content type which can be used as the value of aContent-Typeheader. -
valid
-
create
Creates a new instance ofContentType.- Parameters:
mimeType- MIME type. It may not benullor empty. It may not contain characters<">, <;>, <,>reserved by the HTTP specification.charset- charset.- Returns:
- content type
-
create
Creates a new instance ofContentTypewithout a charset.- Parameters:
mimeType- MIME type. It may not benullor empty. It may not contain characters<">, <;>, <,>reserved by the HTTP specification.- Returns:
- content type
-
create
public static ContentType create(String mimeType, String charset) throws UnsupportedCharsetException Creates a new instance ofContentType.- Parameters:
mimeType- MIME type. It may not benullor 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.- Returns:
- content type
- Throws:
UnsupportedCharsetException- Thrown when the named charset is not available in this instance of the Java virtual machine
-
create
-
create
-
create
public static ContentType create(String mimeType, NameValuePair... params) throws UnsupportedCharsetException Creates a new instance ofContentTypewith the given parameters.- Parameters:
mimeType- MIME type. It may not benullor empty. It may not contain characters<">, <;>, <,>reserved by the HTTP specification.params- parameters.- Returns:
- content type
- Throws:
UnsupportedCharsetException- Since:
- 4.4
-
parse
Parses textual representation ofContent-Typevalue.- Parameters:
s- text- Returns:
- content type
Content-Typevalue or null. - Throws:
UnsupportedCharsetException- Thrown when the named charset is not available in this instance of the Java virtual machine
-
parseLenient
Parses textual representation ofContent-Typevalue ignoring invalid charsets.- Parameters:
s- text- Returns:
- content type
Content-Typevalue or null. - Throws:
UnsupportedCharsetException- Thrown when the named charset is not available in this instance of the Java virtual machine
-
parse
- Throws:
UnsupportedCharsetException
-
getByMimeType
Deprecated.Do not use. This method was made public by mistake.ReturnsContent-Typefor the given MIME type.- Parameters:
mimeType- MIME type- Returns:
- content type or
nullif not known. - Since:
- 4.5
-
getCharset
Gets a ContentType's Charset if neither are null, otherwise, return the givendefaultCharset.- Parameters:
contentType- the ContentType to test and query.defaultCharset- a default Charset.- Returns:
- the ContentType's Charset if neither are null, otherwise, return the given
defaultCharset. - Since:
- 5.2
-
withCharset
Creates a new instance with this MIME type and the given Charset.- Parameters:
charset- charset- Returns:
- a new instance with this MIME type and the given Charset.
- Since:
- 4.3
-
withCharset
Creates a new instance with this MIME type and the given Charset name.- Parameters:
charset- name- Returns:
- a new instance with this MIME type and the given Charset name.
- Throws:
UnsupportedCharsetException- Thrown when the named charset is not available in this instance of the Java virtual machine- Since:
- 4.3
-
withParameters
Creates a new instance with this MIME type and the given parameters.- Parameters:
params- parameters.- Returns:
- a new instance with this MIME type and the given parameters.
- Throws:
UnsupportedCharsetException- Since:
- 4.4
-
isSameMimeType
-