Class CheckerFile

java.lang.Object
util.AbstractChecker<File,CheckerFile>
specialized_checkers.io.CheckerFile
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<File,CheckerFile>,File>

public class CheckerFile extends AbstractChecker<File,CheckerFile>
CheckerFile provides a fluent API for performing various checks and validations on File objects.

This class extends AbstractChecker and allows users to verify file properties such as existence, type, permissions, size, extension, and content identity. It supports both files and directories, and can be used to validate files by path or by File instance.

Example usage:

     CheckerFile.check("example.txt")
         .exists()
         .canRead()
         .withExtension("txt");
 

The class supports method chaining for fluent validation.

  • Constructor Details

    • CheckerFile

      protected CheckerFile(File file, String name)
      Constructs a new CheckerFile with the specified file and name.
      Parameters:
      file - the File object representing the file to be associated with this CheckerFile
      name - the name to be assigned to this CheckerFile
  • Method Details

    • check

      public static CheckerFile check(File file, String name)
      Creates a CheckerFile for the given file and assigns a custom name.
      Parameters:
      file - the file to check
      name - the name to assign to this checker
      Returns:
      a CheckerFile instance for the given file
    • check

      public static CheckerFile check(String pathname, String name)
      Creates a CheckerFile from a string pathname and assigns a custom name.
      Parameters:
      pathname - the path to the file
      name - the name to assign to this checker
      Returns:
      a CheckerFile instance for the given path
    • check

      public static CheckerFile check(File file)
      Creates a CheckerFile for the given file with a default name.
      Parameters:
      file - the file to check
      Returns:
      a CheckerFile instance for the given file
    • check

      public static CheckerFile check(String pathname)
      Creates a CheckerFile from a string pathname with a default name.
      Parameters:
      pathname - the path to the file
      Returns:
      a CheckerFile instance for the given path
    • self

      protected CheckerFile self()
      Returns this instance (for fluent API).
      Specified by:
      self in class AbstractChecker<File,CheckerFile>
      Returns:
      this CheckerFile instance
    • exists

      public CheckerFile exists()
      Checks if the file exists.
      Returns:
      this CheckerFile instance
    • isTypeFile

      public CheckerFile isTypeFile()
      Checks if the file is a regular file (not a directory).
      Returns:
      this CheckerFile instance
    • isTypeDirectory

      public CheckerFile isTypeDirectory()
      Checks if the file is a directory.
      Returns:
      this CheckerFile instance
    • isTypeHidden

      public CheckerFile isTypeHidden()
      Checks if the file is hidden.
      Returns:
      this CheckerFile instance
    • canRead

      public CheckerFile canRead()
      Checks if the file can be read.
      Returns:
      this CheckerFile instance
    • canWrite

      public CheckerFile canWrite()
      Checks if the file can be written to.
      Returns:
      this CheckerFile instance
    • min

      public CheckerFile min(int minBytes)
      Checks if the file size is at least the specified minimum number of bytes.
      Parameters:
      minBytes - the minimum file size in bytes
      Returns:
      this CheckerFile instance
    • max

      public CheckerFile max(int maxBytes)
      Checks if the file size is at most the specified maximum number of bytes.
      Parameters:
      maxBytes - the maximum file size in bytes
      Returns:
      this CheckerFile instance
    • inRange

      public CheckerFile inRange(int minBytes, int maxBytes)
      Checks if the file size is within the specified range (inclusive).
      Parameters:
      minBytes - the minimum file size in bytes
      maxBytes - the maximum file size in bytes
      Returns:
      this CheckerFile instance
    • withExtension

      public CheckerFile withExtension(String extension)
      Checks if the file has the specified extension.
      Parameters:
      extension - the file extension to check for (without dot)
      Returns:
      this CheckerFile instance
    • withAnyExtension

      public CheckerFile withAnyExtension(String... extensions)
      Checks if the file has any of the specified extensions.
      Parameters:
      extensions - the file extensions to check for (without dot)
      Returns:
      this CheckerFile instance
    • isIdentical

      public CheckerFile isIdentical(String path)
      Checks if the file is identical to another file at the specified path.
      Parameters:
      path - the path to the file to compare with
      Returns:
      this CheckerFile instance