Package javax.ws.rs.core
Class MediaType
java.lang.Object
javax.ws.rs.core.MediaType
An abstraction for a media type. Instances are immutable.
- Since:
- 1.0
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringAStringconstant representing "application/atom+xml" media type.static final MediaTypeAMediaTypeconstant representing "application/atom+xml" media type.static final StringAStringconstant representing "application/x-www-form-urlencoded" media type.static final MediaTypeAMediaTypeconstant representing "application/x-www-form-urlencoded" media type.static final StringAStringconstant representing "application/json" media type.static final StringStringrepresentation of "application/json-patch+json" media type..static final MediaTypeAMediaTypeconstant representing "application/json-patch+json" media type.static final MediaTypeAMediaTypeconstant representing "application/json" media type.static final StringAStringconstant representing "application/octet-stream" media type.static final MediaTypeAMediaTypeconstant representing "application/octet-stream" media type.static final StringAStringconstant representing "application/svg+xml" media type.static final MediaTypeAMediaTypeconstant representing "application/svg+xml" media type.static final StringAStringconstant representing "application/xhtml+xml" media type.static final MediaTypeAMediaTypeconstant representing "application/xhtml+xml" media type.static final StringAStringconstant representing "application/xml" media type.static final MediaTypeAMediaTypeconstant representing "application/xml" media type.static final StringThe media typecharsetparameter name.static final StringThe value of a type or subtype wildcard "*".static final StringAStringconstant representing "multipart/form-data" media type.static final MediaTypeAMediaTypeconstant representing "multipart/form-data" media type.static final StringStringrepresentation of Server sent events media type.static final MediaTypeServer sent events media type.static final StringAStringconstant representing "text/html" media type.static final MediaTypeAMediaTypeconstant representing "text/html" media type.static final StringAStringconstant representing "text/plain" media type.static final MediaTypeAMediaTypeconstant representing "text/plain" media type.static final StringAStringconstant representing "text/xml" media type.static final MediaTypeAMediaTypeconstant representing "text/xml" media type.static final StringAStringconstant representing wildcard "*/*" media type .static final MediaType
- 
Constructor SummaryConstructorsConstructorDescriptionCreates a new instance ofMediaType, both type and subtype are wildcards.Creates a new instance ofMediaTypewith the supplied type and subtype.Creates a new instance ofMediaTypewith the supplied type, subtype and "charset" parameter.Creates a new instance ofMediaTypewith the supplied type, subtype and parameters.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanComparesobjto this media type to see if they are the same by comparing type, subtype and parameters.Getter for a read-only parameter map.Getter for subtype.getType()Getter for primary type.inthashCode()Generate a hash code from the type, subtype and parameters.booleanisCompatible(MediaType other) Check if this media type is compatible with another media type.booleanChecks if the subtype is a wildcard.booleanChecks if the primary type is a wildcard.toString()Convert the media type to a string suitable for use as the value of a corresponding HTTP header.static MediaTypeCreates a new instance ofMediaTypeby parsing the supplied string.withCharset(String charset) Create a newMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.
- 
Field Details- 
CHARSET_PARAMETERThe media typecharsetparameter name.- See Also:
 
- 
MEDIA_TYPE_WILDCARDThe value of a type or subtype wildcard "*".- See Also:
 
- 
WILDCARDAStringconstant representing wildcard "*/*" media type .- See Also:
 
- 
WILDCARD_TYPE
- 
APPLICATION_XMLAStringconstant representing "application/xml" media type.- See Also:
 
- 
APPLICATION_XML_TYPEAMediaTypeconstant representing "application/xml" media type.
- 
APPLICATION_ATOM_XMLAStringconstant representing "application/atom+xml" media type.- See Also:
 
- 
APPLICATION_ATOM_XML_TYPEAMediaTypeconstant representing "application/atom+xml" media type.
- 
APPLICATION_XHTML_XMLAStringconstant representing "application/xhtml+xml" media type.- See Also:
 
- 
APPLICATION_XHTML_XML_TYPEAMediaTypeconstant representing "application/xhtml+xml" media type.
- 
APPLICATION_SVG_XMLAStringconstant representing "application/svg+xml" media type.- See Also:
 
- 
APPLICATION_SVG_XML_TYPEAMediaTypeconstant representing "application/svg+xml" media type.
- 
APPLICATION_JSONAStringconstant representing "application/json" media type.- See Also:
 
- 
APPLICATION_JSON_TYPEAMediaTypeconstant representing "application/json" media type.
- 
APPLICATION_FORM_URLENCODEDAStringconstant representing "application/x-www-form-urlencoded" media type.- See Also:
 
- 
APPLICATION_FORM_URLENCODED_TYPEAMediaTypeconstant representing "application/x-www-form-urlencoded" media type.
- 
MULTIPART_FORM_DATAAStringconstant representing "multipart/form-data" media type.- See Also:
 
- 
MULTIPART_FORM_DATA_TYPEAMediaTypeconstant representing "multipart/form-data" media type.
- 
APPLICATION_OCTET_STREAMAStringconstant representing "application/octet-stream" media type.- See Also:
 
- 
APPLICATION_OCTET_STREAM_TYPEAMediaTypeconstant representing "application/octet-stream" media type.
- 
TEXT_PLAINAStringconstant representing "text/plain" media type.- See Also:
 
- 
TEXT_PLAIN_TYPEAMediaTypeconstant representing "text/plain" media type.
- 
TEXT_XMLAStringconstant representing "text/xml" media type.- See Also:
 
- 
TEXT_XML_TYPEAMediaTypeconstant representing "text/xml" media type.
- 
TEXT_HTMLAStringconstant representing "text/html" media type.- See Also:
 
- 
TEXT_HTML_TYPEAMediaTypeconstant representing "text/html" media type.
- 
SERVER_SENT_EVENTSStringrepresentation of Server sent events media type. (""text/event-stream"").- See Also:
 
- 
SERVER_SENT_EVENTS_TYPEServer sent events media type.
- 
APPLICATION_JSON_PATCH_JSONStringrepresentation of "application/json-patch+json" media type..- See Also:
 
- 
APPLICATION_JSON_PATCH_JSON_TYPEAMediaTypeconstant representing "application/json-patch+json" media type.
 
- 
- 
Constructor Details- 
MediaTypeCreates a new instance ofMediaTypewith the supplied type, subtype and parameters.- Parameters:
- type- the primary type,- nullis equivalent to- MEDIA_TYPE_WILDCARD.
- subtype- the subtype,- nullis equivalent to- MEDIA_TYPE_WILDCARD.
- parameters- a map of media type parameters,- nullis the same as an empty map.
 
- 
MediaTypeCreates a new instance ofMediaTypewith the supplied type and subtype.- Parameters:
- type- the primary type,- nullis equivalent to- MEDIA_TYPE_WILDCARD
- subtype- the subtype,- nullis equivalent to- MEDIA_TYPE_WILDCARD
 
- 
MediaTypeCreates a new instance ofMediaTypewith the supplied type, subtype and "charset" parameter.- Parameters:
- type- the primary type,- nullis equivalent to- MEDIA_TYPE_WILDCARD
- subtype- the subtype,- nullis equivalent to- MEDIA_TYPE_WILDCARD
- charset- the "charset" parameter value. If- nullor empty the "charset" parameter will not be set.
 
- 
MediaTypepublic MediaType()Creates a new instance ofMediaType, both type and subtype are wildcards. Consider using the constantWILDCARD_TYPEinstead.
 
- 
- 
Method Details- 
valueOfCreates a new instance ofMediaTypeby parsing the supplied string.- Parameters:
- type- the media type string.
- Returns:
- the newly created MediaType.
- Throws:
- IllegalArgumentException- if the supplied string cannot be parsed or is- null.
 
- 
getTypeGetter for primary type.- Returns:
- value of primary type.
 
- 
isWildcardTypepublic boolean isWildcardType()Checks if the primary type is a wildcard.- Returns:
- true if the primary type is a wildcard.
 
- 
getSubtypeGetter for subtype.- Returns:
- value of subtype.
 
- 
isWildcardSubtypepublic boolean isWildcardSubtype()Checks if the subtype is a wildcard.- Returns:
- true if the subtype is a wildcard.
 
- 
getParametersGetter for a read-only parameter map. Keys are case-insensitive.- Returns:
- an immutable map of parameters.
 
- 
withCharsetCreate a newMediaTypeinstance with the same type, subtype and parameters copied from the original instance and the supplied "charset" parameter.
- 
isCompatibleCheck 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- the media type to compare with.
- Returns:
- true if the types are compatible, false otherwise.
 
- 
equalsComparesobjto 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 {@link <a 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 theequals(...)implementation does not perform a class equality check (this.getClass() == obj.getClass()). Therefore any class that extends fromMediaTypeclass and needs to override one of theequals(...)andhashCode()methods must always override both methods to ensure the contract betweenObject.equals(java.lang.Object)andObject.hashCode()does not break.
- 
hashCodepublic int hashCode()Generate a hash code from the type, subtype and parameters. Note that theequals(java.lang.Object)implementation does not perform a class equality check (this.getClass() == obj.getClass()). Therefore any class that extends fromMediaTypeclass and needs to override one of theequals(Object)andhashCode()methods must always override both methods to ensure the contract betweenObject.equals(java.lang.Object)andObject.hashCode()does not break.
- 
toStringConvert the media type to a string suitable for use as the value of a corresponding HTTP header.
 
-