|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.activation Class MimetypesFileTypeMap
java.lang.Object javax.activation.FileTypeMap javax.activation.MimetypesFileTypeMap
public class MimetypesFileTypeMap
- extends FileTypeMap
此类扩展 FileTypeMap 并通过其文件扩展名提供文件的数据分类。它使用
.mime.types
格式。 MIME 类型文件搜索顺序:
MimetypesFileTypeMap 在用户系统的不同位置查找 MIME 类型文件条目。当发出在 MimetypesFileTypeMap 中搜索 MIME 类型的请求时,它将按以下顺序搜索 MIME 类型文件:
- 以编程方式添加到 MimetypesFileTypeMap 实例的条目。
- 用户主目录中的
.mime.types
文件。 - <java.home>
/lib/mime.types
文件。 - 名为
META-INF/mime.types
的文件或资源。 - 名为
META-INF/mimetypes.default
的文件或资源(通常只存在于activation.jar
文件中)。
MIME 类型文件格式:
# 注释以 '#' 开头
# 格式是 <mime 类型> <以空格分隔文件扩展名>
# 例如:
text/plain txt text TXT
# 这将 file.txt、file.text 和 file.TXT 映射到
# mime 类型 "text/plain"
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"
- Author:
- Bart Calder, Bill Shannon
Constructor Summary | |
---|---|
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 | |
---|---|
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public
MimetypesFileTypeMap()
默认的构造方法。
英文文档:
MimetypesFileTypeMap
public MimetypesFileTypeMap()
- The default constructor.
public
MimetypesFileTypeMap(String mimeTypeFileName) throws java.io.IOException
用从指定文件中添加的编程条目构造 MimetypesFileTypeMap。
mimeTypeFileName | 文件名 |
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
public
MimetypesFileTypeMap(java.io.InputStream is)
用从 InputStream 中添加的编程条目构造 MimetypesFileTypeMap。
is | 要从中读取的输入流 |
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 |
---|
public void
addMimeTypes(String mime_types)
将 MIME 类型值预先添加到注册表。
mime_types | 条目的 .mime. 类型格式化字符串。 |
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.
public String
getContentType(java.io.File f)
返回该文件对象的 MIME 类型。此类中的实现调用 getContentType(f.getName())
。
f | 文件 |
return | 文件的 MIME 类型 |
getContentType
public String getContentType(File f)
- Return the MIME type of the file object.
The implementation in this class calls
getContentType(f.getName())
. - Specified by:
getContentType
in classFileTypeMap
- Parameters:
f
- the file- Returns:
- the file's MIME type
public String
getContentType(String filename)
返回基于指定文件名的 MIME 类型。以如上所述的 MIME 类型文件搜索顺序 来搜索 MIME 类型条目。如果找不到任何条目,则返回 "application/octet-stream" 类型。
filename | 文件名 |
return | 文件的 MIME 类型 |
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!