Class BinaryGuesser

java.lang.Object
org.apache.rat.document.impl.guesser.BinaryGuesser

public class BinaryGuesser extends Object
TODO: factor into MIME guesser and MIME->binary guesser
  • Field Details

  • Constructor Details

    • BinaryGuesser

      public BinaryGuesser()
  • Method Details

    • isBinary

      public static boolean isBinary(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(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.

    • isBinaryData

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

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

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

      public static boolean containsExtension(String name, String[] exts)
    • extensionMatches

      public static boolean extensionMatches(String name, String[] exts)
    • isBytecode

      public static boolean isBytecode(String name)
    • isImage

      public static boolean isImage(String name)
    • isKeystore

      public static boolean isKeystore(String name)
    • isAudio

      public static boolean isAudio(String name)
    • isBinary

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

      public static boolean isBinary(Document document)