MCPcopy Create free account
hub / github.com/SeanDragon/protools / RmrVisitor

Class RmrVisitor

common/src/main/java/pro/tools/path/visit/RmrVisitor.java:18–59  ·  view source on GitHub ↗

@author SeanDragon Create By 2017-09-01 14:47

Source from the content-addressed store, hash-verified

16 * Create By 2017-09-01 14:47
17 */
18public class RmrVisitor implements FileVisitor<Path> {
19
20 private static final Logger log = LoggerFactory.getLogger(RmrVisitor.class);
21
22 public static final RmrVisitor INSTANCE = new RmrVisitor();
23
24 @Override
25 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
26 return FileVisitResult.CONTINUE;
27 }
28
29 @Override
30 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
31 boolean result = rm(file);
32 if (log.isDebugEnabled()) {
33 log.debug("删除文件:\t" + file + ",执行结果:\t" + result);
34 }
35 return FileVisitResult.CONTINUE;
36 }
37
38 @Override
39 public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
40 return FileVisitResult.CONTINUE;
41 }
42
43 @Override
44 public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
45 if (exc == null) {
46 boolean success = rm(dir);
47 if (log.isDebugEnabled()) {
48 log.debug("删除文件夹:\t" + dir + ",执行结果:\t" + success);
49 }
50 } else {
51 throw exc;
52 }
53 return FileVisitResult.CONTINUE;
54 }
55
56 private static boolean rm(Path path) throws IOException {
57 return Files.deleteIfExists(path);
58 }
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected