|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.http.MediaType
public class MediaType
Represents an Internet Media Type, as defined in the HTTP specification.
Consists of a type and a subtype.
Also has functionality to parse media types from a string using parseMediaType(String)
,
or multiple comma-separated media types using parseMediaTypes(String)
.
Field Summary | |
---|---|
static MediaType |
ALL
Public constant media type that includes all media ranges (i.e. |
static MediaType |
APPLICATION_ATOM_XML
Public constant media type for application/atom+xml . |
static MediaType |
APPLICATION_FORM_URLENCODED
Public constant media type for application/x-www-form-urlencoded . |
static MediaType |
APPLICATION_JSON
Public constant media type for application/json . |
static MediaType |
APPLICATION_OCTET_STREAM
Public constant media type for application/octet-stream . |
static MediaType |
APPLICATION_XHTML_XML
Public constant media type for application/xhtml+xml . |
static MediaType |
APPLICATION_XML
Public constant media type for application/xml . |
static MediaType |
IMAGE_GIF
Public constant media type for image/gif . |
static MediaType |
IMAGE_JPEG
Public constant media type for image/jpeg . |
static MediaType |
IMAGE_PNG
Public constant media type for image/png . |
static MediaType |
MULTIPART_FORM_DATA
Public constant media type for multipart/form-data . |
private static java.lang.String |
PARAM_CHARSET
|
private static java.lang.String |
PARAM_QUALITY_FACTOR
|
private java.util.Map<java.lang.String,java.lang.String> |
parameters
|
static java.util.Comparator<MediaType> |
QUALITY_VALUE_COMPARATOR
Comparator used by sortByQualityValue(List) . |
static java.util.Comparator<MediaType> |
SPECIFICITY_COMPARATOR
Comparator used by sortBySpecificity(List) . |
private java.lang.String |
subtype
|
static MediaType |
TEXT_HTML
Public constant media type for text/html . |
static MediaType |
TEXT_PLAIN
Public constant media type for text/plain . |
static MediaType |
TEXT_XML
Public constant media type for text/xml . |
private static java.util.BitSet |
TOKEN
|
private java.lang.String |
type
|
private static java.lang.String |
WILDCARD_TYPE
|
Constructor Summary | |
---|---|
MediaType(MediaType other,
java.util.Map<java.lang.String,java.lang.String> parameters)
Copy-constructor that copies the type and subtype of the given MediaType ,
and allows for different parameter. |
|
MediaType(java.lang.String type)
Create a new MediaType for the given primary type. |
|
MediaType(java.lang.String type,
java.lang.String subtype)
Create a new MediaType for the given primary type and subtype. |
|
MediaType(java.lang.String type,
java.lang.String subtype,
java.nio.charset.Charset charSet)
Create a new MediaType for the given type, subtype, and character set. |
|
MediaType(java.lang.String type,
java.lang.String subtype,
double qualityValue)
Create a new MediaType for the given type, subtype, and quality value. |
|
MediaType(java.lang.String type,
java.lang.String subtype,
java.util.Map<java.lang.String,java.lang.String> parameters)
Create a new MediaType for the given type, subtype, and parameters. |
Method Summary | |
---|---|
private void |
appendTo(java.util.Map<java.lang.String,java.lang.String> map,
java.lang.StringBuilder builder)
|
private void |
appendTo(java.lang.StringBuilder builder)
|
private void |
checkParameters(java.lang.String attribute,
java.lang.String value)
|
private void |
checkToken(java.lang.String s)
Checks the given token string for illegal characters, as defined in RFC 2616, section 2.2. |
int |
compareTo(MediaType other)
Compares this MediaType to another alphabetically. |
boolean |
equals(java.lang.Object other)
|
java.nio.charset.Charset |
getCharSet()
Return the character set, as indicated by a charset parameter, if any. |
java.lang.String |
getParameter(java.lang.String name)
Return a generic parameter value, given a parameter name. |
double |
getQualityValue()
Return the quality value, as indicated by a q parameter, if any. |
java.lang.String |
getSubtype()
Return the subtype. |
java.lang.String |
getType()
Return the primary type. |
int |
hashCode()
|
boolean |
includes(MediaType other)
Indicate whether this MediaType includes the given media type. |
boolean |
isCompatibleWith(MediaType other)
Indicate whether this MediaType is compatible with the given media type. |
boolean |
isConcrete()
Indicates whether this media type is concrete, i.e. |
private boolean |
isQuotedString(java.lang.String s)
|
boolean |
isWildcardSubtype()
Indicates whether the subtype is the wildcard character * or not. |
boolean |
isWildcardType()
Indicates whether the type is the wildcard character * or not. |
static MediaType |
parseMediaType(java.lang.String mediaType)
Parse the given String into a single MediaType . |
static java.util.List<MediaType> |
parseMediaTypes(java.lang.String mediaTypes)
Parse the given, comma-separated string into a list of MediaType objects. |
static void |
sortByQualityValue(java.util.List<MediaType> mediaTypes)
Sorts the given list of MediaType objects by quality value. |
static void |
sortBySpecificity(java.util.List<MediaType> mediaTypes)
Sorts the given list of MediaType objects by specificity. |
java.lang.String |
toString()
|
static java.lang.String |
toString(java.util.Collection<MediaType> mediaTypes)
Return a string representation of the given list of MediaType objects. |
private java.lang.String |
unquote(java.lang.String s)
|
static MediaType |
valueOf(java.lang.String value)
Parse the given String value into a MediaType object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final MediaType ALL
*/*
).
public static final MediaType APPLICATION_ATOM_XML
application/atom+xml
.
public static final MediaType APPLICATION_FORM_URLENCODED
application/x-www-form-urlencoded
.
public static final MediaType APPLICATION_JSON
application/json
.
public static final MediaType APPLICATION_OCTET_STREAM
application/octet-stream
.
public static final MediaType APPLICATION_XHTML_XML
application/xhtml+xml
.
public static final MediaType APPLICATION_XML
application/xml
.
public static final MediaType IMAGE_GIF
image/gif
.
public static final MediaType IMAGE_JPEG
image/jpeg
.
public static final MediaType IMAGE_PNG
image/png
.
public static final MediaType MULTIPART_FORM_DATA
multipart/form-data
.
public static final MediaType TEXT_HTML
text/html
.
public static final MediaType TEXT_PLAIN
text/plain
.
public static final MediaType TEXT_XML
text/xml
.
private static final java.util.BitSet TOKEN
private static final java.lang.String WILDCARD_TYPE
private static final java.lang.String PARAM_QUALITY_FACTOR
private static final java.lang.String PARAM_CHARSET
private final java.lang.String type
private final java.lang.String subtype
private final java.util.Map<java.lang.String,java.lang.String> parameters
public static final java.util.Comparator<MediaType> SPECIFICITY_COMPARATOR
sortBySpecificity(List)
.
public static final java.util.Comparator<MediaType> QUALITY_VALUE_COMPARATOR
sortByQualityValue(List)
.
Constructor Detail |
---|
public MediaType(java.lang.String type)
MediaType
for the given primary type.
The subtype is set to *
, parameters empty.
type
- the primary type
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(java.lang.String type, java.lang.String subtype)
MediaType
for the given primary type and subtype.
The parameters are empty.
type
- the primary typesubtype
- the subtype
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(java.lang.String type, java.lang.String subtype, java.nio.charset.Charset charSet)
MediaType
for the given type, subtype, and character set.
type
- the primary typesubtype
- the subtypecharSet
- the character set
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(java.lang.String type, java.lang.String subtype, double qualityValue)
MediaType
for the given type, subtype, and quality value.
type
- the primary typesubtype
- the subtypequalityValue
- the quality value
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(MediaType other, java.util.Map<java.lang.String,java.lang.String> parameters)
MediaType
,
and allows for different parameter.
other
- the other media typeparameters
- the parameters, may be null
java.lang.IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(java.lang.String type, java.lang.String subtype, java.util.Map<java.lang.String,java.lang.String> parameters)
MediaType
for the given type, subtype, and parameters.
type
- the primary typesubtype
- the subtypeparameters
- the parameters, may be null
java.lang.IllegalArgumentException
- if any of the parameters contain illegal charactersMethod Detail |
---|
private void checkToken(java.lang.String s)
java.lang.IllegalArgumentException
- in case of illegal charactersprivate void checkParameters(java.lang.String attribute, java.lang.String value)
private boolean isQuotedString(java.lang.String s)
private java.lang.String unquote(java.lang.String s)
public java.lang.String getType()
public boolean isWildcardType()
*
or not.
public java.lang.String getSubtype()
public boolean isWildcardSubtype()
*
or not.
*
public boolean isConcrete()
*
.
public java.nio.charset.Charset getCharSet()
charset
parameter, if any.
null
if not availablepublic double getQualityValue()
q
parameter, if any.
Defaults to 1.0
.
public java.lang.String getParameter(java.lang.String name)
name
- the parameter name
null
if not presentpublic boolean includes(MediaType other)
MediaType
includes the given media type.
For instance, text/*
includes text/plain
and text/html
, and application/*+xml
includes application/soap+xml
, etc. This method is not symmetric.
other
- the reference media type with which to compare
true
if this media type includes the given media type; false
otherwisepublic boolean isCompatibleWith(MediaType other)
MediaType
is compatible with the given media type.
For instance, text/*
is compatible with text/plain
, text/html
, and vice versa.
In effect, this method is similar to includes(MediaType)
, except that it is symmetric.
other
- the reference media type with which to compare
true
if this media type is compatible with the given media type; false
otherwisepublic int compareTo(MediaType other)
MediaType
to another alphabetically.
compareTo
in interface java.lang.Comparable<MediaType>
other
- media type to compare tosortBySpecificity(List)
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
private void appendTo(java.lang.StringBuilder builder)
private void appendTo(java.util.Map<java.lang.String,java.lang.String> map, java.lang.StringBuilder builder)
public static MediaType valueOf(java.lang.String value)
MediaType
object,
with this method name following the 'valueOf' naming convention
(as supported by ConversionService
.
parseMediaType(String)
public static MediaType parseMediaType(java.lang.String mediaType)
MediaType
.
mediaType
- the string to parse
java.lang.IllegalArgumentException
- if the string cannot be parsedpublic static java.util.List<MediaType> parseMediaTypes(java.lang.String mediaTypes)
MediaType
objects.
This method can be used to parse an Accept or Content-Type header.
mediaTypes
- the string to parse
java.lang.IllegalArgumentException
- if the string cannot be parsedpublic static java.lang.String toString(java.util.Collection<MediaType> mediaTypes)
MediaType
objects.
This method can be used to for an Accept
or Content-Type
header.
mediaTypes
- the string to parse
java.lang.IllegalArgumentException
- if the String cannot be parsedpublic static void sortBySpecificity(java.util.List<MediaType> mediaTypes)
MediaType
objects by specificity.
Given two media types:
For example:
audio/basic < audio/* < */*
audio/* < audio/*;q=0.7; audio/*;q=0.3
audio/basic;level=1 < audio/basic
audio/basic == text/html
audio/basic == audio/wave
mediaTypes
- the list of media types to be sortedpublic static void sortByQualityValue(java.util.List<MediaType> mediaTypes)
MediaType
objects by quality value.
Given two media types:
mediaTypes
- the list of media types to be sortedgetQualityValue()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |