Interface MimetypeService

  • All Known Implementing Classes:
    MimetypeMap

    @AlfrescoPublicApi
    public interface MimetypeService
    This service interface provides support for Mimetypes.
    Author:
    Derek Hulley
    • Method Detail

      • getExtension

        @NotAuditable
        String getExtension​(String mimetype)
        Get the extension for the specified mimetype
        Parameters:
        mimetype - a valid mimetype
        Returns:
        Returns the default extension for the mimetype
      • getMimetype

        @NotAuditable
        String getMimetype​(String extension)
        Get the mimetype for the specified extension
        Parameters:
        extension - a valid file extension
        Returns:
        Returns a valid mimetype if found, or null if does not exist
      • getDisplaysByExtension

        @NotAuditable
        Map<String,​String> getDisplaysByExtension()
        Get all human readable mimetype descriptions indexed by mimetype extension
        Returns:
        the map of displays indexed by extension
      • getDisplaysByMimetype

        @NotAuditable
        Map<String,​String> getDisplaysByMimetype()
        Get all human readable mimetype descriptions indexed by mimetype
        Returns:
        the map of displays indexed by mimetype
      • getExtensionsByMimetype

        @NotAuditable
        Map<String,​String> getExtensionsByMimetype()
        Get all mimetype extensions indexed by mimetype
        Returns:
        the map of extension indexed by mimetype
      • getMimetypesByExtension

        @NotAuditable
        Map<String,​String> getMimetypesByExtension()
        Get all mimetypes indexed by extension
        Returns:
        the map of mimetypes indexed by extension
      • isText

        @NotAuditable
        boolean isText​(String mimetype)
        Check if a given mimetype represents a text format.
        Parameters:
        mimetype - the mimetype to check
        Returns:
        Returns true if it is text
      • guessMimetype

        @NotAuditable
        String guessMimetype​(String filename)
        Provides a non-null best guess of the appropriate mimetype given a filename, based entirely on the file extension. Because file extensions can be wrong, you are strongly advised to use guessMimetype(String, ContentReader) instead.
        Parameters:
        filename - the name of the file with an optional file extension
        Returns:
        Returns the best guess mimetype or the mimetype for straight binary files if no extension could be found.
      • guessMimetype

        @NotAuditable
        String guessMimetype​(String filename,
                             ContentReader reader)
        Provides a non-null best guess of the appropriate mimetype for a given file. Uses a mixture of file name and file content logic to identify the mimetype for the file, and will usually manage to identify files with incorrect extensions.
        Parameters:
        filename - the name of the file with an optional file extension
        reader - a reader for the content of the file
        Returns:
        Returns the best guess mimetype or the mimetype for straight binary files if no extension could be found.
      • guessMimetype

        @NotAuditable
        String guessMimetype​(String filename,
                             InputStream input)
        Provides a non-null best guess of the appropriate mimetype for a given file. Uses a mixture of file name and file content logic to identify the mimetype for the file, and will usually manage to identify files with incorrect extensions.
        Parameters:
        filename - the name of the file with an optional file extension
        input - an input stream for the content
        Returns:
        Returns the best guess mimetype or the mimetype for straight binary files if no extension could be found.
      • getMimetypeIfNotMatches

        @NotAuditable
        String getMimetypeIfNotMatches​(ContentReader reader)
        Use detection heuristics to check if the mime type of the document really matches what it claims to be. This is typically used when a transformation or metadata extractions fails, and you want to know if someone has renamed a file and consequently it has the wrong mime type.
        Returns:
        Null if the mime type seems ok, otherwise the mime type it probably is
      • getContentCharsetFinder

        @NotAuditable
        ContentCharsetFinder getContentCharsetFinder()
        Provides the system default charset finder.
        Returns:
        Returns a character set finder that can be used to decode streams in order to get the encoding.
        Since:
        2.1
      • getMimetypes

        @NotAuditable
        Collection<String> getMimetypes​(String extension)
        Returns a collection of mimetypes ordered by extension.
        Parameters:
        extension - to restrict the collection to one entry