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 | Method and Description |
---|---|
static ContentType |
create(ContentType contentType,
String parameterName,
String parameterValue)
Creates a content type from an existing content type and an additional parameter as key-value pair.
|
static ContentType |
create(String format)
Creates a
ContentType based on given input string (format ). |
boolean |
equals(Object obj)
|
String |
getParameter(String name)
Returns the value of a given parameter.
|
Map<String,String> |
getParameters()
Gets the parameters of this content type.
|
String |
getSubtype()
Gets the subtype of this content type.
|
String |
getType()
Gets the type of this content type.
|
int |
hashCode() |
boolean |
isCompatible(ContentType other)
|
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 String PARAMETER_CHARSET
public static final String PARAMETER_IEEE754_COMPATIBLE
public static final String PARAMETER_ODATA_METADATA
public static final String VALUE_ODATA_METADATA_NONE
public static final String VALUE_ODATA_METADATA_MINIMAL
public static final String VALUE_ODATA_METADATA_FULL
public static final ContentType APPLICATION_JSON
public static final ContentType JSON
public static final ContentType JSON_NO_METADATA
public static final ContentType JSON_FULL_METADATA
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_ENTRY_UTF8
public static final ContentType APPLICATION_ATOM_XML_FEED
public static final ContentType APPLICATION_ATOM_XML_FEED_UTF8
public static final ContentType APPLICATION_ATOM_SVC
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 APPLICATION_HTTP
public static final ContentType MULTIPART_MIXED
public static final ContentType MULTIPART_FORM_DATA
public static ContentType create(ContentType contentType, String parameterName, String parameterValue) throws IllegalArgumentException
contentType
- an existing content typeparameterName
- the name of the additional parameterparameterValue
- the value of the additional parameterContentType
objectIllegalArgumentException
public static ContentType create(String format) throws IllegalArgumentException
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 mappublic String getParameter(String name)
name
- the name of the parameter to get (case-insensitive)null
if the parameter is not presentpublic 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–2018 The Apache Software Foundation. All rights reserved.