Class HttpMediaType (1.42.0)

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
NameDescription
mediaTypeAString
mediaTypeBString
Returns
TypeDescription
boolean

Constructors

HttpMediaType(String mediaType)

public HttpMediaType(String mediaType)

Creates a HttpMediaType by parsing the specified media type string.

Parameter
NameDescription
mediaTypeString

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
NameDescription
typeString

main media type, for example "text"

subTypeString

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
TypeDescription
String

clearParameters()

public void clearParameters()

Removes all set parameters from this media type.

equals(Object obj)

public boolean equals(Object obj)
Parameter
NameDescription
objObject
Returns
TypeDescription
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
NameDescription
mediaTypeHttpMediaType
Returns
TypeDescription
boolean

getCharsetParameter()

public Charset getCharsetParameter()

Returns the specified charset or null if unset.

Returns
TypeDescription
Charset

getParameter(String name)

public String getParameter(String name)

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

Parameter
NameDescription
nameString

name of the parameter

Returns
TypeDescription
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
TypeDescription
Map<String,String>

getSubType()

public String getSubType()

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

Returns
TypeDescription
String

getType()

public String getType()

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

Returns
TypeDescription
String

hashCode()

public int hashCode()
Returns
TypeDescription
int
Overrides

removeParameter(String name)

public HttpMediaType removeParameter(String name)

Removes the specified media parameter.

Parameter
NameDescription
nameString

parameter to remove

Returns
TypeDescription
HttpMediaType

setCharsetParameter(Charset charset)

public HttpMediaType setCharsetParameter(Charset charset)

Sets the charset parameter of the media type.

Parameter
NameDescription
charsetCharset

new value for the charset parameter or null to remove

Returns
TypeDescription
HttpMediaType

setParameter(String name, String value)

public HttpMediaType setParameter(String name, String value)

Sets the media parameter to the specified value.

Parameters
NameDescription
nameString

case-insensitive name of the parameter

valueString

value of the parameter or null to remove

Returns
TypeDescription
HttpMediaType

setSubType(String subType)

public HttpMediaType setSubType(String subType)

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

Parameter
NameDescription
subTypeString

sub media type

Returns
TypeDescription
HttpMediaType

setType(String type)

public HttpMediaType setType(String type)

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

Parameter
NameDescription
typeString

main/major media type

Returns
TypeDescription
HttpMediaType

toString()

public String toString()
Returns
TypeDescription
String
Overrides