All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.bjurr.violations.lib.reports.ReportsFinder Maven / Gradle / Ivy

There is a newer version: 1.157.3
Show newest version
package se.bjurr.violations.lib.reports;

import static java.nio.file.Files.walkFileTree;
import static java.util.regex.Pattern.matches;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ReportsFinder {

  public static List findAllReports(File startFile, final String pattern) {
    final List found = new ArrayList<>();
    final Path startPath = startFile.toPath();
    try {
      walkFileTree(
          startPath,
          new SimpleFileVisitor() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                throws IOException {
              final String absoluteFile = file.toFile().getAbsolutePath();
              if (matches(pattern, absoluteFile)) {
                found.add(file.toFile());
              }
              return super.visitFile(file, attrs);
            }
          });
    } catch (final IOException e) {
      throw new RuntimeException(e);
    }
    Collections.sort(found);
    return found;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy