Class DefaultMimeService

  • All Implemented Interfaces:
    MimeService, org.springframework.beans.factory.InitializingBean

    public class DefaultMimeService
    extends java.lang.Object
    implements MimeService, org.springframework.beans.factory.InitializingBean
    • Constructor Detail

      • DefaultMimeService

        public DefaultMimeService()
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • getFileExtensionFromMime

        public java.lang.String getFileExtensionFromMime​(java.lang.String mime)
        Description copied from interface: MimeService
        Gets the file extension from provided mime or null if it cannot be found in configuration properties. List of all configured mime types and corresponding file extensions can be found in advanced.properties file (look for keys starting from media.customextension).
        Specified by:
        getFileExtensionFromMime in interface MimeService
        Parameters:
        mime - the mime to check
        Returns:
        the file extension from mime
      • getBestExtensionFromMime

        public java.lang.String getBestExtensionFromMime​(java.lang.String mime)
        Description copied from interface: MimeService
        Gets the best matching extension from mime. This method first tries to look into configured file extensions in advanced.properties file and if cannot be found default bin file extension is returned
        Specified by:
        getBestExtensionFromMime in interface MimeService
        Parameters:
        mime - the mime to check
        Returns:
        the best extension from mime
      • getMimeFromFileExtension

        public java.lang.String getMimeFromFileExtension​(java.lang.String fileName)
        Description copied from interface: MimeService
        Gets the mime from file extension or null if it cannot be found in configuration properties. List of all configured mime types and corresponding file extensions can be found in advanced.properties file (look for keys starting from mediatype.by.fileextension).
        Specified by:
        getMimeFromFileExtension in interface MimeService
        Parameters:
        fileName - the file name to check
        Returns:
        the mime from file extension
      • getConfigParameter

        protected java.lang.String getConfigParameter​(java.lang.String configKey)
      • getBestMime

        public java.lang.String getBestMime​(java.lang.String fileName,
                                            byte[] firstBytes,
                                            java.lang.String overrideMime)
        Description copied from interface: MimeService
        Gets the best mime. This method first tries to determine from fileName extension. If it cannot be determined provided firstBytes of data are used to dermine mime. If it fail then overrideMime may be used if it is on list of supported mime types (look for media.customextension keys in advanced.properties file for supported mime types and file extensions). Finally if it fail than default mime is returned which is always application/octet-stream.
        Specified by:
        getBestMime in interface MimeService
        Parameters:
        fileName - the file name to check
        firstBytes - the first bytes of data
        overrideMime - the override mime
        Returns:
        the best mime
      • getSupportedMimeTypes

        public java.util.Set<java.lang.String> getSupportedMimeTypes()
        Description copied from interface: MimeService
        Gets set of supported mime types.
        Specified by:
        getSupportedMimeTypes in interface MimeService
        Returns:
        the supported mime types
      • getConfigParametersByPattern

        protected java.util.Map<java.lang.String,​java.lang.String> getConfigParametersByPattern​(java.lang.String keyPrefix)
      • getMimeFromFirstBytes

        public java.lang.String getMimeFromFirstBytes​(byte[] firstBytes)
        Description copied from interface: MimeService
        Gets the mime from first bytes of data or null if it cannot be determined.
        Specified by:
        getMimeFromFirstBytes in interface MimeService
        Parameters:
        firstBytes - the first bytes of data
        Returns:
        the mime from first bytes
      • isZipRelatedMime

        public boolean isZipRelatedMime​(java.lang.String mime)
        Description copied from interface: MimeService
        Checks whether provided mime is zip related mime.
        Specified by:
        isZipRelatedMime in interface MimeService
        Parameters:
        mime - the mime to check
        Returns:
        true, if is zip related mime