public final class ContentType extends Object
ContentType
for OData library.
For more details on format and content of a ContentType
see
Media Type format as defined in
RFC 7231, chapter 3.1.1.1.
media-type = type "/" subtype *( OWS ";" OWS parameter ) type = token subtype = token OWS = *( SP / HTAB ) ; optional whitespace parameter = token "=" ( token / quoted-string )Once created a
ContentType
is IMMUTABLE.Modifier and Type | Field and Description |
---|---|
static ContentType |
APPLICATION_ATOM_SVC |
static ContentType |
APPLICATION_ATOM_XML |
static ContentType |
APPLICATION_ATOM_XML_ENTRY |
static ContentType |
APPLICATION_ATOM_XML_FEED |
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 |
MULTIPART_FORM_DATA |
static ContentType |
MULTIPART_MIXED |
static String |
PARAMETER_CHARSET_UTF8 |
static ContentType |
TEXT_HTML |
static ContentType |
TEXT_PLAIN |
static ContentType |
TEXT_XML |
Modifier and Type | Method and Description |
---|---|
static ContentType |
create(ContentType contentType,
String... parameters)
Creates a content type from an existing content type and additional key-value pairs for parameters.
|
static ContentType |
create(String format)
Creates a
ContentType based on given input string (format ). |
static ContentType |
create(String format,
String... parameters)
Creates a content type from format and key-value pairs for parameters.
|
boolean |
equals(Object obj)
|
Map<String,String> |
getParameters() |
String |
getSubtype() |
String |
getType() |
int |
hashCode() |
boolean |
isCompatible(ContentType other)
|
static boolean |
isParseable(String format)
Validates if given
format is parseable and can be used as input for create(String) method. |
static ContentType |
parse(String format)
Parses the given input string (
format ) and returns created ContentType if input was valid or
return NULL if input was not parseable. |
String |
toContentTypeString()
Gets
ContentType as string as defined in
RFC 7231, chapter 3.1.1.1:
Media Type. |
String |
toString() |
public static final ContentType APPLICATION_XML
public static final ContentType APPLICATION_ATOM_XML
public static final ContentType APPLICATION_ATOM_XML_ENTRY
public static final ContentType APPLICATION_ATOM_XML_FEED
public static final ContentType APPLICATION_ATOM_SVC
public static final ContentType APPLICATION_JSON
public static final ContentType APPLICATION_OCTET_STREAM
public static final ContentType APPLICATION_XHTML_XML
public static final ContentType TEXT_HTML
public static final ContentType TEXT_XML
public static final ContentType TEXT_PLAIN
public static final ContentType APPLICATION_SVG_XML
public static final ContentType APPLICATION_FORM_URLENCODED
public static final ContentType MULTIPART_MIXED
public static final ContentType MULTIPART_FORM_DATA
public static final String PARAMETER_CHARSET_UTF8
public static boolean isParseable(String format)
format
is parseable and can be used as input for create(String)
method.format
- to be validated stringtrue
if format is parseable otherwise false
public static ContentType create(String format, String... parameters)
format
- for example "application/json"parameters
- for example "a=b", "c=d"ContentType
objectpublic static ContentType create(ContentType contentType, String... parameters)
contentType
- for example "application/json"parameters
- for example "a=b", "c=d"ContentType
objectpublic static ContentType create(String format)
ContentType
based on given input string (format
). Supported format is
Media Type
format as defined in RFC 7231, chapter 3.1.1.1.format
- a string in format as defined in RFC 7231, chapter 3.1.1.1ContentType
objectIllegalArgumentException
- if input string is not parseablepublic static ContentType parse(String format)
format
) and returns created ContentType
if input was valid or
return NULL
if input was not parseable.
For the definition of the supported format see create(String)
.format
- a string in format as defined in RFC 7231, chapter 3.1.1.1ContentType
objectpublic String getType()
public String getSubtype()
public Map<String,String> getParameters()
ContentType
as unmodifiable map.public boolean isCompatible(ContentType other)
ContentType
s are compatible
if type
and subtype
have the same value.
The set parameters
are always ignored
(for compare with parameters see equals(Object)
).
true
if both instances are compatible (see definition above), otherwise false
.public String toContentTypeString()
ContentType
as string as defined in
RFC 7231, chapter 3.1.1.1:
Media Type.ContentType
objectCopyright © 2013–2015 The Apache Software Foundation. All rights reserved.