- java.lang.Object
-
- org.arakhne.afc.inputoutput.filetype.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
fileLinux 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileType.ContentFileTypeMapMap that contains the file content type definitions.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddContentType(MagicNumber magicNumber)Register a MIME type of the given file.static FileType.ContentFileTypeMapensureContentTypeManager()Be sure that the default FileTypeMap is aFileType.ContentFileTypeMap.static StringgetContentType(File filename)Replies the MIME type of the given file.static StringgetContentType(String filename)Replies the MIME type of the given file.static StringgetContentType(URL filename)Replies the MIME type of the given file.static StringgetFormatVersion(File filename)Replies the version of the format of the given file.static StringgetFormatVersion(String filename)Replies the version of the format of the given file.static StringgetFormatVersion(URL filename)Replies the version of the format of the given file.static booleanisContentType(File filename, String desiredMimeType)Replies if the given file is compatible with the given MIME type.static booleanisContentType(String filename, String desiredMimeType)Replies if the given file is compatible with the given MIME type.static booleanisContentType(URL filename, String desiredMimeType)Replies if the given file is compatible with the given MIME type.static booleanisImage(String mime)Replies if the specified MIME type corresponds to an image.
-
-
-
Method Detail
-
ensureContentTypeManager
public static FileType.ContentFileTypeMap ensureContentTypeManager()
Be sure that the default FileTypeMap is aFileType.ContentFileTypeMap.- Returns:
- the default content type manager.
-
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:
trueif the given MIME type is corresponding to an image, otherwisefalse
-
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:
trueif the given file has type equal to the given MIME type, otherwisefalse.
-
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:
trueif the given file has type equal to the given MIME type, otherwisefalse.
-
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:
trueif the given file has type equal to the given MIME type, otherwisefalse.
-
-