-
- All Implemented Interfaces:
public final class MediaTypeRepresents a document format, identified by a unique RFC 6838 media type.
MediaType handles:
components parsing – eg. type, subtype and parameters,
media types comparison.
Comparing media types is more complicated than it looks, since they can contain parameters, such as
charset=utf-8. We can't ignore them because some formats use parameters in their media type, for exampleapplication/atom+xml;profile=opds-catalogfor an OPDS 1 catalog.Specification: https://tools.ietf.org/html/rfc6838
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classMediaType.Companion
-
Field Summary
Fields Modifier and Type Field Description private final Stringtypeprivate final Stringsubtypeprivate final Map<String, String>parametersprivate final StringstructuredSyntaxSuffixprivate final Charsetcharsetprivate final BooleanisZipprivate final BooleanisJsonprivate final BooleanisOpdsprivate final BooleanisHtmlprivate final BooleanisBitmapprivate final BooleanisAudioprivate final BooleanisVideoprivate final BooleanisRwpmprivate final BooleanisPublicationprivate final MediaTypemediaTypeprivate final Stringnameprivate final StringfileExtension
-
Method Summary
Modifier and Type Method Description final StringgetType()The type component, e.g. final StringgetSubtype()The subtype component, e.g. final Map<String, String>getParameters()The parameters in the media type, such as charset=utf-8.final StringgetStructuredSyntaxSuffix()final CharsetgetCharset()final BooleanisZip()final BooleanisJson()final BooleanisOpds()final BooleanisHtml()final BooleanisBitmap()final BooleanisAudio()final BooleanisVideo()final BooleanisRwpm()final BooleanisPublication()final MediaTypegetMediaType()final StringgetName()final StringgetFileExtension()final MediaTypecanonicalMediaType()Returns the canonical version of this media type, if it is known. StringtoString()The string representation of this media type. Booleanequals(Object other)Returns whether two media types are equal, checking the type, subtype and parameters. IntegerhashCode()final Booleancontains(MediaType other)Returns whether the given other media type is included in this media type. final Booleancontains(String other)Returns whether the given other media type is included in this media type. final Booleanmatches(MediaType other)Returns whether this media type and otherare the same, ignoring parameters that are not in both media types.final Booleanmatches(String other)Returns whether this media type and otherare the same, ignoring parameters that are not in both media types.final BooleanmatchesAny(MediaType others)Returns whether this media type matches any of the othersmedia types.final BooleanmatchesAny(String others)Returns whether this media type matches any of the othersmedia types.-
-
Method Detail
-
getSubtype
final String getSubtype()
The subtype component, e.g.
epub+zipinapplication/epub+zip.
-
getParameters
final Map<String, String> getParameters()
The parameters in the media type, such as
charset=utf-8.
-
getStructuredSyntaxSuffix
final String getStructuredSyntaxSuffix()
-
getCharset
final Charset getCharset()
-
isPublication
final Boolean isPublication()
-
getMediaType
final MediaType getMediaType()
-
getFileExtension
final String getFileExtension()
-
canonicalMediaType
final MediaType canonicalMediaType()
Returns the canonical version of this media type, if it is known.
This is useful to find the name and file extension of a known media type, or to get the canonical media type from an alias. For example,
application/x-cbzis an alias of the canonicalapplication/vnd.comicbook+zip.Non-significant parameters are also discarded.
-
equals
Boolean equals(Object other)
Returns whether two media types are equal, checking the type, subtype and parameters. Parameters order is ignored.
WARNING: Strict media type comparisons can be a source of bug, if parameters are present.
text/html!=text/html;charset=utf-8with strict equality comparison, which is most likely not the desired result. Instead, you can use matches to check if any of the media types is a parameterized version of the other one.
-
contains
final Boolean contains(MediaType other)
Returns whether the given other media type is included in this media type.
For example,
text/htmlcontainstext/html;charset=utf-8.other must match the parameters in the parameters property, but extra parameters are ignored.
Order of parameters is ignored.
Wildcards are supported, meaning that
image/*containsimage/pngand*/*contains everything.
-
contains
final Boolean contains(String other)
Returns whether the given other media type is included in this media type.
-
matches
final Boolean matches(MediaType other)
Returns whether this media type and
otherare the same, ignoring parameters that are not in both media types.For example,
text/htmlmatchestext/html;charset=utf-8, buttext/html;charset=asciidoesn't. This is basically likecontains, but working in both direction.
-
matches
final Boolean matches(String other)
Returns whether this media type and
otherare the same, ignoring parameters that are not in both media types.
-
matchesAny
final Boolean matchesAny(MediaType others)
Returns whether this media type matches any of the
othersmedia types.
-
matchesAny
final Boolean matchesAny(String others)
Returns whether this media type matches any of the
othersmedia types.
-
-
-
-