@@ -0,0 +1,2568 @@
+package gq.baijie.catalog.usecase;%0A%0Aimport java.io.IOException;%0Aimport java.nio.file.FileVisitResult;%0Aimport java.nio.file.FileVisitor;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.attribute.BasicFileAttributes;%0A%0Aimport gq.baijie.catalog.entity.DirectoryFile;%0Aimport gq.baijie.catalog.entity.RegularFile;%0A%0Aimport static java.nio.file.FileVisitResult.CONTINUE;%0A%0Apublic class ScanFileSystem implements UseCase %7B%0A%0A    private final DirectoryFile rootDirectoryFile;%0A%0A    public ScanFileSystem(DirectoryFile rootDirectoryFile) %7B%0A        this.rootDirectoryFile = rootDirectoryFile;%0A    %7D%0A%0A    @Override%0A    public void execute() %7B%0A        try %7B%0A            execute0();%0A        %7D catch (IOException e) %7B%0A            throw new RuntimeException(%0A                    %22can't scan %22 + rootDirectoryFile.getPath() + %22 directory on the file system.%22);%0A        %7D%0A    %7D%0A%0A    private void execute0() throws IOException %7B%0A        Files.walkFileTree(%0A                rootDirectoryFile.getPath(), new DirectoryFileVisitor(rootDirectoryFile));%0A    %7D%0A%0A    private static class DirectoryFileVisitor implements FileVisitor%3CPath%3E %7B%0A%0A        private DirectoryFile mCurrentDirectory;%0A%0A        public DirectoryFileVisitor(DirectoryFile root) %7B%0A            mCurrentDirectory = root;%0A        %7D%0A%0A        @Override%0A        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)%0A                throws IOException %7B%0A            final DirectoryFile subDirectory = new DirectoryFile(dir);%0A            mCurrentDirectory.getContent().add(subDirectory);%0A            mCurrentDirectory = subDirectory;%0A            return CONTINUE;%0A        %7D%0A%0A        @Override%0A        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) %7B%0A            mCurrentDirectory.getContent().add(new RegularFile(file));%0A            return CONTINUE;%0A        %7D%0A%0A        // Print each directory visited.%0A        @Override%0A        public FileVisitResult postVisitDirectory(Path dir, IOException exc) %7B%0A            mCurrentDirectory = mCurrentDirectory.getParent();%0A            return CONTINUE;%0A        %7D%0A%0A        // If there is some error accessing%0A        // the file, let the user know.%0A        // If you don't override this method%0A        // and an error occurs, an IOException%0A        // is thrown.%0A        @Override%0A        public FileVisitResult visitFileFailed(Path file, IOException exc) %7B%0A            System.err.println(String.format(%22visitFileFailed(%25s, %25s)%22, file, exc));%0A            exc.printStackTrace();%0A            return CONTINUE;%0A        %7D%0A    %7D%0A%0A%7D%0A

add ScanFileSystem Use Case