Interface MimetypeRegistry

All Known Implementing Classes:
MimetypeRegistryService

public interface MimetypeRegistry
Allows the management of the mime type entry registry.

Flexible registry of mime types.

  • Field Details

  • Method Details

    • getMimetypeFromBlob

      String getMimetypeFromBlob(Blob blob)
      Returns the mime type from a given stream.
      Returns:
      String mime type name.
      Throws:
      MimetypeNotFoundException - if mime type sniffing failed to identify a registered mime type
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
    • getMimetypeFromBlobWithDefault

      String getMimetypeFromBlobWithDefault(Blob blob, String defaultMimetype)
      Finds the mime type of a Blob content and returns provided default if not possible.
      Parameters:
      blob - content to be analyzed
      defaultMimetype - defaultMimeType to be used if no found
      Returns:
      the mime type for the given blob if it exists, otherwise it returns defaultMimetype
      Throws:
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
    • getMimetypeFromFilename

      String getMimetypeFromFilename(String filename)
      Returns the mime type from a given filename.
      Parameters:
      filename - the file name for which we are looking for the mime type
      Returns:
      the mime type that matches the filename
      Throws:
      MimetypeNotFoundException - if mime type sniffing failed to identify a registered mime type
    • getMimetypeFromFile

      String getMimetypeFromFile(File file)
      Returns the mime type from a given file.
      Returns:
      the mime type of the given file
      Throws:
      MimetypeNotFoundException - if mime type sniffing failed to identify a registered mime type
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
    • getExtensionsFromMimetypeName

      List<String> getExtensionsFromMimetypeName(String mimetypeName)
      Returns the extension for given mime type.
      Parameters:
      mimetypeName - the mime type name.
      Returns:
      a list of strings containing the possible extensions.
    • getMimetypeEntryByName

      MimetypeEntry getMimetypeEntryByName(String name)
      Gets a mime type entry by name.
      Parameters:
      name - the mime type name
      Returns:
      the mime type entry that matches the mime type name if it exists, null otherwise
    • getMimetypeEntryByMimeType

      MimetypeEntry getMimetypeEntryByMimeType(String mimetype)
      Gets the MimetypeEntry for a given mime type.
      Parameters:
      mimetype - the mime type for which we are looking for the mime type entry
      Returns:
      the mime type entry if it exists, DEFAULT_MIMETYPE otherwise
    • getMimetypeFromFilenameAndBlobWithDefault

      String getMimetypeFromFilenameAndBlobWithDefault(String filename, Blob blob, String defaultMimetype)
      Finds the mime type of some content according to its filename and / or binary content.
      Parameters:
      filename - extension to analyze
      blob - content to be analyzed if filename is ambiguous
      defaultMimetype - defaultMimeType to be used if no found
      Returns:
      the mime type
      Throws:
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
    • getMimetypeFromFilenameWithBlobMimetypeFallback

      String getMimetypeFromFilenameWithBlobMimetypeFallback(String filename, Blob blob, String defaultMimetype)
      Finds the mime type of some content according to its filename or binary mime type or binary content.
      Parameters:
      filename - extension to analyze
      blob - content to be analyzed if filename is ambiguous
      defaultMimetype - defaultMimeType to be used if no found
      Returns:
      the mime type
      Throws:
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
      Since:
      8.4
    • updateMimetype

      Blob updateMimetype(Blob blob, String filename, Boolean withBlobMimetypeFallback)
      Updates the mime type field of a Blob based on the provided filename with fallback to binary. If the embedded filename is null, the provided filename is embedded into the blob as well.
      Parameters:
      blob - content to be analyzed if filename is ambiguous
      filename - with extension to analyze
      withBlobMimetypeFallback - to consider blob mime type as fallback or not
      Returns:
      updated blob (persisted if necessary)
      Throws:
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
      Since:
      8.4
    • updateMimetype

      Blob updateMimetype(Blob blob, String filename)
      Updates the mime type field of a Blob based on the provided filename with fallback to binary sniffing. If the embedded filename is null, the provided filename is embedded into the blob as well.
      Parameters:
      blob - content to be analyzed if filename is ambiguous
      filename - with extension to analyze
      Returns:
      updated blob (persisted if necessary)
      Throws:
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
    • updateMimetype

      Blob updateMimetype(Blob blob)
      Updates the mime type field of a Blob based on the embedded filename with fallback to binary sniffing. This method should not be called if the embedded filename is null for performance reasons (+ the fact that binary sniffing is no very reliable).
      Parameters:
      blob - content to be analyzed if filename is ambiguous
      Returns:
      updated blob (persisted if necessary)
      Throws:
      MimetypeDetectionException - if unexpected problem prevent the detection to work as expected
    • getMimetypeFromExtension

      String getMimetypeFromExtension(String extension)
      Returns the mime type from a given extension.
      Parameters:
      extension - the extension for which we are looking for the mime type
      Returns:
      the mime type for the given extension if it exists
      Throws:
      MimetypeNotFoundException - if mime type sniffing failed to identify a registered mime type
      Since:
      7.3
    • getNormalizedMimeType

      Optional<String> getNormalizedMimeType(String mimeType)
      Retrieves the normalized mime type for the given mimeType.
      Parameters:
      mimeType - the mime for which we are looking for the normalized one
      Returns:
      an Optional with a present value if the normalized mime type can be found, otherwise an empty Optional
      Since:
      11.1
    • isMimeTypeNormalized

      boolean isMimeTypeNormalized(String mimeType)
      Checks if the given mimeType is a normalized one.
      Parameters:
      mimeType - the mime type to check
      Returns:
      true if mimeType is normalized, false otherwise
      Since:
      11.1