Package javax.ws.rs.core
Class MediaType
java.lang.Object
javax.ws.rs.core.MediaType
An abstraction for a media type. Instances are immutable.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
"application/atom+xml"static final MediaType
"application/atom+xml"static final String
"application/x-www-form-urlencoded"static final MediaType
"application/x-www-form-urlencoded"static final String
"application/json"static final MediaType
"application/json"static final String
"application/octet-stream"static final MediaType
"application/octet-stream"static final String
"application/svg+xml"static final MediaType
"application/svg+xml"static final String
"application/xhtml+xml"static final MediaType
"application/xhtml+xml"static final String
"application/xml"static final MediaType
"application/xml"private static final RuntimeDelegate.HeaderDelegate
<MediaType> Empty immutable map used for all instances without parametersstatic final String
The value of a type or subtype wildcard: "*"static final String
"multipart/form-data"static final MediaType
"multipart/form-data"private String
static final String
"text/html"static final MediaType
"text/html"static final String
"text/plain"static final MediaType
"text/plain"static final String
"text/xml"static final MediaType
"text/xml"private String
static final String
"*/*"static final MediaType
"*/*" -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of MediaType, both type and subtype are wildcards.Creates a new instance of MediaType with the supplied type and subtype.Creates a new instance of MediaType with the supplied type, subtype and parameters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Compares obj to 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.int
hashCode()
Generate a hashcode from the type, subtype and parameters.boolean
isCompatible
(MediaType other) Check if this media type is compatible with another media type.boolean
Checks if the subtype is a wildcardboolean
Checks 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 MediaType
Creates a new instance of MediaType by parsing the supplied string.
-
Field Details
-
type
-
subtype
-
parameters
-
emptyMap
Empty immutable map used for all instances without parameters -
delegate
-
MEDIA_TYPE_WILDCARD
The value of a type or subtype wildcard: "*"- See Also:
-
WILDCARD
"*/*"- See Also:
-
WILDCARD_TYPE
"*/*" -
APPLICATION_XML
"application/xml"- See Also:
-
APPLICATION_XML_TYPE
"application/xml" -
APPLICATION_ATOM_XML
"application/atom+xml"- See Also:
-
APPLICATION_ATOM_XML_TYPE
"application/atom+xml" -
APPLICATION_XHTML_XML
"application/xhtml+xml"- See Also:
-
APPLICATION_XHTML_XML_TYPE
"application/xhtml+xml" -
APPLICATION_SVG_XML
"application/svg+xml"- See Also:
-
APPLICATION_SVG_XML_TYPE
"application/svg+xml" -
APPLICATION_JSON
"application/json"- See Also:
-
APPLICATION_JSON_TYPE
"application/json" -
APPLICATION_FORM_URLENCODED
"application/x-www-form-urlencoded"- See Also:
-
APPLICATION_FORM_URLENCODED_TYPE
"application/x-www-form-urlencoded" -
MULTIPART_FORM_DATA
"multipart/form-data"- See Also:
-
MULTIPART_FORM_DATA_TYPE
"multipart/form-data" -
APPLICATION_OCTET_STREAM
"application/octet-stream"- See Also:
-
APPLICATION_OCTET_STREAM_TYPE
"application/octet-stream" -
TEXT_PLAIN
"text/plain"- See Also:
-
TEXT_PLAIN_TYPE
"text/plain" -
TEXT_XML
"text/xml"- See Also:
-
TEXT_XML_TYPE
"text/xml" -
TEXT_HTML
"text/html"- See Also:
-
TEXT_HTML_TYPE
"text/html"
-
-
Constructor Details
-
MediaType
Creates a new instance of MediaType with the supplied type, subtype and parameters.- Parameters:
type
- the primary type, null is equivalent toMEDIA_TYPE_WILDCARD
.subtype
- the subtype, null is equivalent toMEDIA_TYPE_WILDCARD
.parameters
- a map of media type parameters, null is the same as an empty map.
-
MediaType
Creates a new instance of MediaType with the supplied type and subtype.- Parameters:
type
- the primary type, null is equivalent toMEDIA_TYPE_WILDCARD
subtype
- the subtype, null is equivalent toMEDIA_TYPE_WILDCARD
-
MediaType
public MediaType()Creates a new instance of MediaType, both type and subtype are wildcards. Consider using the constantWILDCARD_TYPE
instead.
-
-
Method Details
-
valueOf
Creates a new instance of MediaType by 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
-
getType
Getter for primary type.- Returns:
- value of primary type.
-
isWildcardType
public boolean isWildcardType()Checks if the primary type is a wildcard.- Returns:
- true if the primary type is a wildcard
-
getSubtype
Getter for subtype.- Returns:
- value of subtype.
-
isWildcardSubtype
public boolean isWildcardSubtype()Checks if the subtype is a wildcard- Returns:
- true if the subtype is a wildcard
-
getParameters
Getter for a read-only parameter map. Keys are case-insensitive.- Returns:
- an immutable map of parameters.
-
isCompatible
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
- the media type to compare with- Returns:
- true if the types are compatible, false otherwise.
-
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, seeinvalid @link
{@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7">HTTP/1.1</a>
-
hashCode
public int hashCode()Generate a hashcode from the type, subtype and parameters. -
toString
Convert the media type to a string suitable for use as the value of a corresponding HTTP header.
-