Package com.google.api.client.http
Class HttpMediaType
java.lang.Object
com.google.api.client.http.HttpMediaType
HTTP Media-type as specified in the HTTP RFC (
}).
invalid @link
{@link "http://tools.ietf.org/html/rfc2616#section-3.7"
Implementation is not thread-safe.
- Since:
- 1.10
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The last build result ornull
.private static final Pattern
The pattern matching the full HTTP media type string.private static final Pattern
The pattern matching a single parameter (key, value) at a time.Additional parameters to the media type, for example"charset=utf-8"
.private String
The sub type of the media type, for example"plain"
.private static final Pattern
Matches a valid token which might be used as a type, key parameter or key value.private String
The main type of the media type, for example"text"
.private static final Pattern
Matches a valid media type or '*' (examples: "text" or "*"). -
Constructor Summary
ConstructorsConstructorDescriptionHttpMediaType
(String mediaType) Creates aHttpMediaType
by parsing the specified media type string.HttpMediaType
(String type, String subType) Initializes theHttpMediaType
by setting the specified media type. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds the full media type string which can be passed in the Content-Type header.void
Removes all set parameters from this media type.boolean
boolean
equalsIgnoreParameters
(HttpMediaType mediaType) Returnstrue
if the specified media type has both the same type and subtype, orfalse
if they don't match or the media type isnull
.static boolean
equalsIgnoreParameters
(String mediaTypeA, String mediaTypeB) Returnstrue
if the two specified media types have the same type and subtype, or if both types arenull
.private HttpMediaType
fromString
(String combinedType) Sets the full media type by parsing a full content-type string, for example"text/plain; foo=bar"
.Returns the specified charset ornull
if unset.getParameter
(String name) Returns the value of the specified parameter ornull
if not found.Returns an unmodifiable map of all specified parameters.Returns the sub media type, for example"plain"
when using"text"
.getType()
Returns the main media type, for example"text"
, ornull
for '*'.int
hashCode()
(package private) static boolean
matchesToken
(String value) Returns whether the given value matches the regular expression for "token" as specified in RFC 2616 section 2.2.private static String
quoteString
(String unquotedString) removeParameter
(String name) Removes the specified media parameter.setCharsetParameter
(Charset charset) Sets the charset parameter of the media type.setParameter
(String name, String value) Sets the media parameter to the specified value.setSubType
(String subType) Sets the sub media type, for example"plain"
when using"text"
.Sets the (main) media type, for example"text"
.toString()
-
Field Details
-
TYPE_REGEX
Matches a valid media type or '*' (examples: "text" or "*"). -
TOKEN_REGEX
Matches a valid token which might be used as a type, key parameter or key value. -
FULL_MEDIA_TYPE_REGEX
The pattern matching the full HTTP media type string. -
PARAMETER_REGEX
The pattern matching a single parameter (key, value) at a time. -
type
The main type of the media type, for example"text"
. -
subType
The sub type of the media type, for example"plain"
. -
parameters
Additional parameters to the media type, for example"charset=utf-8"
. -
cachedBuildResult
The last build result ornull
.
-
-
Constructor Details
-
HttpMediaType
Initializes theHttpMediaType
by setting the specified media type.- Parameters:
type
- main media type, for example"text"
subType
- sub media type, for example"plain"
-
HttpMediaType
Creates aHttpMediaType
by parsing the specified media type string.- Parameters:
mediaType
- full media type string, for example"text/plain; charset=utf-8"
-
-
Method Details
-
setType
Sets the (main) media type, for example"text"
.- Parameters:
type
- main/major media type
-
getType
Returns the main media type, for example"text"
, ornull
for '*'. -
setSubType
Sets the sub media type, for example"plain"
when using"text"
.- Parameters:
subType
- sub media type
-
getSubType
Returns the sub media type, for example"plain"
when using"text"
. -
fromString
Sets the full media type by parsing a full content-type string, for example"text/plain; foo=bar"
.This method will not clear existing parameters. Use
clearParameters()
if this behavior is required.- Parameters:
combinedType
- full media type in the"maintype/subtype; key=value"
format.
-
setParameter
Sets the media parameter to the specified value.- Parameters:
name
- case-insensitive name of the parametervalue
- value of the parameter ornull
to remove
-
getParameter
Returns the value of the specified parameter ornull
if not found.- Parameters:
name
- name of the parameter
-
removeParameter
Removes the specified media parameter.- Parameters:
name
- parameter to remove
-
clearParameters
public void clearParameters()Removes all set parameters from this media type. -
getParameters
Returns an unmodifiable map of all specified parameters. Parameter names will be stored in lower-case in this map. -
matchesToken
Returns whether the given value matches the regular expression for "token" as specified in RFC 2616 section 2.2. -
quoteString
-
build
Builds the full media type string which can be passed in the Content-Type header. -
toString
-
equalsIgnoreParameters
Returnstrue
if the specified media type has both the same type and subtype, orfalse
if they don't match or the media type isnull
. -
equalsIgnoreParameters
Returnstrue
if the two specified media types have the same type and subtype, or if both types arenull
. -
setCharsetParameter
Sets the charset parameter of the media type.- Parameters:
charset
- new value for the charset parameter ornull
to remove
-
getCharsetParameter
Returns the specified charset ornull
if unset. -
hashCode
public int hashCode() -
equals
-