package top.r3944realms.docchecktoolrefactored.test;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

@Slf4j
public class ParallelFileScannerTest {
    public static void main(String[] args) throws IOException {
       test1(Path.of("D:/测试数据/JPG"));
    }
    private static void test1(Path rootPath) throws IOException {
        @SuppressWarnings("resource") List<Path> files = Files.walk(rootPath)
                .peek(p -> log.trace("visiting: {}", p))
                .parallel()
                .filter(p -> {
                    boolean isRegular = Files.isRegularFile(p);
                    if (!isRegular) {
                        log.debug("Skip non-regular : {} ", p);
                    }
                    return isRegular;
                })
                .peek(p -> log.trace("Found file: {}", p))
                .toList();  // 立即消费Stream
        if (files.isEmpty()) {
            log.warn("No files found in directory: {}", rootPath);
        } else log.debug("Found {} files in {}", files.size(), rootPath);
    }
}
