Class BinaryGuesser


  • public class BinaryGuesser
    extends java.lang.Object
    TODO: factor into MIME guesser and MIME->binary guesser
    • Field Detail

      • CHARSET_FROM_FILE_ENCODING_OR_UTF8

        private static java.nio.charset.Charset CHARSET_FROM_FILE_ENCODING_OR_UTF8
      • DATA_EXTENSIONS

        private static final java.lang.String[] DATA_EXTENSIONS
      • EXE_EXTENSIONS

        private static final java.lang.String[] EXE_EXTENSIONS
      • KEYSTORE_EXTENSIONS

        private static final java.lang.String[] KEYSTORE_EXTENSIONS
      • IMAGE_EXTENSIONS

        private static final java.lang.String[] IMAGE_EXTENSIONS
      • BYTECODE_EXTENSIONS

        private static final java.lang.String[] BYTECODE_EXTENSIONS
      • AUDIO_EXTENSIONS

        private static final java.lang.String[] AUDIO_EXTENSIONS
      • NON_BINARY_EXTENSIONS

        private static final java.lang.String[] NON_BINARY_EXTENSIONS
        Based on https://www.apache.org/dev/svn-eol-style.txt
    • Constructor Detail

      • BinaryGuesser

        public BinaryGuesser()
    • Method Detail

      • isBinaryDocument

        private static boolean isBinaryDocument​(Document document)
      • isBinary

        private static boolean isBinary​(java.lang.CharSequence taste)
      • isBinary

        public static boolean isBinary​(java.io.Reader in)
        Parameters:
        in - the file to check.
        Returns:
        Do the first few bytes of the stream hint at a binary file?

        Any IOException is swallowed internally and the test returns false.

        This method may lead to false negatives if the reader throws an exception because it can't read characters according to the reader's encoding from the underlying stream.

      • isBinary

        public static boolean isBinary​(java.io.InputStream in)
        Parameters:
        in - the file to check.
        Returns:
        Do the first few bytes of the stream hint at a binary file?

        Any IOException is swallowed internally and the test returns false.

        This method will try to read bytes from the stream and translate them to characters according to the platform's default encoding. If any bytes can not be translated to characters it will assume the original data must be binary and return true.

      • getFileEncodingOrUTF8AsFallback

        static java.nio.charset.Charset getFileEncodingOrUTF8AsFallback()
      • isBinaryData

        public static final boolean isBinaryData​(java.lang.String name)
        Parameters:
        name - current file name.
        Returns:
        whether given name is binary.
      • isNonBinary

        public static final boolean isNonBinary​(java.lang.String name)
        Parameters:
        name - current file name.
        Returns:
        Is a file by that name a known non-binary file?
      • isExecutable

        public static final boolean isExecutable​(java.lang.String name)
        Parameters:
        name - current file name.
        Returns:
        Is a file by that name an executable/binary file?
      • containsExtension

        public static boolean containsExtension​(java.lang.String name,
                                                java.lang.String[] exts)
      • extensionMatches

        public static boolean extensionMatches​(java.lang.String name,
                                               java.lang.String[] exts)
      • isBytecode

        public static boolean isBytecode​(java.lang.String name)
      • isImage

        public static final boolean isImage​(java.lang.String name)
      • isKeystore

        public static final boolean isKeystore​(java.lang.String name)
      • isAudio

        public static final boolean isAudio​(java.lang.String name)
      • isBinary

        public static final boolean isBinary​(java.lang.String name)
        Parameters:
        name - file name.
        Returns:
        Is a file by that name a known binary file?
      • isBinary

        public static final boolean isBinary​(Document document)