
com.aol.micro.server.s3.CleanupFileVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro-s3 Show documentation
Show all versions of micro-s3 Show documentation
Opinionated rest microservices
package com.aol.micro.server.s3;
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;
public class CleanupFileVisitor extends SimpleFileVisitor {
private final Path tempDirectory;
public CleanupFileVisitor(Path directory) {
this.tempDirectory = directory;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
if (e == null) {
if(!dir.equals(tempDirectory)) {
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
} else {
throw e;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy