Package com.google.api.client.http
Class HttpMediaType
- java.lang.Object
-
- com.google.api.client.http.HttpMediaType
-
public final class HttpMediaType extends Object
HTTP Media-type as specified in the HTTP RFC ( {@link "http://tools.ietf.org/html/rfc2616#section-3.7"}).Implementation is not thread-safe.
- Since:
- 1.10
- Author:
- Matthias Linder (mlinder)
-
-
Constructor Summary
Constructors Constructor Description HttpMediaType(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
build()
Builds the full media type string which can be passed in the Content-Type header.void
clearParameters()
Removes all set parameters from this media type.boolean
equals(Object obj)
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
.Charset
getCharsetParameter()
Returns the specified charset ornull
if unset.String
getParameter(String name)
Returns the value of the specified parameter ornull
if not found.Map<String,String>
getParameters()
Returns an unmodifiable map of all specified parameters.String
getSubType()
Returns the sub media type, for example"plain"
when using"text"
.String
getType()
Returns the main media type, for example"text"
, ornull
for '*'.int
hashCode()
HttpMediaType
removeParameter(String name)
Removes the specified media parameter.HttpMediaType
setCharsetParameter(Charset charset)
Sets the charset parameter of the media type.HttpMediaType
setParameter(String name, String value)
Sets the media parameter to the specified value.HttpMediaType
setSubType(String subType)
Sets the sub media type, for example"plain"
when using"text"
.HttpMediaType
setType(String type)
Sets the (main) media type, for example"text"
.String
toString()
-
-
-
Constructor Detail
-
HttpMediaType
public HttpMediaType(String type, String subType)
Initializes theHttpMediaType
by setting the specified media type.- Parameters:
type
- main media type, for example"text"
subType
- sub media type, for example"plain"
-
HttpMediaType
public HttpMediaType(String mediaType)
Creates aHttpMediaType
by parsing the specified media type string.- Parameters:
mediaType
- full media type string, for example"text/plain; charset=utf-8"
-
-
Method Detail
-
setType
public HttpMediaType setType(String type)
Sets the (main) media type, for example"text"
.- Parameters:
type
- main/major media type
-
getType
public String getType()
Returns the main media type, for example"text"
, ornull
for '*'.
-
setSubType
public HttpMediaType setSubType(String subType)
Sets the sub media type, for example"plain"
when using"text"
.- Parameters:
subType
- sub media type
-
getSubType
public String getSubType()
Returns the sub media type, for example"plain"
when using"text"
.
-
setParameter
public HttpMediaType setParameter(String name, String value)
Sets the media parameter to the specified value.- Parameters:
name
- case-insensitive name of the parametervalue
- value of the parameter ornull
to remove
-
getParameter
public String getParameter(String name)
Returns the value of the specified parameter ornull
if not found.- Parameters:
name
- name of the parameter
-
removeParameter
public HttpMediaType removeParameter(String name)
Removes the specified media parameter.- Parameters:
name
- parameter to remove
-
clearParameters
public void clearParameters()
Removes all set parameters from this media type.
-
getParameters
public Map<String,String> getParameters()
Returns an unmodifiable map of all specified parameters. Parameter names will be stored in lower-case in this map.
-
build
public String build()
Builds the full media type string which can be passed in the Content-Type header.
-
equalsIgnoreParameters
public 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
.
-
equalsIgnoreParameters
public 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
.
-
setCharsetParameter
public HttpMediaType setCharsetParameter(Charset charset)
Sets the charset parameter of the media type.- Parameters:
charset
- new value for the charset parameter ornull
to remove
-
getCharsetParameter
public Charset getCharsetParameter()
Returns the specified charset ornull
if unset.
-
-