Package org.apache.http.entity
Class ContentType
java.lang.Object
org.apache.http.entity.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 ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentType -
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.static ContentTypeget(HttpEntity entity) ExtractsContent-Typevalue fromHttpEntityexactly as specified by theContent-Typeheader of the entity.static ContentTypegetByMimeType(String mimeType) ReturnsContent-Typefor the given MIME type.static ContentTypegetLenient(HttpEntity entity) ExtractsContent-Typevalue fromHttpEntity.static ContentTypegetLenientOrDefault(HttpEntity entity) ExtractsContent-Typevalue fromHttpEntityor returns the default valueDEFAULT_TEXTif not explicitly specified or incorrect (could not be parsed).static ContentTypegetOrDefault(HttpEntity entity) ExtractsContent-Typevalue fromHttpEntityor returns the default valueDEFAULT_TEXTif not explicitly specified.getParameter(String name) static ContentTypeParses textual representation ofContent-Typevalue.toString()Generates textual representation of this content type which can be used as the value of aContent-Typeheader.withCharset(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
-
APPLICATION_ATOM_XML
-
APPLICATION_FORM_URLENCODED
-
APPLICATION_JSON
-
APPLICATION_OCTET_STREAM
-
APPLICATION_SVG_XML
-
APPLICATION_XHTML_XML
-
APPLICATION_XML
-
MULTIPART_FORM_DATA
-
TEXT_HTML
-
TEXT_PLAIN
-
TEXT_XML
-
WILDCARD
-
DEFAULT_TEXT
-
DEFAULT_BINARY
-
-
Method Details
-
getMimeType
-
getCharset
-
getParameter
- Since:
- 4.3
-
toString
Generates textual representation of this content type which can be used as the value of aContent-Typeheader. -
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
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
- Throws:
ParseException- if the given text does not represent a validContent-Typevalue.UnsupportedCharsetException- Thrown when the named charset is not available in this instance of the Java virtual machine
-
get
ExtractsContent-Typevalue fromHttpEntityexactly as specified by theContent-Typeheader of the entity. Returnsnullif not specified.- Parameters:
entity- HTTP entity- Returns:
- content type
- Throws:
ParseException- if the given text does not represent a validContent-Typevalue.UnsupportedCharsetException- Thrown when the named charset is not available in this instance of the Java virtual machine
-
getLenient
ExtractsContent-Typevalue fromHttpEntity. Returnsnullif not specified or incorrect (could not be parsed)..- Parameters:
entity- HTTP entity- Returns:
- content type
- Since:
- 4.4
-
getOrDefault
public static ContentType getOrDefault(HttpEntity entity) throws ParseException, UnsupportedCharsetException ExtractsContent-Typevalue fromHttpEntityor returns the default valueDEFAULT_TEXTif not explicitly specified.- Parameters:
entity- HTTP entity- Returns:
- content type
- Throws:
ParseException- if the given text does not represent a validContent-Typevalue.UnsupportedCharsetException- Thrown when the named charset is not available in this instance of the Java virtual machine
-
getLenientOrDefault
public static ContentType getLenientOrDefault(HttpEntity entity) throws ParseException, UnsupportedCharsetException ExtractsContent-Typevalue fromHttpEntityor returns the default valueDEFAULT_TEXTif not explicitly specified or incorrect (could not be parsed).- Parameters:
entity- HTTP entity- Returns:
- content type
- Throws:
ParseExceptionUnsupportedCharsetException- Since:
- 4.4
-
getByMimeType
ReturnsContent-Typefor the given MIME type.- Parameters:
mimeType- MIME type- Returns:
- content type or
nullif not known. - Since:
- 4.5
-
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-- Returns:
- a new instance with this MIME type and the given parameters.
- Throws:
UnsupportedCharsetException- Since:
- 4.4
-