javax.ws.rs.core
Class MediaType

java.lang.Object
  extended by javax.ws.rs.core.MediaType

public class MediaType
extends java.lang.Object

An abstraction for a media type. Instances are immutable.

See Also:
HTTP/1.1 section 3.7

Field Summary
static java.lang.String MEDIA_TYPE_WILDCARD
          The value of a type or subtype wildcard.
 
Constructor Summary
MediaType()
          Creates a new instance of MediaType, both type and subtype are wildcards.
MediaType(java.lang.String type, java.lang.String subtype)
          Creates a new instance of MediaType with the supplied type and subtype.
MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)
          Creates a new instance of MediaType with the supplied type, subtype and parameters.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares obj to this media type to see if they are the same by comparing type and subtype only - parameters are ignored.
 java.util.Map<java.lang.String,java.lang.String> getParameters()
          Getter for parameter map.
 java.lang.String getSubtype()
          Getter for subtype.
 java.lang.String getType()
          Getter for primary type.
 int hashCode()
          Generate a hashcode from the type and subtype.
 boolean isCompatible(MediaType other)
          Check if this media type is compatible with another media type.
 boolean isWildcardSubtype()
          Checks if the subtype is a wildcard
 boolean isWildcardType()
          Checks if the primary type is a wildcard.
static MediaType parse(java.lang.String type)
          Creates a new instance of MediaType by parsing the supplied string.
 java.lang.String toString()
          Convert the media type to a string suitable for use as the value of a corresponding HTTP header.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MEDIA_TYPE_WILDCARD

public static final java.lang.String MEDIA_TYPE_WILDCARD
The value of a type or subtype wildcard.

See Also:
Constant Field Values
Constructor Detail

MediaType

public MediaType(java.lang.String type,
                 java.lang.String subtype,
                 java.util.Map<java.lang.String,java.lang.String> parameters)
Creates a new instance of MediaType with the supplied type, subtype and parameters.

Parameters:
type - the primary type
subtype - the subtype
parameters - a map of media type parameters

MediaType

public MediaType(java.lang.String type,
                 java.lang.String subtype)
Creates a new instance of MediaType with the supplied type and subtype.

Parameters:
type - the primary type
subtype - the subtype

MediaType

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

Method Detail

parse

public static MediaType parse(java.lang.String type)
                       throws java.lang.IllegalArgumentException
Creates a new instance of MediaType by parsing the supplied string.

Parameters:
type - the media type string
Returns:
the newly created MediaType
Throws:
java.lang.IllegalArgumentException - if the supplied string cannot be parsed

getType

public java.lang.String 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

public java.lang.String 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

public java.util.Map<java.lang.String,java.lang.String> getParameters()
Getter for parameter map.

Returns:
an immutable map of parameters.

isCompatible

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.

Parameters:
other - the media type to compare with
Returns:
true if other is a subtype of this media type, false otherwise.

equals

public boolean equals(java.lang.Object obj)
Compares obj to this media type to see if they are the same by comparing type and subtype only - parameters are ignored.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare to
Returns:
true if the two media types are the same, false otherwise.

hashCode

public int hashCode()
Generate a hashcode from the type and subtype.

Overrides:
hashCode in class java.lang.Object
Returns:
a hashcode

toString

public java.lang.String toString()
Convert the media type to a string suitable for use as the value of a corresponding HTTP header.

Overrides:
toString in class java.lang.Object
Returns:
a stringified media type