Top Description Fields Constructors Methods
javax.ws.rs.core

public Class MediaType

extends Object
Class Inheritance
Annotations
@SuppressWarnings:JavaDoc
Imports
java.util.Collections, .Comparator, .Map, .TreeMap, javax.ws.rs.ext.RuntimeDelegate

An abstraction for a media type. Instances are immutable.
Authors
Paul Sandoz, Marc Hadley
Since
1.0
See Also
HTTP/1.1 section 3.7

Field Summary

Modifier and TypeField and Description
public static final String
APPLICATION_ATOM_XML

A String constant representing application/atom+xml media type.

public static final MediaType
APPLICATION_ATOM_XML_TYPE

A MediaType constant representing application/atom+xml media type.

public static final String
APPLICATION_FORM_URLENCODED

A String constant representing application/x-www-form-urlencoded media type.

public static final MediaType
APPLICATION_FORM_URLENCODED_TYPE

A MediaType constant representing application/x-www-form-urlencoded media type.

public static final String
APPLICATION_JSON

A String constant representing application/json media type.

public static final String
APPLICATION_JSON_PATCH_JSON

String representation of application/json-patch+json media type..

public static final MediaType
APPLICATION_JSON_PATCH_JSON_TYPE

A MediaType constant representing application/json-patch+json media type.

public static final MediaType
APPLICATION_JSON_TYPE

A MediaType constant representing application/json media type.

public static final String
APPLICATION_OCTET_STREAM

A String constant representing application/octet-stream media type.

public static final MediaType
APPLICATION_OCTET_STREAM_TYPE

A MediaType constant representing application/octet-stream media type.

public static final String
APPLICATION_SVG_XML

A String constant representing application/svg+xml media type.

public static final MediaType
APPLICATION_SVG_XML_TYPE

A MediaType constant representing application/svg+xml media type.

public static final String
APPLICATION_XHTML_XML

A String constant representing application/xhtml+xml media type.

public static final MediaType
APPLICATION_XHTML_XML_TYPE

A MediaType constant representing application/xhtml+xml media type.

public static final String
APPLICATION_XML

A String constant representing application/xml media type.

public static final MediaType
APPLICATION_XML_TYPE

A MediaType constant representing application/xml media type.

public static final String
CHARSET_PARAMETER

The media type charset parameter name.

public static final String
MEDIA_TYPE_WILDCARD

The value of a type or subtype wildcard *.

public static final String
MULTIPART_FORM_DATA

A String constant representing multipart/form-data media type.

public static final MediaType
MULTIPART_FORM_DATA_TYPE

A MediaType constant representing multipart/form-data media type.

private Map<String, String>
public static final String
SERVER_SENT_EVENTS

String representation of Server sent events media type.

public static final MediaType
SERVER_SENT_EVENTS_TYPE

Server sent events media type.

private String
public static final String
TEXT_HTML

A String constant representing text/html media type.

public static final MediaType
TEXT_HTML_TYPE

A MediaType constant representing text/html media type.

public static final String
TEXT_PLAIN

A String constant representing text/plain media type.

public static final MediaType
TEXT_PLAIN_TYPE

A MediaType constant representing text/plain media type.

public static final String
TEXT_XML

A String constant representing text/xml media type.

public static final MediaType
TEXT_XML_TYPE

A MediaType constant representing text/xml media type.

private String
public static final String
WILDCARD

A String constant representing wildcard */* media type .

public static final MediaType
WILDCARD_TYPE

A MediaType constant representing wildcard */* media type.

Constructor Summary

AccessConstructor and Description
public
MediaType(String
the primary type, null is equivalent to MEDIA_TYPE_WILDCARD.
type
,
String
the subtype, null is equivalent to MEDIA_TYPE_WILDCARD.
subtype
,
Map<String, String>
a map of media type parameters, null is the same as an empty map.
parameters
)

Creates a new instance of MediaType with the supplied type, subtype and parameters.

public
MediaType(String
the primary type, null is equivalent to MEDIA_TYPE_WILDCARD
type
,
String
the subtype, null is equivalent to MEDIA_TYPE_WILDCARD
subtype
)

Creates a new instance of MediaType with the supplied type and subtype.

public
MediaType(String
the primary type, null is equivalent to MEDIA_TYPE_WILDCARD
type
,
String
the subtype, null is equivalent to MEDIA_TYPE_WILDCARD
subtype
,
String
the charset parameter value. If null or empty the charset parameter will not be set.
charset
)

Creates a new instance of MediaType with the supplied type, subtype and charset parameter.

public
MediaType()

Creates a new instance of MediaType, both type and subtype are wildcards.

private
MediaType(String type, String subtype, String charset, Map<String, String> parameterMap)

Method Summary

Modifier and TypeMethod and Description
private static TreeMap<String, String>
public boolean

Returns:

true if the two media types are the same, false otherwise.
equals
(Object
the object to compare to.
obj
)

Overrides java.lang.Object.equals.

Compares obj to this media type to see if they are the same by comparing type, subtype and parameters.
public Map<String, String>

Returns:

an immutable map of parameters.
getParameters
()

Getter for a read-only parameter map.

public String

Returns:

value of subtype.
getSubtype
()

Getter for subtype.

public String

Returns:

value of primary type.
getType
()

Getter for primary type.

public int

Returns:

a generated hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

Generate a hash code from the type, subtype and parameters.
public boolean

Returns:

true if the types are compatible, false otherwise.
isCompatible
(MediaType
the media type to compare with.
other
)

Check if this media type is compatible with another media type.

public boolean

Returns:

true if the subtype is a wildcard.
isWildcardSubtype
()

Checks if the subtype is a wildcard.

public boolean

Returns:

true if the primary type is a wildcard.
isWildcardType
()

Checks if the primary type is a wildcard.

public String

Returns:

a string version of the media type.
toString
()

Overrides java.lang.Object.toString.

Convert the media type to a string suitable for use as the value of a corresponding HTTP header.
public static MediaType

Returns:

the newly created MediaType.
valueOf
(String
the media type string.
type
)

Creates a new instance of MediaType by parsing the supplied string.

public MediaType

Returns:

copy of the current MediaType instance with the charset parameter set to the supplied value.
withCharset
(String
the charset parameter value. If null or empty the charset parameter will not be set or updated.
charset
)

Create a new MediaType instance with the same type, subtype and parameters copied from the original instance and the supplied charset parameter.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

APPLICATION_ATOM_XMLback to summary
public static final String APPLICATION_ATOM_XML

A String constant representing application/atom+xml media type.

APPLICATION_ATOM_XML_TYPEback to summary
public static final MediaType APPLICATION_ATOM_XML_TYPE

A MediaType constant representing application/atom+xml media type.

APPLICATION_FORM_URLENCODEDback to summary
public static final String APPLICATION_FORM_URLENCODED

A String constant representing application/x-www-form-urlencoded media type.

APPLICATION_FORM_URLENCODED_TYPEback to summary
public static final MediaType APPLICATION_FORM_URLENCODED_TYPE

A MediaType constant representing application/x-www-form-urlencoded media type.

APPLICATION_JSONback to summary
public static final String APPLICATION_JSON

A String constant representing application/json media type.

APPLICATION_JSON_PATCH_JSONback to summary
public static final String APPLICATION_JSON_PATCH_JSON

String representation of application/json-patch+json media type..

APPLICATION_JSON_PATCH_JSON_TYPEback to summary
public static final MediaType APPLICATION_JSON_PATCH_JSON_TYPE

A MediaType constant representing application/json-patch+json media type.

APPLICATION_JSON_TYPEback to summary
public static final MediaType APPLICATION_JSON_TYPE

A MediaType constant representing application/json media type.

APPLICATION_OCTET_STREAMback to summary
public static final String APPLICATION_OCTET_STREAM

A String constant representing application/octet-stream media type.

APPLICATION_OCTET_STREAM_TYPEback to summary
public static final MediaType APPLICATION_OCTET_STREAM_TYPE

A MediaType constant representing application/octet-stream media type.

APPLICATION_SVG_XMLback to summary
public static final String APPLICATION_SVG_XML

A String constant representing application/svg+xml media type.

APPLICATION_SVG_XML_TYPEback to summary
public static final MediaType APPLICATION_SVG_XML_TYPE

A MediaType constant representing application/svg+xml media type.

APPLICATION_XHTML_XMLback to summary
public static final String APPLICATION_XHTML_XML

A String constant representing application/xhtml+xml media type.

APPLICATION_XHTML_XML_TYPEback to summary
public static final MediaType APPLICATION_XHTML_XML_TYPE

A MediaType constant representing application/xhtml+xml media type.

APPLICATION_XMLback to summary
public static final String APPLICATION_XML

A String constant representing application/xml media type.

APPLICATION_XML_TYPEback to summary
public static final MediaType APPLICATION_XML_TYPE

A MediaType constant representing application/xml media type.

CHARSET_PARAMETERback to summary
public static final String CHARSET_PARAMETER

The media type charset parameter name.

MEDIA_TYPE_WILDCARDback to summary
public static final String MEDIA_TYPE_WILDCARD

The value of a type or subtype wildcard *.

MULTIPART_FORM_DATAback to summary
public static final String MULTIPART_FORM_DATA

A String constant representing multipart/form-data media type.

MULTIPART_FORM_DATA_TYPEback to summary
public static final MediaType MULTIPART_FORM_DATA_TYPE

A MediaType constant representing multipart/form-data media type.

parametersback to summary
private Map<String, String> parameters
SERVER_SENT_EVENTSback to summary
public static final String SERVER_SENT_EVENTS

String representation of Server sent events media type. ("text/event-stream").

SERVER_SENT_EVENTS_TYPEback to summary
public static final MediaType SERVER_SENT_EVENTS_TYPE

Server sent events media type.

subtypeback to summary
private String subtype
TEXT_HTMLback to summary
public static final String TEXT_HTML

A String constant representing text/html media type.

TEXT_HTML_TYPEback to summary
public static final MediaType TEXT_HTML_TYPE

A MediaType constant representing text/html media type.

TEXT_PLAINback to summary
public static final String TEXT_PLAIN

A String constant representing text/plain media type.

TEXT_PLAIN_TYPEback to summary
public static final MediaType TEXT_PLAIN_TYPE

A MediaType constant representing text/plain media type.

TEXT_XMLback to summary
public static final String TEXT_XML

A String constant representing text/xml media type.

TEXT_XML_TYPEback to summary
public static final MediaType TEXT_XML_TYPE

A MediaType constant representing text/xml media type.

typeback to summary
private String type
WILDCARDback to summary
public static final String WILDCARD

A String constant representing wildcard */* media type .

WILDCARD_TYPEback to summary
public static final MediaType WILDCARD_TYPE

A MediaType constant representing wildcard */* media type.

Constructor Detail

MediaTypeback to summary
public MediaType(String type, String subtype, Map<String, String> parameters)

Creates a new instance of MediaType with the supplied type, subtype and parameters.

Parameters
type:String

the primary type, null is equivalent to MEDIA_TYPE_WILDCARD.

subtype:String

the subtype, null is equivalent to MEDIA_TYPE_WILDCARD.

parameters:Map<String, String>

a map of media type parameters, null is the same as an empty map.

MediaTypeback to summary
public MediaType(String type, String subtype)

Creates a new instance of MediaType with the supplied type and subtype.

Parameters
type:String

the primary type, null is equivalent to MEDIA_TYPE_WILDCARD

subtype:String

the subtype, null is equivalent to MEDIA_TYPE_WILDCARD

MediaTypeback to summary
public MediaType(String type, String subtype, String charset)

Creates a new instance of MediaType with the supplied type, subtype and charset parameter.

Parameters
type:String

the primary type, null is equivalent to MEDIA_TYPE_WILDCARD

subtype:String

the subtype, null is equivalent to MEDIA_TYPE_WILDCARD

charset:String

the charset parameter value. If null or empty the charset parameter will not be set.

MediaTypeback to summary
public MediaType()

Creates a new instance of MediaType, both type and subtype are wildcards. Consider using the constant WILDCARD_TYPE instead.

MediaTypeback to summary
private MediaType(String type, String subtype, String charset, Map<String, String> parameterMap)

Method Detail

createParametersMapback to summary
private static TreeMap<String, String> createParametersMap(Map<String, String> initialValues)
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Compares obj to this media type to see if they are the same by comparing type, subtype and parameters. Note that the case-sensitivity of parameter values is dependent on the semantics of the parameter name, see href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7">HTTP/1.1</a>. This method assumes that values are case-sensitive.

Note that the equals(...) implementation does not perform a class equality check (this.getClass() == obj.getClass()). Therefore any class that extends from MediaType class and needs to override one of the equals(...) and hashCode() methods must always override both methods to ensure the contract between Object#equals(java.lang.Object) and Object#hashCode() does not break.

Parameters
obj:Object

the object to compare to.

Returns:boolean

true if the two media types are the same, false otherwise.

Annotations
@SuppressWarnings:UnnecessaryJavaDocLink
@Override
getParametersback to summary
public Map<String, String> getParameters()

Getter for a read-only parameter map. Keys are case-insensitive.

Returns:Map<String, String>

an immutable map of parameters.

getSubtypeback to summary
public String getSubtype()

Getter for subtype.

Returns:String

value of subtype.

getTypeback to summary
public String getType()

Getter for primary type.

Returns:String

value of primary type.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Generate a hash code from the type, subtype and parameters.

Note that the equals(java.lang.Object) implementation does not perform a class equality check (this.getClass() == obj.getClass()). Therefore any class that extends from MediaType class and needs to override one of the equals(Object) and hashCode() methods must always override both methods to ensure the contract between Object#equals(java.lang.Object) and Object#hashCode() does not break.

Returns:int

a generated hash code.

Annotations
@SuppressWarnings:UnnecessaryJavaDocLink
@Override
isCompatibleback to summary
public boolean isCompatible(MediaType other)

Check if this media type is compatible with another media type. E.g. image/* is compatible with image/jpeg, image/png, etc. Media type parameters are ignored. The function is commutative.

Parameters
other:MediaType

the media type to compare with.

Returns:boolean

true if the types are compatible, false otherwise.

isWildcardSubtypeback to summary
public boolean isWildcardSubtype()

Checks if the subtype is a wildcard.

Returns:boolean

true if the subtype is a wildcard.

isWildcardTypeback to summary
public boolean isWildcardType()

Checks if the primary type is a wildcard.

Returns:boolean

true if the primary type is a wildcard.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Convert the media type to a string suitable for use as the value of a corresponding HTTP header.

Returns:String

a string version of the media type.

Annotations
@Override
valueOfback to summary
public static MediaType valueOf(String type)

Creates a new instance of MediaType by parsing the supplied string.

Parameters
type:String

the media type string.

Returns:MediaType

the newly created MediaType.

Exceptions
IllegalArgumentException:
if the supplied string cannot be parsed or is null.
withCharsetback to summary
public MediaType withCharset(String charset)

Create a new MediaType instance with the same type, subtype and parameters copied from the original instance and the supplied charset parameter.

Parameters
charset:String

the charset parameter value. If null or empty the charset parameter will not be set or updated.

Returns:MediaType

copy of the current MediaType instance with the charset parameter set to the supplied value.

Since
2.0