public static void eachFileMatch(final Path self, final FileType fileType, final Object nameFilter, final @ClosureParams(value=SimpleType.class, options="java.nio.file.Path") Closure closure) throws IOException {
// throws FileNotFoundException, IllegalArgumentException {
checkDir(self);
try ( DirectoryStream<Path> stream = Files.newDirectoryStream(self) ) {
Iterator<Path> itr = stream.iterator();
BooleanReturningMethodInvoker bmi = new BooleanReturningMethodInvoker("isCase");
while ( itr.hasNext() ) {
Path currentPath = itr.next();
if ((fileType != FileType.FILES && Files.isDirectory(currentPath)) ||
(fileType != FileType.DIRECTORIES && Files.isRegularFile(currentPath)))
{
if (bmi.invoke(nameFilter, currentPath.getFileName().toString()))
closure.call(currentPath);
}
}
}
}