Mime Type Detection
Mime-Util is a library for Java that allows you to identify the Mime type of files, byte arrays and other sources. It's based on the magic numbers used by Unix utility program file(1). Is OSGi compatible and a light component that won't impact negatively the performance of your application. The usage is as simple as registering one of the available MimeDetectors and passing to it the object to identify:
// Register the MagicMimeMimeDetector. MimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector"); File f = new File("path/to/a/real/file/myfile.xyz.tar.gz"); System.out.println("MIME types = [" + MimeUtil.getMimeTypes(f) + "]");
You have more documentation here, the javadoc is available here
.