The MimetypesFileMap class is used to map a File to a Mime Type. Mime types supported are defined in a ressource file inside the activation.jar.
import javax.activation.MimetypesFileTypeMap;
import java.io.File;
class GetMimeType {
public static void main(String args[]) {
File f = new File("gumby.gif");
System.out.println("Mime Type of " + f.getName() + " is " +
new MimetypesFileTypeMap().getContentType(f));
// expected output :
// "Mime Type of gumby.gif is image/gif"
}
}The MimetypesFileTypeMap looks in various places in the user's system for MIME types file entries. When requests are made to search for MIME types in the MimetypesFileTypeMap, it searches MIME types files in the following order:
Like the above method a match is done with the extension. The mapping between the extension and the mime-type is defined in the file [jre_home]\lib\content-types.properties
import java.net.*;
public class FileUtils{
public static String getMimeType(String fileUrl)
throws java.io.IOException, MalformedURLException
{
String type = null;
URL u = new URL(fileUrl);
URLConnection uc = null;
uc = u.openConnection();
type = uc.getContentType();
return type;
}
public static void main(String args[]) throws Exception {
System.out.println(FileUtils.getMimeType("file://c:/temp/test.TXT"));
// output : text/plain
}
}
// snippet for JMimeMagic lib
// http://sourceforge.net/projects/jmimemagic/
Magic parser = new Magic() ;
// getMagicMatch accepts Files or byte[],
// which is nice if you want to test streams
MagicMatch match = parser.getMagicMatch(new File("gumby.gif"));
System.out.println(match.getMimeType()) ;
// snippet for mime-util lib // http://sourceforge.net/projects/mime-util public static final String UNKNOWN_MIME_TYPE="application/x-unknown-mime-type"; ... String mimeType = MimeUtil.getMagicMimeType(file); if(mimeType == null) mimeType = UNKNOWN_MIME_TYPE;
DROID uses internal and external signatures to identify and report the specific file format versions of digital files. These signatures are stored in an XML signature file, generated from information recorded in the PRONOM technical registry. New and updated signatures are regularly added to PRONOM, and DROID can be configured to automatically download updated signature files from the PRONOM website via web services.
It can be invoked from two interfaces, a Java Swing GUI or a command line interface.
http://droid.sourceforge.net/wiki/index.php/Introduction
The Aperture code consists of a number of related but independently usable parts:
http://aperture.wiki.sourceforge.net/Overview
Written and compiled by Réal Gagnon ©1998-2007
[ home ]