Class CheckerFile
java.lang.Object
com.luchersol.core.util.AbstractChecker<File,CheckerFile>
com.luchersol.core.specialized_checkers.io.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 checker = CheckerFile.check("example.txt")
.exists()
.canRead()
.withExtension("txt");
The class supports method chaining for fluent validation.
-
Field Summary
Fields inherited from class com.luchersol.core.util.AbstractChecker
backObject, exceptionTracker, name, object, saveErrors, stop -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCheckerFile(File file, String name) Constructs a newCheckerFilewith 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 CheckerFileCreates a CheckerFile for the given file with a default name.static CheckerFileCreates a CheckerFile for the given file and assigns a custom name.static CheckerFileCreates a CheckerFile from a string pathname with a default name.static CheckerFileCreates 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 CheckerFileself()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 com.luchersol.core.util.AbstractChecker
checkProperty, checkProperty, checkProperty, checkProperty, end, getMethod, getObject, getProperty, hasErrors, hasNotErrors, is, is, is, isEqual, isNonNull, isNot, isNot, isNull, notSaveErrors, saveErrors, setBackObject, setExceptionTracker, setName, setObject, setSaveErrors, setStop, show, showPassedChecks, showThrownException, stop, toChecker, updateChecker
-
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:
selfin 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
-