codeclimate/sonar-wrapper

View on GitHub
src/main/java/cc/files/Collector.java

Summary

Maintainability
A
0 mins
Test Coverage
package cc.files;

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

public class Collector extends SimpleFileVisitor<Path> {
    final List<Path> files;
    final Path baseDir;

    public Collector(Path baseDir) {
        this.baseDir = baseDir;
        this.files = new ArrayList<>();
    }

    public List<Path> getFiles() {
        return files;
    }

    @Override
    public FileVisitResult visitFile(final Path file, BasicFileAttributes attrs) throws IOException {
        files.add(file);
        return super.visitFile(file, attrs);
    }

    @Override
    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
        if (Files.isHidden(dir)) {
            return FileVisitResult.SKIP_SUBTREE;
        }

        return super.preVisitDirectory(dir, attrs);
    }
}