Class CheckerFile
- All Implemented Interfaces:
InterfaceChecker<AbstractChecker<File,
CheckerFile>, File>
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.
-
Field Summary
Fields inherited from class util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
CheckerFile
(File file, String name) Constructs a newCheckerFile
with the specified file and name. -
Method Summary
Modifier and TypeMethodDescriptioncanRead()
Checks if the file can be read.canWrite()
Checks if the file can be written to.static CheckerFile
Creates a CheckerFile for the given file with a default name.static CheckerFile
Creates a CheckerFile for the given file and assigns a custom name.static CheckerFile
Creates a CheckerFile from a string pathname with a default name.static CheckerFile
Creates a CheckerFile from a string pathname and assigns a custom name.exists()
Checks if the file exists.inRange
(int minBytes, int maxBytes) Checks if the file size is within the specified range (inclusive).isIdentical
(String path) Checks if the file is identical to another file at the specified path.Checks if the file is a directory.Checks if the file is a regular file (not a directory).Checks if the file is hidden.max
(int maxBytes) Checks if the file size is at most the specified maximum number of bytes.min
(int minBytes) Checks if the file size is at least the specified minimum number of bytes.protected CheckerFile
self()
Returns this instance (for fluent API).withAnyExtension
(String... extensions) Checks if the file has any of the specified extensions.withExtension
(String extension) Checks if the file has the specified extension.Methods inherited from class util.AbstractChecker
checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, show, showNotThrownException, showThrownException, stop
-
Constructor Details
-
CheckerFile
-
-
Method Details
-
check
Creates a CheckerFile for the given file and assigns a custom name.- Parameters:
file
- the file to checkname
- the name to assign to this checker- Returns:
- a CheckerFile instance for the given file
-
check
Creates a CheckerFile from a string pathname and assigns a custom name.- Parameters:
pathname
- the path to the filename
- the name to assign to this checker- Returns:
- a CheckerFile instance for the given path
-
check
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
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
Returns this instance (for fluent API).- Specified by:
self
in classAbstractChecker<File,
CheckerFile> - Returns:
- this CheckerFile instance
-
exists
-
isTypeFile
Checks if the file is a regular file (not a directory).- Returns:
- this CheckerFile instance
-
isTypeDirectory
Checks if the file is a directory.- Returns:
- this CheckerFile instance
-
isTypeHidden
-
canRead
-
canWrite
Checks if the file can be written to.- Returns:
- this CheckerFile instance
-
min
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
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
Checks if the file size is within the specified range (inclusive).- Parameters:
minBytes
- the minimum file size in bytesmaxBytes
- the maximum file size in bytes- Returns:
- this CheckerFile instance
-
withExtension
Checks if the file has the specified extension.- Parameters:
extension
- the file extension to check for (without dot)- Returns:
- this CheckerFile instance
-
withAnyExtension
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
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
-