/** * Returns the Media Type for the given file. * * <p>The media type is only based on the file extension. * * <p>This method uses the the 'mime.properties' resource file from the classpath which maps * file extensions to the corresponding Media Type. This file is loaded once. * * @see <a href="http://tools.ietf.org/html/rfc2046">MIME Part Two: Media Types</a> * @see <a href="http://tools.ietf.org/html/rfc3023">XML Media Types</a> * * @param f The file. * @return the corresponding Media Type or <code>null</code> if not found. */ public static @Nullable String getMediaType(File f) { // Load if empty if (MEDIATYPES.isEmpty()) { loadMIMEProperties(); } // Lookup extension in properties file String name = f.getName(); int dot = name.lastIndexOf("."); if (dot >= 0) return MEDIATYPES.getProperty(name.substring(dot+1)); else return null; }