Class FileType


  • public final class FileType
    extends Object
    An utility class that permits to detect the type of a file. This class determines the file type according to the file content (Unix approach) and not according to the filename extension (Windows® approach). A MIME constant is replied for the detected type.

    This class implements equivalent functionalities as the file Linux command.

    Since:
    14.0
    Version:
    17.0 2020-01-04 14:41:40
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    inputoutput
    • Method Detail

      • addContentType

        public static void addContentType​(MagicNumber magicNumber)
        Register a MIME type of the given file.
        Parameters:
        magicNumber - is the string that identify the type of the content.
      • getContentType

        public static String getContentType​(File filename)
        Replies the MIME type of the given file.
        Parameters:
        filename - is the name of the file to test.
        Returns:
        the MIME type of the given file.
      • getContentType

        public static String getContentType​(String filename)
        Replies the MIME type of the given file.
        Parameters:
        filename - is the name of the file to test.
        Returns:
        the MIME type of the given file.
      • getContentType

        public static String getContentType​(URL filename)
        Replies the MIME type of the given file.
        Parameters:
        filename - is the name of the file to test.
        Returns:
        the MIME type of the given file.
      • getFormatVersion

        public static String getFormatVersion​(File filename)
        Replies the version of the format of the given file.
        Parameters:
        filename - is the name of the file to test.
        Returns:
        the format version for the given file.
      • getFormatVersion

        public static String getFormatVersion​(String filename)
        Replies the version of the format of the given file.
        Parameters:
        filename - is the name of the file to test.
        Returns:
        the format version for the given file.
      • getFormatVersion

        public static String getFormatVersion​(URL filename)
        Replies the version of the format of the given file.
        Parameters:
        filename - is the name of the file to test.
        Returns:
        the format version for the given file.
      • isImage

        public static boolean isImage​(String mime)
        Replies if the specified MIME type corresponds to an image.
        Parameters:
        mime - is the MIME type to test.
        Returns:
        true if the given MIME type is corresponding to an image, otherwise false
      • isContentType

        public static boolean isContentType​(File filename,
                                            String desiredMimeType)
        Replies if the given file is compatible with the given MIME type.
        Parameters:
        filename - is the name of the file to test.
        desiredMimeType - is the desired MIME type.
        Returns:
        true if the given file has type equal to the given MIME type, otherwise false.
      • isContentType

        public static boolean isContentType​(String filename,
                                            String desiredMimeType)
        Replies if the given file is compatible with the given MIME type.
        Parameters:
        filename - is the name of the file to test.
        desiredMimeType - is the desired MIME type.
        Returns:
        true if the given file has type equal to the given MIME type, otherwise false.
      • isContentType

        public static boolean isContentType​(URL filename,
                                            String desiredMimeType)
        Replies if the given file is compatible with the given MIME type.
        Parameters:
        filename - is the name of the file to test.
        desiredMimeType - is the desired MIME type.
        Returns:
        true if the given file has type equal to the given MIME type, otherwise false.