-
- All Implemented Interfaces:
public final class SnifferContextA companion type of Sniffer holding the type hints (file extensions, media types) and providing an access to the file content.
-
-
Field Summary
Fields Modifier and Type Field Description private final List<MediaType>mediaTypesprivate final List<String>fileExtensionsprivate final Charsetcharset
-
Method Summary
Modifier and Type Method Description final List<MediaType>getMediaTypes()Media type hints. final List<String>getFileExtensions()File extension hints. final CharsetgetCharset()Finds the first Charset declared in the media types' charsetparameter.final BooleanhasFileExtension(String fileExtensions)Returns whether this context has any of the given file extensions, ignoring case. final BooleanhasMediaType(String mediaTypes)Returns whether this context has any of the given media type, ignoring case and extra parameters. final StringcontentAsString()Content as plain text. final ElementNodecontentAsXml()Content as an XML document. final ArchivecontentAsArchive()Content as an Archive instance. final JSONObjectcontentAsJson()Content parsed from JSON. final ManifestcontentAsRwpm()Readium Web Publication Manifest parsed from the content. final InputStreamstream()Raw bytes stream of the content. final ByteArrayread(LongRange range)Reads all the bytes or the given range. -
-
Method Detail
-
getMediaTypes
final List<MediaType> getMediaTypes()
Media type hints.
-
getFileExtensions
final List<String> getFileExtensions()
File extension hints.
-
getCharset
final Charset getCharset()
Finds the first Charset declared in the media types'
charsetparameter.
-
hasFileExtension
final Boolean hasFileExtension(String fileExtensions)
Returns whether this context has any of the given file extensions, ignoring case.
-
hasMediaType
final Boolean hasMediaType(String mediaTypes)
Returns whether this context has any of the given media type, ignoring case and extra parameters.
Implementation note: Use MediaType to handle the comparison to avoid edge cases.
-
contentAsString
final String contentAsString()
Content as plain text.
It will extract the charset parameter from the media type hints to figure out an encoding. Otherwise, fallback on UTF-8.
-
contentAsXml
final ElementNode contentAsXml()
Content as an XML document.
-
contentAsArchive
final Archive contentAsArchive()
Content as an Archive instance. Warning: Archive is only supported for a local file, for now.
-
contentAsJson
final JSONObject contentAsJson()
Content parsed from JSON.
-
contentAsRwpm
final Manifest contentAsRwpm()
Readium Web Publication Manifest parsed from the content.
-
stream
final InputStream stream()
Raw bytes stream of the content.
A byte stream can be useful when sniffers only need to read a few bytes at the beginning of the file.
-
-
-
-