The MimeUtil2
is a utility class that allows applications to detect, work with and manipulate MIME types.
A MIME or "Multipurpose Internet Mail Extension" type is an Internet standard that is important outside of just e-mail use. MIME is used extensively in other communications protocols such as HTTP for web communications. IANA "Internet Assigned Numbers Authority" is responsible for the standardisation and publication of MIME types. Basically any resource on any computer that can be located via a URL can be assigned a MIME type. So for instance, JPEG images have a MIME type of image/jpg. Some resources can have multiple MIME types associated with them such as files with an XML extension have the MIME types text/xml and application/xml and even specialised versions of xml such as image/svg+xml for SVG image files.
To do this MimeUtil2
uses registered MimeDetector
(s) that are delegated too in sequence to actually perform the detection. There are several MimeDetector
implementations that come with the utility and you can register and unregister them to perform detection based on file extensions, file globing and magic number detection.
Their is also a fourth MimeDetector that is registered by default that detects text files and encodings. Unlike the other MimeDetector(s) or any MimeDetector(s) you may choose to implement, the TextMimeDetector cannot be registered or unregistered by your code. It is advisable that you read the java doc for the TextMimeDetector as it can be modified in several ways to make it perform better and or detect more specific types.
Please refer to the java doc for each of these MimeDetector
(s) for a description of how they actually perform their particular detection process.
It is important to note that MIME matching is not an exact science, meaning that a positive match does not guarantee that the returned MIME type is actually correct. It is a best guess method of matching and the matched MIME types should be used with this in mind.
New MimeDetector
(s) can easily be created and registered with MimeUtil2
to extend it's functionality beyond these initial detection strategies by extending the AbstractMimeDetector
class. To see how to implement your own MimeDetector
take a look at the java doc and source code for the {@link ExtensionMimeDetector}, {@link MagicMimeMimeDetector} and{@link OpendesktopMimeDetector} classes. To register and unregister MimeDetector(s) use the[un]registerMimeDetector(...) methods of this class.
The order that the MimeDetector
(s) are executed is defined by the order each MimeDetector
is registered.
The resulting Collection
of mime types returned in response to a getMimeTypes(...) call is a normalised list of the accumulation of MIME types returned by each of the registered MimeDetector
(s) that implement the specified getMimeTypesXXX(...) methods.
All methods in this class that return a Collection object containing MimeType(s) actually return a {@link MimeTypeHashSet}that implements both the {@link Set} and {@link Collection} interfaces.
@author Steven McArdle. @since 2.1
|
|
|
|
|
|
|
|
|
|
|
|