Class HttpMediaType (1.45.2)

public final class HttpMediaType

HTTP Media-type as specified in the HTTP RFC.

Implementation is not thread-safe.

Inheritance

Object > HttpMediaType

Static Methods

equalsIgnoreParameters(String mediaTypeA, String mediaTypeB)

public static boolean equalsIgnoreParameters(String mediaTypeA, String mediaTypeB)

Returns true if the two specified media types have the same type and subtype, or if both types are null.

Parameters
Name Description
mediaTypeA String
mediaTypeB String
Returns
Type Description
boolean

Constructors

HttpMediaType(String mediaType)

public HttpMediaType(String mediaType)

Creates a HttpMediaType by parsing the specified media type string.

Parameter
Name Description
mediaType String

full media type string, for example "text/plain; charset=utf-8"

HttpMediaType(String type, String subType)

public HttpMediaType(String type, String subType)

Initializes the HttpMediaType by setting the specified media type.

Parameters
Name Description
type String

main media type, for example "text"

subType String

sub media type, for example "plain"

Methods

build()

public String build()

Builds the full media type string which can be passed in the Content-Type header.

Returns
Type Description
String

clearParameters()

public void clearParameters()

Removes all set parameters from this media type.

equals(Object obj)

public boolean equals(Object obj)
Parameter
Name Description
obj Object
Returns
Type Description
boolean
Overrides

equalsIgnoreParameters(HttpMediaType mediaType)

public boolean equalsIgnoreParameters(HttpMediaType mediaType)

Returns true if the specified media type has both the same type and subtype, or false if they don't match or the media type is null.

Parameter
Name Description
mediaType HttpMediaType
Returns
Type Description
boolean

getCharsetParameter()

public Charset getCharsetParameter()

Returns the specified charset or null if unset.

Returns
Type Description
Charset

getParameter(String name)

public String getParameter(String name)

Returns the value of the specified parameter or null if not found.

Parameter
Name Description
name String

name of the parameter

Returns
Type Description
String

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.

Returns
Type Description
Map<String,String>

getSubType()

public String getSubType()

Returns the sub media type, for example "plain" when using "text".

Returns
Type Description
String

getType()

public String getType()

Returns the main media type, for example "text", or null for '*'.

Returns
Type Description
String

hashCode()

public int hashCode()
Returns
Type Description
int
Overrides

removeParameter(String name)

public HttpMediaType removeParameter(String name)

Removes the specified media parameter.

Parameter
Name Description
name String

parameter to remove

Returns
Type Description
HttpMediaType

setCharsetParameter(Charset charset)

public HttpMediaType setCharsetParameter(Charset charset)

Sets the charset parameter of the media type.

Parameter
Name Description
charset Charset

new value for the charset parameter or null to remove

Returns
Type Description
HttpMediaType

setParameter(String name, String value)

public HttpMediaType setParameter(String name, String value)

Sets the media parameter to the specified value.

Parameters
Name Description
name String

case-insensitive name of the parameter

value String

value of the parameter or null to remove

Returns
Type Description
HttpMediaType

setSubType(String subType)

public HttpMediaType setSubType(String subType)

Sets the sub media type, for example "plain" when using "text".

Parameter
Name Description
subType String

sub media type

Returns
Type Description
HttpMediaType

setType(String type)

public HttpMediaType setType(String type)

Sets the (main) media type, for example "text".

Parameter
Name Description
type String

main/major media type

Returns
Type Description
HttpMediaType

toString()

public String toString()
Returns
Type Description
String
Overrides