|
|||||||||
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 that includes all media ranges (i.e. |
Constructor Summary | |
---|---|
MediaType(String type)
Create a new MediaType for the given primary type. |
|
MediaType(String type,
String subtype)
Create a new MediaType for the given primary type and subtype. |
|
MediaType(String type,
String subtype,
Charset charSet)
Create a new MediaType for the given type, subtype, and character set. |
|
MediaType(String type,
String subtype,
double qualityValue)
Create a new MediaType for the given type, subtype, and quality value. |
|
MediaType(String type,
String subtype,
Map<String,String> parameters)
Create a new MediaType for the given type, subtype, and parameters. |
Method Summary | |
---|---|
int |
compareTo(MediaType other)
Compares this MediaType to another alphabetically. |
boolean |
equals(Object other)
|
Charset |
getCharSet()
Return the character set, as indicated by a charset parameter, if any. |
String |
getParameter(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. |
String |
getSubtype()
Return the subtype. |
String |
getType()
Return the primary type. |
int |
hashCode()
|
boolean |
includes(MediaType other)
Indicate whether this MediaType includes the given media type. |
boolean |
isWildcardSubtype()
Indicate whether the subtype is the wildcard character * or not. |
boolean |
isWildcardType()
Indicate whether the type is the wildcard character * or not. |
static MediaType |
parseMediaType(String mediaType)
Parse the given String into a single MediaType . |
static List<MediaType> |
parseMediaTypes(String mediaTypes)
Parse the given, comma-seperated string into a list of MediaType objects. |
static void |
sortBySpecificity(List<MediaType> mediaTypes)
Sorts the given list of MediaType objects by specificity. |
String |
toString()
|
static String |
toString(Collection<MediaType> mediaTypes)
Return a string representation of the given list of MediaType objects. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final MediaType ALL
*/*
).
Constructor Detail |
---|
public MediaType(String type)
MediaType
for the given primary type.
The subtype is set to *
, parameters empty.
type
- the primary type
IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype)
MediaType
for the given primary type and subtype. The parameters are empty.
type
- the primary typesubtype
- the subtype
IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype, Charset charSet)
MediaType
for the given type, subtype, and character set.
type
- the primary typesubtype
- the subtypecharSet
- the character set
IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype, double qualityValue)
MediaType
for the given type, subtype, and quality value.
type
- the primary typesubtype
- the subtypequalityValue
- the quality value
IllegalArgumentException
- if any of the parameters contain illegal characterspublic MediaType(String type, String subtype, Map<String,String> parameters)
MediaType
for the given type, subtype, and parameters.
type
- the primary typesubtype
- the subtypeparameters
- the parameters, mat be null
IllegalArgumentException
- if any of the parameters contain illegal charactersMethod Detail |
---|
public String getType()
public boolean isWildcardType()
*
or not.
public String getSubtype()
public boolean isWildcardSubtype()
*
or not.
*
public Charset getCharSet()
charset
parameter, if any.
null
if not availablepublic double getQualityValue()
q
parameter, if any. Defaults to 1.0
.
public String getParameter(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
, text/html
, and application/*+xml
includes application/soap+xml
, etc.
other
- the reference media type with which to compare
true
if this media type includes the given media type; false
otherwisepublic int compareTo(MediaType other)
MediaType
to another alphabetically.
compareTo
in interface Comparable<MediaType>
other
- media type to compare tosortBySpecificity(List)
public boolean equals(Object other)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public static MediaType parseMediaType(String mediaType)
MediaType
.
mediaType
- the string to parse
IllegalArgumentException
- if the string cannot be parsedpublic static List<MediaType> parseMediaTypes(String mediaTypes)
MediaType
objects. This method can be used to parse an Accept or Content-Type header.
mediaTypes
- the string to parse
IllegalArgumentException
- if the string cannot be parsedpublic static String toString(Collection<MediaType> mediaTypes)
MediaType
objects.
This method can be used to for an Accept
or Content-Type
header.
mediaTypes
- the string to parse
IllegalArgumentException
- if the String cannot be parsedpublic static void sortBySpecificity(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 sorted
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |