Java – how do I detect if the MIME type is an executable?
I am using Apache Tika to detect the MIME type of the input stream
http://www.file-extensions.org/filetype/extension/name/program-executable-files
I want to know the best way to cover them up Please give me some advice. Thank you
Solution
Apache Tika's MIME type has a hierarchy Therefore, instead of checking all possible executable types, you need to check whether the detected type has a parent, which is one of the few executable types
For windows, the main is application / x-msdownload You may also want to check the application / x-ms-installer
For UNIX, the main is application / x-elf, but you may also want to check the script format, such as application / x-sh, text / x-perl, text / x-python, etc
As for how to transfer from mimeType in Tika to its parent, you need this existing answer here – "correct use of Apache Tika mediatype" (note that if there are multiple levels between the detected MIME type and the basic executable parent type, recursion is required)