Interface TruffleFile.FileTypeDetector

Enclosing class:
TruffleFile

public static interface TruffleFile.FileTypeDetector
A detector for finding file's MIME type and encoding.

The means by which the detector determines the MIME is highly implementation specific. A simple implementation might detect the MIME type using file extension. In other cases, the content of file needs to be examined to guess its file type.

The implementations are registered using TruffleLanguage registration.

Since:
19.0
See Also:
  • Method Details

    • findMimeType

      String findMimeType(TruffleFile file) throws IOException
      Finds a MIME type for given TruffleFile.
      Parameters:
      file - the file to find a MIME type for
      Returns:
      the MIME type or null if the MIME type is not recognized
      Throws:
      IOException - of an I/O error occurs
      SecurityException - if the implementation requires an access the file and the FileSystem denies the operation
      Since:
      19.0
    • findEncoding

      Charset findEncoding(TruffleFile file) throws IOException
      For a file containing an encoding information returns the encoding.
      Parameters:
      file - the file to find an encoding for. It's guaranteed that the file has a MIME type supported by the language registering this TruffleFile.FileTypeDetector.
      Returns:
      the file encoding or null if the file does not provide encoding
      Throws:
      IOException - of an I/O error occurs
      SecurityException - if the FileSystem denies the file access
      Since:
      19.0