-
- All Implemented Interfaces:
-
android.os.Parcelable
public final class MediaType implements Parcelable
Represents 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 StringstructuredSyntaxSuffixprivate final Charsetcharsetprivate final BooleanisZipprivate final BooleanisJsonprivate final BooleanisOpdsprivate final BooleanisHtmlprivate final BooleanisBitmapprivate final BooleanisAudioprivate final BooleanisVideoprivate final BooleanisRwpmprivate final BooleanisRpfprivate final BooleanisPublicationprivate final StringfileExtensionprivate final Stringtypeprivate final Stringsubtypeprivate final Map<String, String>parameters
-
Method Summary
Modifier and Type Method Description final StringgetStructuredSyntaxSuffix()final CharsetgetCharset()final BooleangetIsZip()final BooleangetIsJson()final BooleangetIsOpds()final BooleangetIsHtml()final BooleangetIsBitmap()final BooleangetIsAudio()final BooleangetIsVideo()final BooleangetIsRwpm()final BooleangetIsRpf()final BooleangetIsPublication()final StringgetFileExtension()final StringgetType()final StringgetSubtype()final Map<String, String>getParameters()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
-
getStructuredSyntaxSuffix
final String getStructuredSyntaxSuffix()
-
getCharset
final Charset getCharset()
-
getIsBitmap
final Boolean getIsBitmap()
-
getIsAudio
final Boolean getIsAudio()
-
getIsVideo
final Boolean getIsVideo()
-
getIsPublication
final Boolean getIsPublication()
-
getFileExtension
final String getFileExtension()
-
getSubtype
final String getSubtype()
-
getParameters
final Map<String, String> getParameters()
-
canonicalMediaType
@Deprecated(message = Use FormatRegistry.canonicalize() instead, replaceWith = @ReplaceWith(imports = {}, expression = formatRegistry.canonicalize(this)), level = DeprecationLevel.ERROR) 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.
-
-
-
-