Package 

Class SnifferContext

  • All Implemented Interfaces:

    
    public final class SnifferContext
    
                        

    A companion type of Sniffer holding the type hints (file extensions, media types) and providing an access to the file content.

    • Constructor Detail

    • Method Detail

      • 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.

      • contentAsArchive

         final Archive contentAsArchive()

        Content as an Archive instance. Warning: Archive is only supported for a local file, for now.

      • 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.

      • read

         final ByteArray read(LongRange range)

        Reads all the bytes or the given range.

        It can be used to check a file signature, aka magic number. See https://en.wikipedia.org/wiki/List_of_file_signatures