Class ContentTypeDetector


  • public final class ContentTypeDetector
    extends Object
    Master class to detect all content types. This class is thread-safe.
    Since:
    2.0.0
    Author:
    Pascal Essiembre
    • Method Detail

      • detect

        public static ContentType detect​(File file)
                                  throws IOException
        Detects the content type of the given file.
        Parameters:
        file - file on which to detect content type
        Returns:
        the detected content type
        Throws:
        IOException - problem detecting content type
      • detect

        public static ContentType detect​(File file,
                                         String fileName)
                                  throws IOException
        Detects the content type of the given file.
        Parameters:
        file - file on which to detect content type
        fileName - a file name which can help influence detection
        Returns:
        the detected content type
        Throws:
        IOException - problem detecting content type
      • detect

        public static ContentType detect​(InputStream content)
                                  throws IOException
        Detects the content type from the given input stream.
        Parameters:
        content - the content on which to detect content type
        Returns:
        the detected content type
        Throws:
        IOException - problem detecting content type
      • detect

        public static ContentType detect​(InputStream content,
                                         String fileName)
                                  throws IOException
        Detects the content type from the given input stream.
        Parameters:
        content - the content on which to detect content type
        fileName - a file name which can help influence detection
        Returns:
        the detected content type
        Throws:
        IOException - problem detecting content type