public ContentInfo findMatch ( File file ) throws IOException { int readSize = fileReadSize ; if ( ! file . exists ( ) ) { throw new IOException ( "File does not exist: " + file ) ; } if ( ! file . canRead ( ) ) { throw new IOException ( "File is not readable: " + file ) ; } long length = file . length ( ) ; if ( length <= 0 ) { return ContentInfo . EMPTY_INFO ; } if ( length < readSize ) { readSize = ( int ) length ; } byte [ ] bytes = new byte [ readSize ] ; FileInputStream fis = null ; try { fis = new FileInputStream ( file ) ; int numRead = fis . read ( bytes ) ; if ( numRead <= 0 ) { return ContentInfo . EMPTY_INFO ; } if ( numRead < bytes . length ) { bytes = Arrays . copyOf ( bytes , numRead ) ; } } finally { closeQuietly ( fis ) ; } return findMatch ( bytes ) ; }
Return the content type for the file or null if none of the magic entries matched .