public final class MediaTypes extends Object
Modifier and Type | Field and Description |
---|---|
static Comparator<List<? extends javax.ws.rs.core.MediaType>> |
MEDIA_TYPE_LIST_COMPARATOR
Comparator for lists of media types.
|
static Comparator<javax.ws.rs.core.MediaType> |
PARTIAL_ORDER_COMPARATOR
A comparator for media types, that implements the "partial order" defined in the resource matching algorithm
section of the JAX-RS specification, except that this comparator is "inverted" so that it allows for natural
sorting in Java collections, where "lower" values are put to the front of a collection.
|
static javax.ws.rs.core.MediaType |
WADL_TYPE
WADL Media type.
|
static AcceptableMediaType |
WILDCARD_ACCEPTABLE_TYPE
An acceptable media type corresponding to a wildcard type.
|
static QualitySourceMediaType |
WILDCARD_QS_TYPE
An acceptable media type corresponding to a wildcard type.
|
static List<javax.ws.rs.core.MediaType> |
WILDCARD_QS_TYPE_SINGLETON_LIST
A singleton list containing the wildcard media type.
|
static List<javax.ws.rs.core.MediaType> |
WILDCARD_TYPE_SINGLETON_LIST
A singleton list containing the wildcard media type.
|
Modifier and Type | Method and Description |
---|---|
static String |
convertToString(Iterable<javax.ws.rs.core.MediaType> mediaTypes)
Convert media types into
String . |
static List<javax.ws.rs.core.MediaType> |
createFrom(javax.ws.rs.Consumes annotation)
Create an unmodifiable list of media types from the values declared in the
Consumes
annotation. |
static List<javax.ws.rs.core.MediaType> |
createFrom(javax.ws.rs.Produces annotation)
Create an unmodifiable list of media types from the values declared in the
Produces
annotation. |
static List<javax.ws.rs.core.MediaType> |
createFrom(String[] mediaTypes)
Create an unmodifiable list of media type from a string array of media types.
|
static List<javax.ws.rs.core.MediaType> |
createQualitySourceMediaTypes(javax.ws.rs.Produces mime)
Create a list of quality source media type from the Produces annotation.
|
static List<QualitySourceMediaType> |
createQualitySourceMediaTypes(String[] mediaTypes)
Create a list of quality source media type from an array of media types.
|
static int |
getQuality(javax.ws.rs.core.MediaType mt)
Reads quality factor from given media type.
|
static javax.ws.rs.core.MediaType |
getTypeWildCart(javax.ws.rs.core.MediaType mediaType)
Returns MediaType with wildcard in subtype.
|
static boolean |
intersect(List<? extends javax.ws.rs.core.MediaType> ml1,
List<? extends javax.ws.rs.core.MediaType> ml2)
Determine if the two list of media types share a common
type-equal
sub-list. |
static boolean |
isWildcard(javax.ws.rs.core.MediaType mediaType)
Check if the given media type is a wildcard type.
|
static javax.ws.rs.core.MediaType |
mostSpecific(javax.ws.rs.core.MediaType m1,
javax.ws.rs.core.MediaType m2)
Get the most specific media type from a pair of media types.
|
static javax.ws.rs.core.MediaType |
stripQualityParams(javax.ws.rs.core.MediaType mediaType)
Strips any quality parameters, i.e.
|
static boolean |
typeEqual(javax.ws.rs.core.MediaType m1,
javax.ws.rs.core.MediaType m2)
Determine if the two media types are type-equal (their
type
and subtype are equal). |
public static final javax.ws.rs.core.MediaType WADL_TYPE
public static final Comparator<javax.ws.rs.core.MediaType> PARTIAL_ORDER_COMPARATOR
m/n < m/* < */*The actual media type values are ignored, i.e. the different media types are considered equal if they are comparably specific:
compare(m/n, x/y) == 0 compare(m/*, x/*) == 0
public static final Comparator<List<? extends javax.ws.rs.core.MediaType>> MEDIA_TYPE_LIST_COMPARATOR
The least specific content type of each list is obtained and then compared
using PARTIAL_ORDER_COMPARATOR
.
Assumes each list is already ordered according to PARTIAL_ORDER_COMPARATOR
and therefore the least specific media type is at the end of the list.
public static final List<javax.ws.rs.core.MediaType> WILDCARD_TYPE_SINGLETON_LIST
public static final AcceptableMediaType WILDCARD_ACCEPTABLE_TYPE
public static final QualitySourceMediaType WILDCARD_QS_TYPE
public static final List<javax.ws.rs.core.MediaType> WILDCARD_QS_TYPE_SINGLETON_LIST
public static boolean typeEqual(javax.ws.rs.core.MediaType m1, javax.ws.rs.core.MediaType m2)
type
and subtype
are equal). For example:
m/n == m/n m/n;p1 == m/n;p2 m/n != m/y m/n != x/n m/n != x/y
m1
- first media type.m2
- second media type.true
if the two media types are of the same type and subtype,
false
otherwise.public static boolean intersect(List<? extends javax.ws.rs.core.MediaType> ml1, List<? extends javax.ws.rs.core.MediaType> ml2)
type-equal
sub-list.ml1
- first media type list.ml2
- second media type list.true
if the two media type lists intersect by sharing a
common type-equal sub-list, false
otherwise.public static javax.ws.rs.core.MediaType mostSpecific(javax.ws.rs.core.MediaType m1, javax.ws.rs.core.MediaType m2)
m1
- the first media type.m2
- the second media type.public static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Consumes annotation)
Consumes
annotation.annotation
- the Consumes annotation.MediaType
, ordered according to PARTIAL_ORDER_COMPARATOR
.public static List<javax.ws.rs.core.MediaType> createFrom(javax.ws.rs.Produces annotation)
Produces
annotation.annotation
- the Produces annotation.MediaType
, ordered according to PARTIAL_ORDER_COMPARATOR
.public static List<javax.ws.rs.core.MediaType> createFrom(String[] mediaTypes)
mediaTypes
- the string array of media types.MediaType
, ordered according to PARTIAL_ORDER_COMPARATOR
.public static List<javax.ws.rs.core.MediaType> createQualitySourceMediaTypes(javax.ws.rs.Produces mime)
mime
- the Produces annotation.QualitySourceMediaType
, ordered according to
QualitySourceMediaType.COMPARATOR
.public static List<QualitySourceMediaType> createQualitySourceMediaTypes(String[] mediaTypes)
mediaTypes
- the array of media types.QualitySourceMediaType
, ordered according to
the quality source as the primary key and PARTIAL_ORDER_COMPARATOR
as the secondary key.public static int getQuality(javax.ws.rs.core.MediaType mt)
mt
- media type to read quality parameter frompublic static javax.ws.rs.core.MediaType stripQualityParams(javax.ws.rs.core.MediaType mediaType)
mediaType
- type to strip quality parameters frompublic static javax.ws.rs.core.MediaType getTypeWildCart(javax.ws.rs.core.MediaType mediaType)
mediaType
- original MediaType.public static String convertToString(Iterable<javax.ws.rs.core.MediaType> mediaTypes)
String
. The result string contains
media types in the same order, separated by comma ',' and enclosed into quotes.
For example for input media types
MediaType.TEXT_PLAIN_TYPE
, MediaType.TEXT_PLAIN_TYPE
and
MediaType.APPLICATION_JSON_TYPE
the result will be
"text/plain", "application/json", "text/html".mediaTypes
- iterable
with media types
.public static boolean isWildcard(javax.ws.rs.core.MediaType mediaType)
mediaType
- media type.true
if the media type is a wildcard type, false
otherwise.Copyright © 2007-2021, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.