Class OpendesktopMimeDetector
- java.lang.Object
-
- eu.medsea.mimeutil.detector.MimeDetector
-
- eu.medsea.mimeutil.detector.OpendesktopMimeDetector
-
public class OpendesktopMimeDetector extends MimeDetector
The Opendesktop shared mime database contains glob rules and magic number lookup information to enable applications to detect the mime types of files.
This class uses the mime.cache file which is one of the files created by the update-mime-database application. This file is a memory mapped file that enables the database to be updated and copied without interrupting applications.
This implementation follows the memory mapped spec so it is not required to restart an application using this mime detector should the underlying mime.cache database change.
For a complete description of the information contained in this file please see: http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info- spec-latest.html
This class also follows, where possible, the RECOMENDED order of detection as detailed in this spec. Thanks go to Mathias Clasen at Red Hat for pointing me to the original xdgmime implementation http://svn.gnome.org/viewvc/glib/trunk/ gio/xdgmime/xdgmimecache.c?revision=7784&view=markup
-
-
Constructor Summary
Constructors Constructor Description OpendesktopMimeDetector()OpendesktopMimeDetector(java.lang.String mimeCacheFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()You can override this method if for instance you allocated any resources in the init() method that need to be closed or deallocated specially.java.lang.Stringdump()java.lang.StringgetDescription()Abstract method to be implement by concrete MimeDetector(s).java.util.CollectiongetMimeTypesByteArray(byte[] data)This method is unable to perform glob matching as no name is available.java.util.CollectiongetMimeTypesFile(java.io.File file)This method resolves mime types closely in accordance with the RECOMENDED order of detection detailed in the Opendesktop shared mime database specification http://standards.freedesktop.org/shared-mime-info-spec/shared -mime-info-spec-latest.html See the Recommended checking order.java.util.CollectiongetMimeTypesFileName(java.lang.String fileName)This method resolves mime types closely in accordance with the RECOMENDED order of detection detailed in the Opendesktop shared mime database specification http://standards.freedesktop.org/shared-mime-info-spec/shared -mime-info-spec-latest.html See the Recommended checking order.java.util.CollectiongetMimeTypesInputStream(java.io.InputStream in)This method is unable to perform glob matching as no name is available.java.util.CollectiongetMimeTypesURL(java.net.URL url)This method resolves mime types closely in accordance with the RECOMENDED order of detection detailed in the Opendesktop shared mime database specification http://standards.freedesktop.org/shared-mime-info-spec/shared -mime-info-spec-latest.html See the Recommended checking order.-
Methods inherited from class eu.medsea.mimeutil.detector.MimeDetector
closeStream, getMimeTypes, getMimeTypes, getMimeTypes, getMimeTypes, getMimeTypes, getName, init
-
-
-
-
Method Detail
-
delete
public void delete()
Description copied from class:MimeDetectorYou can override this method if for instance you allocated any resources in the init() method that need to be closed or deallocated specially.- Overrides:
deletein classMimeDetector
-
getDescription
public java.lang.String getDescription()
Description copied from class:MimeDetectorAbstract method to be implement by concrete MimeDetector(s).- Specified by:
getDescriptionin classMimeDetector- Returns:
- description of this MimeDetector
-
getMimeTypesFileName
public java.util.Collection getMimeTypesFileName(java.lang.String fileName)
This method resolves mime types closely in accordance with the RECOMENDED order of detection detailed in the Opendesktop shared mime database specification http://standards.freedesktop.org/shared-mime-info-spec/shared -mime-info-spec-latest.html See the Recommended checking order.- Specified by:
getMimeTypesFileNamein classMimeDetector- Returns:
- Collection of matched MimeType(s)
-
getMimeTypesURL
public java.util.Collection getMimeTypesURL(java.net.URL url)
This method resolves mime types closely in accordance with the RECOMENDED order of detection detailed in the Opendesktop shared mime database specification http://standards.freedesktop.org/shared-mime-info-spec/shared -mime-info-spec-latest.html See the Recommended checking order.- Specified by:
getMimeTypesURLin classMimeDetector- Returns:
- Collection of matched MimeType(s)
-
getMimeTypesFile
public java.util.Collection getMimeTypesFile(java.io.File file) throws java.lang.UnsupportedOperationExceptionThis method resolves mime types closely in accordance with the RECOMENDED order of detection detailed in the Opendesktop shared mime database specification http://standards.freedesktop.org/shared-mime-info-spec/shared -mime-info-spec-latest.html See the Recommended checking order.- Specified by:
getMimeTypesFilein classMimeDetector- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypesInputStream
public java.util.Collection getMimeTypesInputStream(java.io.InputStream in) throws java.lang.UnsupportedOperationExceptionThis method is unable to perform glob matching as no name is available. This means that it does not follow the recommended order of detection defined in the shared mime database spec http://standards.freedesktop.org/ shared-mime-info-spec/shared-mime-info-spec-latest.html- Specified by:
getMimeTypesInputStreamin classMimeDetector- Parameters:
in- InputStream.- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
getMimeTypesByteArray
public java.util.Collection getMimeTypesByteArray(byte[] data) throws java.lang.UnsupportedOperationExceptionThis method is unable to perform glob matching as no name is available. This means that it does not follow the recommended order of detection defined in the shared mime database spec http://standards.freedesktop.org/ shared-mime-info-spec/shared-mime-info-spec-latest.html- Specified by:
getMimeTypesByteArrayin classMimeDetector- Parameters:
data- byte []. Is a byte array that you want to parse for matching mime types.- Returns:
- Collection of matched MimeType(s)
- Throws:
java.lang.UnsupportedOperationException
-
dump
public java.lang.String dump()
-
-