Top Description Fields Constructors Methods
jakarta.activation

public Class MimetypesFileTypeMap

extends FileTypeMap
Class Inheritance
Imports
jakarta.activation.spi.MimeTypeRegistryProvider, java.io.*, java.net.*, java.util.*, java.security.AccessController, .PrivilegedAction

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 mime.types in the Java runtime.
  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).

(The current implementation looks for the mime.types file in the Java runtime in the directory java.home/conf if it exists, and otherwise in the directory java.home/lib, where java.home is the value of the "java.home" System property. Note that the "conf" directory was introduced in JDK 9.)

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"

Authors
Bart Calder, Bill Shannon

Field Summary

Modifier and TypeField and Description
private static final String
private MimeTypeRegistry[]
private static final String
private static final int

Constructor Summary

AccessConstructor and Description
public
MimetypesFileTypeMap()

The default constructor.

public
MimetypesFileTypeMap(String
the file name
mimeTypeFileName
)

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

public
MimetypesFileTypeMap(InputStream
the input stream to read from
is
)

Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addMimeTypes(String
A .mime.types formatted string of entries.
mime_types
)

Prepend the MIME type values to the registry.

public String

Returns:

the file's MIME type
getContentType
(File
the file
f
)

Implements abstract jakarta.activation.FileTypeMap.getContentType.

Return the MIME type of the file object.
public synchronized String

Returns:

the file's MIME type
getContentType
(String
the file name
filename
)

Implements abstract jakarta.activation.FileTypeMap.getContentType.

Return the MIME type based on the specified file name.
private MimeTypeRegistryProvider
private void
loadAllResources(Vector<MimeTypeRegistry> v, String name)

Load all of the named resource.

private MimeTypeRegistry
loadFile(String name)

Load the named file.

private MimeTypeRegistry
loadResource(String name)

Load from the named resource.

Inherited from jakarta.activation.FileTypeMap:
getDefaultFileTypeMapsetDefaultFileTypeMap

Field Detail

confDirback to summary
private static final String confDir
DBback to summary
private MimeTypeRegistry[] DB
defaultTypeback to summary
private static final String defaultType
PROGback to summary
private static final int PROG

Constructor Detail

MimetypesFileTypeMapback to summary
public MimetypesFileTypeMap()

The default constructor.

MimetypesFileTypeMapback to summary
public MimetypesFileTypeMap(String mimeTypeFileName) throws IOException

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

Parameters
mimeTypeFileName:String

the file name

Exceptions
IOException:
for errors reading the file
MimetypesFileTypeMapback to summary
public MimetypesFileTypeMap(InputStream is)

Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.

Parameters
is:InputStream

the input stream to read from

Method Detail

addMimeTypesback to summary
public synchronized void addMimeTypes(String mime_types)

Prepend the MIME type values to the registry.

Parameters
mime_types:String

A .mime.types formatted string of entries.

getContentTypeback to summary
public String getContentType(File f)

Implements abstract jakarta.activation.FileTypeMap.getContentType.

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

Parameters
f:File

the file

Returns:String

the file's MIME type

getContentTypeback to summary
public synchronized String getContentType(String filename)

Implements abstract jakarta.activation.FileTypeMap.getContentType.

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:String

the file name

Returns:String

the file's MIME type

getImplementationback to summary
private MimeTypeRegistryProvider getImplementation()
loadAllResourcesback to summary
private void loadAllResources(Vector<MimeTypeRegistry> v, String name)

Load all of the named resource.

loadFileback to summary
private MimeTypeRegistry loadFile(String name)

Load the named file.

loadResourceback to summary
private MimeTypeRegistry loadResource(String name)

Load from the named resource.