- java.lang.Object
-
- jakarta.activation.FileTypeMap
-
- jakarta.activation.MimetypesFileTypeMap
-
public class MimetypesFileTypeMap extends FileTypeMap
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:
- Programmatically added entries to the MimetypesFileTypeMap instance.
- The file
.mime.types
in the user's home directory. - The file
mime.types
in the Java runtime. - The file or resources named
META-INF/mime.types
. - The file or resource named
META-INF/mimetypes.default
(usually found only in theactivation.jar
file).
(The current implementation looks for the
mime.types
file in the Java runtime in the directoryjava.home/conf
if it exists, and otherwise in the directoryjava.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"
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
confDir
private MimeTypeRegistry[]
DB
private static java.lang.String
defaultType
private static int
PROG
-
Constructor Summary
Constructors Constructor Description MimetypesFileTypeMap()
The default constructor.MimetypesFileTypeMap(java.io.InputStream is)
Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.MimetypesFileTypeMap(java.lang.String mimeTypeFileName)
Construct a MimetypesFileTypeMap with programmatic entries added from the named file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMimeTypes(java.lang.String mime_types)
Prepend the MIME type values to the registry.java.lang.String
getContentType(java.io.File f)
Return the MIME type of the file object.java.lang.String
getContentType(java.lang.String filename)
Return the MIME type based on the specified file name.private MimeTypeRegistryProvider
getImplementation()
private void
loadAllResources(java.util.Vector<MimeTypeRegistry> v, java.lang.String name)
Load all of the named resource.private MimeTypeRegistry
loadFile(java.lang.String name)
Load the named file.private MimeTypeRegistry
loadResource(java.lang.String name)
Load from the named resource.-
Methods inherited from class jakarta.activation.FileTypeMap
getDefaultFileTypeMap, setDefaultFileTypeMap
-
-
-
-
Field Detail
-
DB
private MimeTypeRegistry[] DB
-
PROG
private static final int PROG
- See Also:
- Constant Field Values
-
defaultType
private static final java.lang.String defaultType
- See Also:
- Constant Field Values
-
confDir
private static final java.lang.String confDir
-
-
Constructor Detail
-
MimetypesFileTypeMap
public MimetypesFileTypeMap()
The default constructor.
-
MimetypesFileTypeMap
public MimetypesFileTypeMap(java.lang.String mimeTypeFileName) throws java.io.IOException
Construct a MimetypesFileTypeMap with programmatic entries added from the named file.- Parameters:
mimeTypeFileName
- the file name- Throws:
java.io.IOException
- for errors reading the file
-
MimetypesFileTypeMap
public MimetypesFileTypeMap(java.io.InputStream is)
Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.- Parameters:
is
- the input stream to read from
-
-
Method Detail
-
loadResource
private MimeTypeRegistry loadResource(java.lang.String name)
Load from the named resource.
-
loadAllResources
private void loadAllResources(java.util.Vector<MimeTypeRegistry> v, java.lang.String name)
Load all of the named resource.
-
loadFile
private MimeTypeRegistry loadFile(java.lang.String name)
Load the named file.
-
addMimeTypes
public void addMimeTypes(java.lang.String mime_types)
Prepend the MIME type values to the registry.- Parameters:
mime_types
- A .mime.types formatted string of entries.
-
getContentType
public java.lang.String getContentType(java.io.File f)
Return the MIME type of the file object. The implementation in this class callsgetContentType(f.getName())
.- Specified by:
getContentType
in classFileTypeMap
- Parameters:
f
- the file- Returns:
- the file's MIME type
-
getContentType
public java.lang.String getContentType(java.lang.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.- Specified by:
getContentType
in classFileTypeMap
- Parameters:
filename
- the file name- Returns:
- the file's MIME type
-
getImplementation
private MimeTypeRegistryProvider getImplementation()
-
-