pvillega’s posterous

pvillega’s posterous

Pere Villega  //  Born in Barcelona, living in Dublin, and tagged as geek since youth. Developer in the path to becoming a software architect. I swear this is not a proper blog :)

Feb 16 / 6:51am

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

.

Loading mentions Retweet

Filed under // java magic numbers mime

Comments (0)