Class MimeTypes


  • public class MimeTypes
    extends Object
    Simple utility class that resolves file extensions to MIME types.

    There are various solutions built into Java that depend on extra resource and configuration files. They are designed to be composable and extensible, but also unfortunately tricky to control. This is meant to be a simple solution that may eventually be subsumed by a better one.

    • Method Detail

      • getMimeTypeForExtension

        public static String getMimeTypeForExtension​(String fileExtension)
        Gets the MIME type for the file with the given extension. If the mime type is not recognized, this method returns null.
        Parameters:
        fileExtension - The file extension.
        Returns:
        The MIME type, or null, if the file extension is not recognized.
      • getMimeTypeForFileName

        public static String getMimeTypeForFileName​(String fileName)
        Gets the MIME type for the file with the given name, by extension. This method tries to extract the file extension and then use the getMimeTypeForExtension(String) to determine the MIME type. If the extension cannot be determined, or the extension is unrecognized, this method return null.
        Parameters:
        fileName - The file name.
        Returns:
        The MIME type, or null, if the file's extension is not recognized.
      • getDefaultMimeType

        public static String getDefaultMimeType()
        Gets the default MIME type, which is "application/octet-stream".
        Returns:
        The default MIME type.