com.openexchange.mail.mime
Class MIMEType2ExtMap

java.lang.Object
  extended by com.openexchange.mail.mime.MIMEType2ExtMap

public final class MIMEType2ExtMap
extends java.lang.Object

MIMEType2ExtMap - Maps MIME types to file extensions and vice versa.

This class looks in various places for MIME types file entries. When requests are made to look up MIME types or file extensions, it searches MIME types files in the following order:

  1. The file .mime.types in the user's home directory.
  2. The file <java.home>/lib/mime.types.
  3. The file or resources named META-INF/mime.types.
  4. The file or resource named META-INF/mimetypes.default.
  5. The file or resource denoted by property MimeTypeFile.

Author:
Thorben Betten

Method Summary
static java.lang.String getContentType(java.io.File file)
          Gets the MIME type associated with given file.
static java.lang.String getContentType(java.lang.String fileName)
          Gets the MIME type associated with given file name.
static java.lang.String getContentTypeByExtension(java.lang.String extension)
          Gets the MIME type associated with given file extension.
static java.util.List<java.lang.String> getFileExtensions(java.lang.String mimeType)
          Gets the file extension for given MIME type.
static void init()
          Initializes MIME type file map.
static void load(java.io.File file)
          Loads the MIME type file specified through given file.
static void load(java.lang.String fileStr)
          Loads the MIME type file specified through fileStr.
static void reset()
          Resets MIME type file map.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

reset

public static void reset()
Resets MIME type file map.


init

public static void init()
Initializes MIME type file map.


getContentType

public static java.lang.String getContentType(java.io.File file)
Gets the MIME type associated with given file.

Parameters:
file - The file
Returns:
The MIME type associated with given file or application/octet-stream if none found

getContentType

public static java.lang.String getContentType(java.lang.String fileName)
Gets the MIME type associated with given file name.

Parameters:
fileName - The file name; e.g. "file.html"
Returns:
The MIME type associated with given file name or application/octet-stream if none found

getContentTypeByExtension

public static java.lang.String getContentTypeByExtension(java.lang.String extension)
Gets the MIME type associated with given file extension.

Parameters:
extension - The file extension; e.g. "txt"
Returns:
The MIME type associated with given file extension or application/octet-stream if none found

getFileExtensions

public static java.util.List<java.lang.String> getFileExtensions(java.lang.String mimeType)
Gets the file extension for given MIME type.

Parameters:
mimeType - The MIME type
Returns:
The file extension for given MIME type or dat if none found

load

public static void load(java.lang.String fileStr)
Loads the MIME type file specified through fileStr.

Parameters:
fileStr - The MIME type file to load

load

public static void load(java.io.File file)
Loads the MIME type file specified through given file.

Parameters:
file - The MIME type file to load