Class TextFileDetector

java.lang.Object
me.pauleff.common.handlers.files.TextFileDetector

public final class TextFileDetector extends Object
Classifies files as text or binary using a bounded byte-sample heuristic.
  • Method Details

    • isTextBased

      public static boolean isTextBased(Path path) throws IOException
      Determines whether a file appears to be text-based rather than binary.

      Reads up to 8 KiB from the start of the file and counts bytes outside printable ASCII, Latin-1, and common control characters. Empty files are treated as text.

      Parameters:
      path - the path to the file to inspect
      Returns:
      true if the file is classified as text-based; false otherwise
      Throws:
      IllegalArgumentException - if path is not a regular file
      IOException - if the file cannot be read