public class

MimetypesFileTypeMap

extends FileTypeMap
java.lang.Object
   ↳ com.google.code.javax.activation.FileTypeMap
     ↳ com.google.code.javax.activation.MimetypesFileTypeMap

Class Overview

This class extends FileTypeMap and provides data typing of files via their file extension. It uses the .mime.types format.

MIME types file search order:

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:

  1. Programmatically added entries to the MimetypesFileTypeMap instance.
  2. The file .mime.types in the user's home directory.
  3. The file <java.home>/lib/mime.types.
  4. The file or resources named META-INF/mime.types.
  5. The file or resource named META-INF/mimetypes.default (usually found only in the activation.jar file).

MIME types file format:

# comments begin with a '#'
# the format is <mime type> <space separated file extensions>
# for example:
text/plain txt text TXT
# this would map file.txt, file.text, and file.TXT to
# the mime type "text/plain"

Summary

Constants
int PROG
Fields
private MimeTypeFile[] DB
private static MimeTypeFile defDB
private static String defaultType
[Expand]
Inherited Fields
From class com.google.code.javax.activation.FileTypeMap
Public Constructors
MimetypesFileTypeMap()
The default constructor.
MimetypesFileTypeMap(String mimeTypeFileName)
Construct a MimetypesFileTypeMap with programmatic entries added from the named file.
MimetypesFileTypeMap(InputStream is)
Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.
Public Methods
synchronized void addMimeTypes(String mime_types)
Prepend the MIME type values to the registry.
String getContentType(File f)
Return the MIME type of the file object.
synchronized String getContentType(String filename)
Return the MIME type based on the specified file name.
[Expand]
Inherited Methods
From class com.google.code.javax.activation.FileTypeMap
From class java.lang.Object

Constants

private static final int PROG

Constant Value: 0 (0x00000000)

Fields

private MimeTypeFile[] DB

private static MimeTypeFile defDB

private static String defaultType

Public Constructors

public MimetypesFileTypeMap ()

The default constructor.

public MimetypesFileTypeMap (String mimeTypeFileName)

Construct a MimetypesFileTypeMap with programmatic entries added from the named file.

Parameters
mimeTypeFileName The file name
Throws
IOException

public MimetypesFileTypeMap (InputStream is)

Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.

Parameters
is The input stream to read from

Public Methods

public synchronized void addMimeTypes (String mime_types)

Prepend the MIME type values to the registry.

Parameters
mime_types A .mime.types formatted string of entries.

public String getContentType (File f)

Return the MIME type of the file object. The implementation in this class calls getContentType(f.getName()).

Parameters
f The file
Returns
  • the file's MIME type

public synchronized String getContentType (String filename)

Return the MIME type based on the specified file name. The MIME type entries are searched as described above under MIME types file search order. If no entry is found, the type "application/octet-stream" is returned.

Parameters
filename The file name
Returns
  • the file's MIME type