public final class MediaTypeSet extends AbstractSet<MediaType>
Set of MediaTypes which provides useful methods for content negotiation.
This Set provides match(MediaType) and matchHeaders(CharSequence...)
so that a user can find the preferred MediaType that matches the specified media ranges. For example:
MediaTypeSet set = new MediaTypeSet(MediaType.HTML_UTF_8, MediaType.PLAIN_TEXT_UTF_8);
MediaType negotiated1 = set.matchHeaders("text/html; q=0.5, text/plain");
assert negotiated1 != null;
assert negotiated1.equals(MediaType.PLAIN_TEXT_UTF_8);
MediaType negotiated2 = set.matchHeaders("audio/*, text/*");
assert negotiated2 != null;
assert negotiated2.equals(MediaType.HTML_UTF_8);
MediaType negotiated3 = set.matchHeaders("video/webm");
assert negotiated3 == null;
| Constructor and Description |
|---|
MediaTypeSet(Iterable<MediaType> mediaTypes)
Deprecated.
Use
of(Iterable). |
MediaTypeSet(MediaType... mediaTypes)
Deprecated.
Use
of(MediaType...). |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(Object o) |
Iterator<MediaType> |
iterator() |
MediaType |
match(Iterable<MediaType> ranges)
|
MediaType |
match(MediaType range)
|
MediaType |
match(MediaType first,
MediaType... rest)
|
MediaType |
matchHeaders(CharSequence... acceptHeaders)
|
MediaType |
matchHeaders(Iterable<? extends CharSequence> acceptHeaders)
|
static MediaTypeSet |
of(Iterable<MediaType> mediaTypes)
Returns the
MediaTypeSet which is composed of the specified MediaTypes. |
static MediaTypeSet |
of(MediaType... mediaTypes)
Returns the
MediaTypeSet which is composed of the specified MediaTypes. |
int |
size() |
equals, hashCode, removeAlladd, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, addAll, clear, containsAll, isEmpty, remove, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, stream@Deprecated public MediaTypeSet(MediaType... mediaTypes)
of(MediaType...).@Deprecated public MediaTypeSet(Iterable<MediaType> mediaTypes)
of(Iterable).public static MediaTypeSet of(MediaType... mediaTypes)
MediaTypeSet which is composed of the specified MediaTypes.public static MediaTypeSet of(Iterable<MediaType> mediaTypes)
MediaTypeSet which is composed of the specified MediaTypes.public boolean contains(Object o)
contains in interface Collection<MediaType>contains in interface Set<MediaType>contains in class AbstractCollection<MediaType>public int size()
size in interface Collection<MediaType>size in interface Set<MediaType>size in class AbstractCollection<MediaType>public MediaType matchHeaders(Iterable<? extends CharSequence> acceptHeaders)
MediaType in this List that matches one of the media ranges specified in the
specified string.acceptHeaders - the values of the "accept" header, as defined in
the section 14.1, RFC2616MediaType that matches one of the specified media ranges.
null if there are no matches or acceptHeaders does not contain any valid ranges.public MediaType matchHeaders(CharSequence... acceptHeaders)
MediaType in this List that matches one of the media ranges specified in the
specified string.acceptHeaders - the values of the "accept" header, as defined in
the section 14.1, RFC2616MediaType that matches one of the specified media ranges.
null if there are no matches or acceptHeaders does not contain any valid ranges.public MediaType match(MediaType range)
MediaType that matches the specified media range.
null if there are no matchespublic MediaType match(MediaType first, MediaType... rest)
MediaType that matches one of the specified media ranges.
null if there are no matches or the specified ranges do not contain any valid ranges.Copyright © 2020 LeanCloud. All rights reserved.