Class 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

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete()
      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.String dump()  
      java.lang.String getDescription()
      Abstract method to be implement by concrete MimeDetector(s).
      java.util.Collection getMimeTypesByteArray​(byte[] data)
      This method is unable to perform glob matching as no name is available.
      java.util.Collection getMimeTypesFile​(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.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.
      java.util.Collection getMimeTypesInputStream​(java.io.InputStream in)
      This method is unable to perform glob matching as no name is available.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OpendesktopMimeDetector

        public OpendesktopMimeDetector​(java.lang.String mimeCacheFile)
      • OpendesktopMimeDetector

        public OpendesktopMimeDetector()
    • Method Detail

      • delete

        public void delete()
        Description copied from class: MimeDetector
        You can override this method if for instance you allocated any resources in the init() method that need to be closed or deallocated specially.
        Overrides:
        delete in class MimeDetector
      • getDescription

        public java.lang.String getDescription()
        Description copied from class: MimeDetector
        Abstract method to be implement by concrete MimeDetector(s).
        Specified by:
        getDescription in class MimeDetector
        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:
        getMimeTypesFileName in class MimeDetector
        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:
        getMimeTypesURL in class MimeDetector
        Returns:
        Collection of matched MimeType(s)
      • getMimeTypesFile

        public java.util.Collection getMimeTypesFile​(java.io.File file)
                                              throws java.lang.UnsupportedOperationException
        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:
        getMimeTypesFile in class MimeDetector
        Returns:
        Collection of matched MimeType(s)
        Throws:
        java.lang.UnsupportedOperationException
      • getMimeTypesInputStream

        public java.util.Collection getMimeTypesInputStream​(java.io.InputStream in)
                                                     throws java.lang.UnsupportedOperationException
        This 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:
        getMimeTypesInputStream in class MimeDetector
        Parameters:
        in - InputStream.
        Returns:
        Collection of matched MimeType(s)
        Throws:
        java.lang.UnsupportedOperationException
      • getMimeTypesByteArray

        public java.util.Collection getMimeTypesByteArray​(byte[] data)
                                                   throws java.lang.UnsupportedOperationException
        This 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:
        getMimeTypesByteArray in class MimeDetector
        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()