Package com.aspectran.web.support.http
Class MediaTypeUtils
- java.lang.Object
-
- com.aspectran.web.support.http.MediaTypeUtils
-
public abstract class MediaTypeUtils extends java.lang.Object
MiscellaneousMediaType
utility methods.- Author:
- Arjen Poutsma, Rossen Stoyanchev, Dimitrios Liapis, Brian Clozel
-
-
Field Summary
Fields Modifier and Type Field Description static MediaType
ALL
Public constant media type that includes all media ranges (i.e.static java.lang.String
ALL_VALUE
A String equivalent ofALL
.static MediaType
APPLICATION_JSON
Public constant media type forapplication/json
.static java.lang.String
APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON
.static MediaType
APPLICATION_OCTET_STREAM
Public constant media type forapplication/octet-stream
.static java.lang.String
APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM
.static MediaType
APPLICATION_XML
Public constant media type forapplication/xml
.static java.lang.String
APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML
.static MediaType
IMAGE_GIF
Public constant media type forimage/gif
.static java.lang.String
IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF
.static MediaType
IMAGE_JPEG
Public constant media type forimage/jpeg
.static java.lang.String
IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG
.static MediaType
IMAGE_PNG
Public constant media type forimage/png
.static java.lang.String
IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG
.static java.util.Comparator<MediaType>
SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List)
.static MediaType
TEXT_HTML
Public constant media type fortext/html
.static java.lang.String
TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML
.static MediaType
TEXT_PLAIN
Public constant media type fortext/plain
.static java.lang.String
TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN
.static MediaType
TEXT_XML
Public constant media type fortext/xml
.static java.lang.String
TEXT_XML_VALUE
A String equivalent ofTEXT_XML
.
-
Constructor Summary
Constructors Constructor Description MediaTypeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MediaType
parseMediaType(java.lang.String mediaType)
Parse the given String into a singleMediaType
.static java.util.List<MediaType>
parseMediaTypes(java.lang.String mediaTypes)
Parse the comma-separated string into a list ofMediaType
objects.static void
sortBySpecificity(java.util.List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity.static java.util.List<java.lang.String>
tokenize(java.lang.String mediaTypes)
Tokenize the given comma-separated string ofMediaType
objects into aList<String>
.static java.lang.String
toString(java.util.Collection<MediaType> mediaTypes)
Return a string representation of the given list ofMediaType
objects.
-
-
-
Field Detail
-
SPECIFICITY_COMPARATOR
public static final java.util.Comparator<MediaType> SPECIFICITY_COMPARATOR
Comparator used bysortBySpecificity(List)
.
-
ALL
public static final MediaType ALL
Public constant media type that includes all media ranges (i.e. "*/*").
-
ALL_VALUE
public static final java.lang.String ALL_VALUE
A String equivalent ofALL
.- See Also:
- Constant Field Values
-
APPLICATION_JSON
public static final MediaType APPLICATION_JSON
Public constant media type forapplication/json
.
-
APPLICATION_JSON_VALUE
public static final java.lang.String APPLICATION_JSON_VALUE
A String equivalent ofAPPLICATION_JSON
.- See Also:
- Constant Field Values
-
APPLICATION_OCTET_STREAM
public static final MediaType APPLICATION_OCTET_STREAM
Public constant media type forapplication/octet-stream
.
-
APPLICATION_OCTET_STREAM_VALUE
public static final java.lang.String APPLICATION_OCTET_STREAM_VALUE
A String equivalent ofAPPLICATION_OCTET_STREAM
.- See Also:
- Constant Field Values
-
APPLICATION_XML
public static final MediaType APPLICATION_XML
Public constant media type forapplication/xml
.
-
APPLICATION_XML_VALUE
public static final java.lang.String APPLICATION_XML_VALUE
A String equivalent ofAPPLICATION_XML
.- See Also:
- Constant Field Values
-
IMAGE_GIF
public static final MediaType IMAGE_GIF
Public constant media type forimage/gif
.
-
IMAGE_GIF_VALUE
public static final java.lang.String IMAGE_GIF_VALUE
A String equivalent ofIMAGE_GIF
.- See Also:
- Constant Field Values
-
IMAGE_JPEG
public static final MediaType IMAGE_JPEG
Public constant media type forimage/jpeg
.
-
IMAGE_JPEG_VALUE
public static final java.lang.String IMAGE_JPEG_VALUE
A String equivalent ofIMAGE_JPEG
.- See Also:
- Constant Field Values
-
IMAGE_PNG
public static final MediaType IMAGE_PNG
Public constant media type forimage/png
.
-
IMAGE_PNG_VALUE
public static final java.lang.String IMAGE_PNG_VALUE
A String equivalent ofIMAGE_PNG
.- See Also:
- Constant Field Values
-
TEXT_HTML
public static final MediaType TEXT_HTML
Public constant media type fortext/html
.
-
TEXT_HTML_VALUE
public static final java.lang.String TEXT_HTML_VALUE
A String equivalent ofTEXT_HTML
.- See Also:
- Constant Field Values
-
TEXT_PLAIN
public static final MediaType TEXT_PLAIN
Public constant media type fortext/plain
.
-
TEXT_PLAIN_VALUE
public static final java.lang.String TEXT_PLAIN_VALUE
A String equivalent ofTEXT_PLAIN
.- See Also:
- Constant Field Values
-
TEXT_XML
public static final MediaType TEXT_XML
Public constant media type fortext/xml
.
-
TEXT_XML_VALUE
public static final java.lang.String TEXT_XML_VALUE
A String equivalent ofTEXT_XML
.- See Also:
- Constant Field Values
-
-
Method Detail
-
parseMediaType
public static MediaType parseMediaType(java.lang.String mediaType)
Parse the given String into a singleMediaType
. Recently parsedMediaType
are cached for further retrieval.- Parameters:
mediaType
- the string to parse- Returns:
- the media type
- Throws:
InvalidMediaTypeException
- if the string cannot be parsed
-
parseMediaTypes
public static java.util.List<MediaType> parseMediaTypes(java.lang.String mediaTypes)
Parse the comma-separated string into a list ofMediaType
objects.- Parameters:
mediaTypes
- the string to parse- Returns:
- the list of media types
- Throws:
InvalidMediaTypeException
- if the string cannot be parsed
-
tokenize
public static java.util.List<java.lang.String> tokenize(java.lang.String mediaTypes)
Tokenize the given comma-separated string ofMediaType
objects into aList<String>
. Unlike simple tokenization by ",", this method takes into account quoted parameters.- Parameters:
mediaTypes
- the string to tokenize- Returns:
- the list of tokens
-
toString
public static java.lang.String toString(java.util.Collection<MediaType> mediaTypes)
Return a string representation of the given list ofMediaType
objects.- Parameters:
mediaTypes
- the string to parse- Returns:
- the list of media types
- Throws:
java.lang.IllegalArgumentException
- if the String cannot be parsed
-
sortBySpecificity
public static void sortBySpecificity(java.util.List<MediaType> mediaTypes)
Sorts the given list ofMediaType
objects by specificity.Given two media types:
- if either media type has a wildcard type, then the media type without the wildcard is ordered before the other.
- if the two media types have different types, then they are considered equal and remain their current order.
- if either media type has a wildcard subtype , then the media type without the wildcard is sorted before the other.
- if the two media types have different subtypes, then they are considered equal and remain their current order.
- if the two media types have a different amount of parameters, then the media type with the most parameters is ordered before the other.
For example:
audio/basic < audio/* < */*
audio/basic;level=1 < audio/basic
audio/basic == text/html
audio/basic == audio/wave
- Parameters:
mediaTypes
- the list of media types to be sorted- See Also:
- HTTP 1.1: Semantics and Content, section 5.3.2
-
-