|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object eu.medsea.mimeutil.detector.MimeDetector eu.medsea.mimeutil.detector.ExtensionMimeDetector
public class ExtensionMimeDetector
The extension mime mappings are loaded in the following way.
eu.medsea.mimeutil.mime-types.properties
..mime-types.properties
from the
users home directory if one exists.mime-types.properties
from the
classpath if one existsmime-mappings
i.e.
-Dmime-mappings=../my-mime-types.properties
Fortunately, we have compiled a relatively large list of mappings into a java properties file from information gleaned from many sites on the Internet. This file resides in the eu.medsea.util.mime-types.properties file and is not guaranteed to be correct or contain all the known mappings for a file extension type. This is not a complete or exhaustive list as that would have proven too difficult to compile for this project. So instead we give you the opportunity to extend and override these mappings for yourself as defined above. Obviously, to use this method you don't actually need a file object, you just need a file name with an extension. Also, if you have given or renamed a file using a different extension than the one that it would normally be associated with then this mapping will return the wrong mime-type and if the file has no extension at all, such as Make, then it's not going to be possible to determine a mime type using this technique
We acquired many mappings from many different sources on the net for the extension mappings. The internal list is quite large and there can be many associated mime types. These may not match what you are expecting so you can add the mapping you want to change to your own property file following the rules above. If you provide a mapping for an extension then any previously loaded mappings will be removed and only the mappings you define will be returned. This can be used to map certain extensions that are incorrectly returned for our environment defined in the internal property file.
If we have not provided a mapping for a file extension that you know the mime type for you can add this to your custom property files so that a correct mime type is returned for you.
We use the application/directory
mime type to identify
directories. Even though this is not an official mime type it seems to be
well accepted on the net as an unofficial mime type so we thought it was OK
for us to use as well.
This class is auto loaded by MimeUtil as it has an entry in the file called MimeDetectors. MimeUtil reads this file at startup and calls Class.forName() on each entry found. This mean the MimeDetector must have a no arg constructor.
Constructor Summary | |
---|---|
ExtensionMimeDetector()
|
Method Summary | |
---|---|
String |
getDescription()
Abstract method to be implement by concrete MimeDetector(s). |
Collection |
getMimeTypesByteArray(byte[] data)
This method is required by the abstract MimeDetector class. |
Collection |
getMimeTypesFile(File file)
Get the mime type of a file using extension mappings. |
Collection |
getMimeTypesFileName(String fileName)
Get the mime type of a file name using file name extension mappings. |
Collection |
getMimeTypesInputStream(InputStream in)
This method is required by the abstract MimeDetector class. |
Collection |
getMimeTypesURL(URL url)
Get the mime type of a URL using extension mappings. |
Methods inherited from class eu.medsea.mimeutil.detector.MimeDetector |
---|
closeStream, delete, getMimeTypes, getMimeTypes, getMimeTypes, getMimeTypes, getMimeTypes, getName, init |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ExtensionMimeDetector()
Method Detail |
---|
public String getDescription()
MimeDetector
getDescription
in class MimeDetector
public Collection getMimeTypesFile(File file) throws MimeException
getMimeTypesFile
in class MimeDetector
file
- points to a file or directory. May not actually exist
MimeException
- if errors occur.public Collection getMimeTypesURL(URL url) throws MimeException
getMimeTypesURL
in class MimeDetector
url
- is a valid URL
MimeException
- if errors occur.public Collection getMimeTypesFileName(String fileName) throws MimeException
getMimeTypesFileName
in class MimeDetector
fileName
- points to a file or directory. May not actually exist
MimeException
- if errors occur.public Collection getMimeTypesInputStream(InputStream in) throws UnsupportedOperationException
UnsupportedOperationException
. This ensures that the getMimeTypes(...) methods ignore this
method. We could also have just returned an empty collection.
getMimeTypesInputStream
in class MimeDetector
in
- InputStream.
UnsupportedOperationException
public Collection getMimeTypesByteArray(byte[] data) throws UnsupportedOperationException
UnsupportedOperationException
. This ensures that the getMimeTypes(...) methods ignore this
method. We could also have just returned an empty collection.
getMimeTypesByteArray
in class MimeDetector
data
- byte []. Is a byte array that you want to parse for matching mime types.
UnsupportedOperationException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |