Class FileTypeDetector


  • public final class FileTypeDetector
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FileTypeDetector()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static FileType detectFileType​(byte[] fileBytes)  
      static FileType detectFileType​(java.io.BufferedInputStream inputStream)
      Examines the a file's first bytes and estimates the file's type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileTypeDetector

        private FileTypeDetector()
    • Method Detail

      • detectFileType

        public static FileType detectFileType​(java.io.BufferedInputStream inputStream)
                                       throws java.io.IOException
        Examines the a file's first bytes and estimates the file's type.

        Requires a BufferedInputStream in order to mark and reset the stream to the position at which it was provided to this method once completed.

        Requires the stream to contain at least eight bytes.

        Parameters:
        inputStream - a buffered input stream of the file to examine.
        Returns:
        the file type.
        Throws:
        java.io.IOException - if an IO error occurred or the input stream ended unexpectedly.
      • detectFileType

        public static FileType detectFileType​(byte[] fileBytes)
                                       throws java.io.IOException
        Throws:
        java.io.IOException