public final class Mimetypes
extends java.lang.Object
This class is obtained with the {#link getInstance()
method. It has
a default extension to mimetype mapping which is taken from the Apache HTTP
server's mime.types file. New mappings can be added or overwritten by
registerMimetype(String, String)
.
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.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MIMETYPE_GZIP
The default gzip mimetype: application/x-gzip
|
static java.lang.String |
MIMETYPE_HTML
The default HTML mimetype: text/html
|
static java.lang.String |
MIMETYPE_OCTET_STREAM
The default binary mimetype: application/octet-stream
|
static java.lang.String |
MIMETYPE_XML
The default XML mimetype: application/xml
|
Modifier and Type | Method and Description |
---|---|
static Mimetypes |
getInstance()
Gets an instance of
Mimetypes with default mime type info. |
java.lang.String |
getMimetype(java.io.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.
|
java.lang.String |
getMimetype(java.lang.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(java.io.InputStream is)
Reads and stores the mime type setting corresponding to a file extension,
by reading text from an InputStream.
|
void |
registerMimetype(java.lang.String extension,
java.lang.String mimetype)
Register a new mimetype for the given extension.
|
public static final java.lang.String MIMETYPE_XML
public static final java.lang.String MIMETYPE_HTML
public static final java.lang.String MIMETYPE_OCTET_STREAM
public static final java.lang.String MIMETYPE_GZIP
public static Mimetypes getInstance()
Mimetypes
with default mime type info. You
can load more via loadAndReplaceMimetypes(InputStream)
.
For more information about Internet media types, please read RFC 2045, 2046, 2047, 2048, and 2077. The Internet media type registry is at http://www.iana.org/assignments/media-types/
Mimetypes
public void loadAndReplaceMimetypes(java.io.InputStream is) throws java.io.IOException
is
- the input stream.java.io.IOException
public java.lang.String getMimetype(java.lang.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 an 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 java.lang.String getMimetype(java.io.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.public void registerMimetype(java.lang.String extension, java.lang.String mimetype)
extension
- a file extensionmimetype
- mime type stringCopyright © 2018 Amazon Web Services, Inc. All Rights Reserved.