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

    • Constructor Detail

      • OpendesktopMimeDetector

        public OpendesktopMimeDetector​(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 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 Collection getMimeTypesFileName​(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 Collection getMimeTypesURL​(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 Collection getMimeTypesFile​(File file)
                                    throws 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:
        UnsupportedOperationException
      • getMimeTypesInputStream

        public Collection getMimeTypesInputStream​(InputStream in)
                                           throws 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:
        UnsupportedOperationException
      • getMimeTypesByteArray

        public Collection getMimeTypesByteArray​(byte[] data)
                                         throws 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:
        UnsupportedOperationException