public class Mimetypes extends Object
This class is obtained with the {#link getInstance()
method that
recognizes loaded mime types from the file mime.types
if 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
. 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 String |
MIMETYPE_GZIP
The default gzip mimetype: application/x-gzip
|
static String |
MIMETYPE_HTML
The default HTML mimetype: text/html
|
static String |
MIMETYPE_OCTET_STREAM
The default binary mimetype: application/octet-stream
|
static String |
MIMETYPE_XML
The default XML mimetype: application/xml
|
限定符和类型 | 方法和说明 |
---|---|
static Mimetypes |
getInstance()
Loads MIME type info from the file 'mime.types' in the classpath, if it's available.
|
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.
|
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.
|
void |
loadAndReplaceMimetypes(InputStream is)
Reads and stores the mime type setting corresponding to a file extension, by reading
text from an InputStream.
|
public static final String MIMETYPE_XML
public static final String MIMETYPE_HTML
public static final String MIMETYPE_OCTET_STREAM
public static Mimetypes getInstance()
public void loadAndReplaceMimetypes(InputStream is) throws IOException
is
- IOException
public String getMimetype(String fileName)
application/octet-stream
is 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.application/octet-stream
if a mime type value cannot
be found.public String getMimetype(File file)
application/octet-stream
is 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.application/octet-stream
if a mime type value cannot be found.Copyright © 2016. All rights reserved.