|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecteu.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.propertiesFortunately, 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 file extension mappings. |
Collection |
getMimeTypesInputStream(InputStream in)
This method is required by the abstract MimeDetector class. |
| Methods inherited from class eu.medsea.mimeutil.detector.MimeDetector |
|---|
addMimeHandler, getMimeHandlers, getMimeTypes, getMimeTypes, getMimeTypes, getMimeTypes, getMimeTypes, getName, removeMimeHandler |
| 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 MimeDetectorfile - is a File object that points to a file or
directory.
MimeException - if the file cannot be parsed.
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 MimeDetectorin - InputStream. If the InputStream does not support the mark() and reset() methods it will throw an exception.
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 MimeDetectordata - 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 | |||||||||