Package org.appng.tools.file
Class MagicByteCheck
- java.lang.Object
-
- org.appng.tools.file.MagicByteCheck
-
public class MagicByteCheck extends Object
This is an utility class to to check the type of file by probing the magic bytes.- Author:
- Claus Stümke, aiticon GmbH, 2016
-
-
Constructor Summary
Constructors Constructor Description MagicByteCheck()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
compareFileExtensionWithMagicBytes(File sourceFile)
It checks the magic bytes of the file and compares the extension by magic byte match with the extension in the file name.static String
getExtensionByMagicBytes(File file)
Retrieves the file's extension by magic byte detection.
-
-
-
Method Detail
-
compareFileExtensionWithMagicBytes
public static boolean compareFileExtensionWithMagicBytes(File sourceFile)
It checks the magic bytes of the file and compares the extension by magic byte match with the extension in the file name. The magic byte match is not available for text files. Because here it is not possible to distinguish .csv from .txt files. The magic byte is the same. It is also not functioning reliable for MS Office or OpenOffice files. The method is tested for image files such as jpg, png and bmp. Please test this utility for other file types first.- Parameters:
sourceFile
- the file to check- Returns:
- true if the extension of the file is equal with the determined extension from magic bytes.
- Throws:
IllegalArgumentException
- if there is any issue reading the file
-
getExtensionByMagicBytes
public static String getExtensionByMagicBytes(File file)
Retrieves the file's extension by magic byte detection.- Parameters:
file
- the file to check- Throws:
IllegalArgumentException
- if there is any issue reading the file
-
-