Class HttpMediaType
java.lang.Object
com.google.api.client.http.HttpMediaType
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe last build result ornull.private static final PatternThe pattern matching the full HTTP media type string.private static final PatternThe pattern matching a single parameter (key, value) at a time.Additional parameters to the media type, for example"charset=utf-8".private StringThe sub type of the media type, for example"plain".private static final PatternMatches a valid token which might be used as a type, key parameter or key value.private StringThe main type of the media type, for example"text".private static final PatternMatches a valid media type or '*' (examples: "text" or "*"). -
Constructor Summary
ConstructorsConstructorDescriptionHttpMediaType(String mediaType) Creates aHttpMediaTypeby parsing the specified media type string.HttpMediaType(String type, String subType) Initializes theHttpMediaTypeby 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.voidRemoves all set parameters from this media type.booleanbooleanequalsIgnoreParameters(HttpMediaType mediaType) Returnstrueif the specified media type has both the same type and subtype, orfalseif they don't match or the media type isnull.static booleanequalsIgnoreParameters(String mediaTypeA, String mediaTypeB) Returnstrueif the two specified media types have the same type and subtype, or if both types arenull.private HttpMediaTypefromString(String combinedType) Sets the full media type by parsing a full content-type string, for example"text/plain; foo=bar".Returns the specified charset ornullif unset.getParameter(String name) Returns the value of the specified parameter ornullif 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", ornullfor '*'.inthashCode()(package private) static booleanmatchesToken(String value) Returns whether the given value matches the regular expression for "token" as specified in RFC 2616 section 2.2.private static StringquoteString(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
-
cachedBuildResult
The last build result ornull.
-
-
Constructor Details
-
HttpMediaType
Initializes theHttpMediaTypeby setting the specified media type.- Parameters:
type- main media type, for example"text"subType- sub media type, for example"plain"
-
HttpMediaType
Creates aHttpMediaTypeby 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", ornullfor '*'. -
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 ornullto remove
-
getParameter
-
removeParameter
Removes the specified media parameter.- Parameters:
name- parameter to remove
-
clearParameters
public void clearParameters()Removes all set parameters from this media type. -
getParameters
-
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
Returnstrueif the specified media type has both the same type and subtype, orfalseif they don't match or the media type isnull. -
equalsIgnoreParameters
-
setCharsetParameter
Sets the charset parameter of the media type.- Parameters:
charset- new value for the charset parameter ornullto remove
-
getCharsetParameter
Returns the specified charset ornullif unset. -
hashCode
-
equals
-