Class MimeTypesUtils


  • public class MimeTypesUtils
    extends Object
    This class defines from static helper methods to deal with Mime Types.
    • Constructor Detail

      • MimeTypesUtils

        public MimeTypesUtils()
    • Method Detail

      • getContentType

        public static String getContentType​(File file)
        Returns the content type from the file.
        Parameters:
        file - the file
        Returns:
        detected content type if it is a supported format or "application/octet-stream" if it is an unsupported format
      • getContentType

        public static String getContentType​(Path path)
        Returns the content type from the path.
        Parameters:
        path - the path
        Returns:
        detected content type if it is a supported format or "application/octet-stream" if it is an unsupported format
      • getContentType

        public static String getContentType​(String fileName)
        Detects the content type of the given file name. The type detection is based on known file name extensions.
        Parameters:
        fileName - the file name
        Returns:
        detected content type if it is a supported format or "application/octet-stream" if it is an unsupported format
      • getExtensionContentType

        public static String getExtensionContentType​(String extension)
        Returns the content type from the file extension.
        Parameters:
        extension - the extension of the file (e.g., "doc")
        Returns:
        detected content type if it is a supported format or "application/octet-stream" if it is an unsupported format
      • getContentType

        public static String getContentType​(File file,
                                            String fileName)
        Returns the content type from the file and file name.
        Parameters:
        file - the file, can be null
        fileName - the file name or extension of the file (e.g., "doc")
        Returns:
        detected content type if it is a supported format or "application/octet-stream" if it is an unsupported format
      • getContentType

        public static String getContentType​(InputStream inputStream,
                                            String fileName)
        Returns the content type from the file and file name.
        Parameters:
        inputStream - the input stream, can be null
        fileName - the file name or extension of the file (e.g., "doc")
        Returns:
        detected content type if it is a supported format or "application/octet-stream" if it is an unsupported format