类 Mimetypes
- java.lang.Object
-
- com.baidubce.util.Mimetypes
-
public class Mimetypes extends Object
Utility class that maintains a listing of known Mimetypes, and determines the mimetype of files based on file extensions.This class is obtained with the {#link
getInstance()method that recognizes loaded mime types from the filemime.typesif this file is available at the root of the classpath. The mime.types file format, and most of the content, is taken from the Apache HTTP server's mime.types file.The format for mime type setting documents is:
mimetype <Space | Tab>+ extension (<Space|Tab>+ extension)*. Any blank lines in the file are ignored, as are lines starting with#which are considered comments. Lines that have a mimetype but no associated extensions are also ignored.
-
-
字段概要
字段 修饰符和类型 字段 说明 static StringMIMETYPE_OCTET_STREAMThe default binary mimetype: application/octet-stream
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 static MimetypesgetInstance()Loads MIME type info from the file 'mime.types' in the classpath, if it's available.StringgetMimetype(File file)Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type.StringgetMimetype(String fileName)Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type.voidloadAndReplaceMimetypes(InputStream is)Reads and stores the mime type setting corresponding to a file extension, by reading text from an InputStream.
-
-
-
方法详细资料
-
getInstance
public static Mimetypes getInstance()
Loads MIME type info from the file 'mime.types' in the classpath, if it's available.
-
loadAndReplaceMimetypes
public void loadAndReplaceMimetypes(InputStream is) throws IOException
Reads and stores the mime type setting corresponding to a file extension, by reading text from an InputStream. If a mime type setting already exists when this method is run, the mime type value is replaced with the newer one.- 参数:
is-- 抛出:
IOException
-
getMimetype
public String getMimetype(String fileName)
Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type. If the file has no extension, or the extension is not available in the listing contained in this class, the default mimetypeapplication/octet-streamis returned.A file extension is one or more characters that occur after the last period (.) in the file's name. If a file has no extension, Guesses the mimetype of file data based on the file's extension.
- 参数:
fileName- The name of the file whose extension may match a known mimetype.- 返回:
- The file's mimetype based on its extension, or a default value of
application/octet-streamif a mime type value cannot be found.
-
getMimetype
public String getMimetype(File file)
Determines the mimetype of a file by looking up the file's extension in an internal listing to find the corresponding mime type. If the file has no extension, or the extension is not available in the listing contained in this class, the default mimetypeapplication/octet-streamis returned.A file extension is one or more characters that occur after the last period (.) in the file's name. If a file has no extension, Guesses the mimetype of file data based on the file's extension.
- 参数:
file- the file whose extension may match a known mimetype.- 返回:
- the file's mimetype based on its extension, or a default value of
application/octet-streamif a mime type value cannot be found.
-
-