MimetypesFileTypeMap (Java EE 5 SDK)

Java

Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


javax.activation Class MimetypesFileTypeMap

java.lang.Object
  extended by javax.activation.FileTypeMap
      extended by 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:

  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"

作者:
Bart Calder, Bill Shannon

构造器摘要
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.
 
方法摘要
 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.
 
类方法继承 javax.activation.FileTypeMap
getDefaultFileTypeMap, setDefaultFileTypeMap
 
类方法继承 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造器详细信息

MimetypesFileTypeMap

public MimetypesFileTypeMap()
The default constructor.


MimetypesFileTypeMap

public MimetypesFileTypeMap(String mimeTypeFileName)
                     throws IOException
Construct a MimetypesFileTypeMap with programmatic entries added from the named file.

参数:
mimeTypeFileName - the file name
抛出异常:
IOException


MimetypesFileTypeMap

public MimetypesFileTypeMap(InputStream is)
Construct a MimetypesFileTypeMap with programmatic entries added from the InputStream.

参数:
is - the input stream to read from

方法详细信息

addMimeTypes

public void addMimeTypes(String mime_types)
Prepend the MIME type values to the registry.

参数:
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 calls getContentType(f.getName()).

规范说明:
getContentType in class FileTypeMap
参数:
f - the file
返回:
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.

规范说明:
getContentType in class FileTypeMap
参数:
filename - the file name
返回:
the file's MIME type

Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


提交错误或意见

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。深圳电信培训中心.徐海蛟老师教学参考.