- java.lang.Object
-
- javax.activation.FileTypeMap
-
- javax.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 <java.home>
/lib/mime.types
. - 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).
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"
- Since:
- 1.6
-
-
Constructor Summary
Constructors Constructor and Description MimetypesFileTypeMap()
The default constructor.MimetypesFileTypeMap(InputStream is)
Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.MimetypesFileTypeMap(String mimeTypeFileName)
Construct a MimetypesFileTypeMap with programmatic entries added from the named file.
-
Method Summary
Methods Modifier and Type Method and Description 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.String
getContentType(String filename)
Return the MIME type based on the specified file name.-
Methods inherited from class javax.activation.FileTypeMap
getDefaultFileTypeMap, setDefaultFileTypeMap
-
-
-
-
Constructor Detail
-
MimetypesFileTypeMap
public MimetypesFileTypeMap()
The default constructor.
-
MimetypesFileTypeMap
public MimetypesFileTypeMap(String mimeTypeFileName) throws IOException
Construct a MimetypesFileTypeMap with programmatic entries added from the named file.- Parameters:
mimeTypeFileName
- the file name- Throws:
IOException
-
MimetypesFileTypeMap
public MimetypesFileTypeMap(InputStream is)
Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.- Parameters:
is
- the input stream to read from
-
-
Method Detail
-
addMimeTypes
public void addMimeTypes(String mime_types)
Prepend the MIME type values to the registry.- Parameters:
mime_types
- A .mime.types formatted string of entries.
-
getContentType
public String getContentType(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 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.- Specified by:
getContentType
in classFileTypeMap
- Parameters:
filename
- the file name- Returns:
- the file's MIME type
-
-
Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-javax/activation/MimetypesFileTypeMap.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.