Package com.linecorp.armeria.common
Class MediaTypeSet
An immutable
Set
of MediaType
s 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 = MediaTypeSet.of(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;
-
Method Summary
Modifier and TypeMethodDescriptionboolean
iterator()
matchHeaders
(CharSequence... acceptHeaders) matchHeaders
(Iterable<? extends CharSequence> acceptHeaders) static MediaTypeSet
Returns theMediaTypeSet
which is composed of the specifiedMediaType
s.static MediaTypeSet
Returns theMediaTypeSet
which is composed of the specifiedMediaType
s.int
size()
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Method Details
-
of
Returns theMediaTypeSet
which is composed of the specifiedMediaType
s. -
of
Returns theMediaTypeSet
which is composed of the specifiedMediaType
s. -
contains
- Specified by:
contains
in interfaceCollection<MediaType>
- Specified by:
contains
in interfaceSet<MediaType>
- Overrides:
contains
in classAbstractCollection<MediaType>
-
iterator
-
size
public int size()- Specified by:
size
in interfaceCollection<MediaType>
- Specified by:
size
in interfaceSet<MediaType>
- Specified by:
size
in classAbstractCollection<MediaType>
-
matchHeaders
Finds theMediaType
in thisList
that matches one of the media ranges specified in the specified string.- Parameters:
acceptHeaders
- the values of the"accept"
header, as defined in the section 14.1, RFC2616- Returns:
- the most preferred
MediaType
that matches one of the specified media ranges.null
if there are no matches oracceptHeaders
does not contain any valid ranges.
-
matchHeaders
Finds theMediaType
in thisList
that matches one of the media ranges specified in the specified string.- Parameters:
acceptHeaders
- the values of the"accept"
header, as defined in the section 14.1, RFC2616- Returns:
- the most preferred
MediaType
that matches one of the specified media ranges.null
if there are no matches oracceptHeaders
does not contain any valid ranges.
-
match
- Returns:
- the
MediaType
that matches the specified media range.null
if there are no matches
-
match
- Returns:
- the most preferred
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.
-
match
- Returns:
- the most preferred
MediaType
that matches one of the specified media ranges.null
if there are no matches orranges
does not contain any valid ranges.
-