Object
XFiles
Additions to standard java.nio.file.Files
-
Field Summary
Modifier and TypeFieldDescriptionSystem temporary folder location if it was found -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
containsAll
(Path a, Path b) Checks, non recursively, if all files of folder A exists in folder B and their content is equal (byte-to-byte comparison).static boolean
containsAll
(Path a, Path b, int maxDepth) static boolean
containsAllRecursively
(Path a, Path b) Checks, recursively, if all files of folder A and its subfolders exists in folder B and their content is equal (byte-to-byte comparison).static void
copyRecursively
(Path source, Path destination) Copies directory recursively with all files and sub-directories inside.static void
deleteRecursively
(Path dir) Deletes directory recursively with all files and sub-directoriesfindFilesRecursively
(Path root, Predicate<Path> fileFilter) Expands to:static boolean
isContentEqual
(File a, File b) Compares two files byte-to-bytewatchForLineInFile
(Path filePath, Predicate<String> matchPredicate, Duration pollDelay) Setup a watcher on a file for a particular line.
-
Field Details
-
TEMP_FOLDER
System temporary folder location if it was found
-
-
Constructor Details
-
XFiles
public XFiles()
-
-
Method Details
-
deleteRecursively
Deletes directory recursively with all files and sub-directories- Throws:
IOException
-
copyRecursively
Copies directory recursively with all files and sub-directories inside.- Parameters:
source
- file or directory to copy from- Throws:
IOException
-
containsAll
Checks, non recursively, if all files of folder A exists in folder B and their content is equal (byte-to-byte comparison).- Parameters:
a
- folder Ab
- folder B- Throws:
IOException
-
containsAllRecursively
Checks, recursively, if all files of folder A and its subfolders exists in folder B and their content is equal (byte-to-byte comparison).- Parameters:
a
- folder Ab
- folder B- Throws:
IOException
-
containsAll
- Parameters:
maxDepth
- the maximum number of directory levels to visit- Throws:
IOException
- See Also:
-
watchForLineInFile
public static Future<String> watchForLineInFile(Path filePath, Predicate<String> matchPredicate, Duration pollDelay) throws IOException, InterruptedException Setup a watcher on a file for a particular line.It polls file with given delay for all new incoming lines. Once it finds a line which matches the predicate it completes the future with that line.
Initially this function was implemented with
WatchService
. This was more efficient since we avoided unnecessary polls when file is not changed. Unfortunately in certain conditionsWatchService
could stuck waiting for events forever although the file was changed already multiple of times. Querying the file size somehow affects this and unblocks the events.Such behavior was observed in Windows10, Java 17 with log file which was actively written but WatchService was not emiting anything.
- Throws:
IOException
InterruptedException
-
isContentEqual
Compares two files byte-to-byte- Throws:
IOException
-
findFilesRecursively
public static Stream<Path> findFilesRecursively(Path root, Predicate<Path> fileFilter) throws IOException Expands to:Files.find(root, Integer.MAX_VALUE, (p, a) -> fileFilter.test(p));
- Throws:
IOException
-