use of java.nio.file.FileVisitResult in project neo4j by neo4j.
the class FileVisitorsDecoratorsTest method shouldPropagateReturnValueFromPostVisitDirectory.
@Test
public void shouldPropagateReturnValueFromPostVisitDirectory() throws IOException {
for (FileVisitResult result : FileVisitResult.values()) {
when(wrapped.postVisitDirectory(any(), any())).thenReturn(result);
assertThat(decorator.postVisitDirectory(null, null), is(result));
}
}
use of java.nio.file.FileVisitResult in project neo4j by neo4j.
the class FileVisitorsDecoratorsTest method shouldPropagateReturnValueFromVisitFileFailed.
@Test
public void shouldPropagateReturnValueFromVisitFileFailed() throws IOException {
for (FileVisitResult result : FileVisitResult.values()) {
when(wrapped.visitFileFailed(any(), any())).thenReturn(result);
assertThat(decorator.visitFileFailed(null, null), is(result));
}
}
use of java.nio.file.FileVisitResult in project wire by square.
the class SchemaLoader method loadFromDirectories.
private Schema loadFromDirectories(Map<Path, Path> directories) throws IOException {
final Deque<String> protos = new ArrayDeque<>(this.protos);
if (protos.isEmpty()) {
for (final Map.Entry<Path, Path> entry : directories.entrySet()) {
Files.walkFileTree(entry.getValue(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith(".proto")) {
protos.add(entry.getValue().relativize(file).toString());
}
return FileVisitResult.CONTINUE;
}
});
}
}
Map<String, ProtoFile> loaded = new LinkedHashMap<>();
loaded.put(DESCRIPTOR_PROTO, loadDescriptorProto());
while (!protos.isEmpty()) {
String proto = protos.removeFirst();
if (loaded.containsKey(proto)) {
continue;
}
ProtoFileElement element = null;
for (Map.Entry<Path, Path> entry : directories.entrySet()) {
Source source = source(entry.getValue(), proto);
if (source == null) {
continue;
}
Path base = entry.getKey();
try {
Location location = Location.get(base.toString(), proto);
String data = Okio.buffer(source).readUtf8();
element = ProtoParser.parse(location, data);
break;
} catch (IOException e) {
throw new IOException("Failed to load " + proto + " from " + base, e);
} finally {
source.close();
}
}
if (element == null) {
throw new FileNotFoundException("Failed to locate " + proto + " in " + sources);
}
ProtoFile protoFile = ProtoFile.get(element);
loaded.put(proto, protoFile);
// Queue dependencies to be loaded.
for (String importPath : element.imports()) {
protos.addLast(importPath);
}
}
return new Linker(loaded.values()).link();
}
use of java.nio.file.FileVisitResult in project zaproxy by zaproxy.
the class VulnerabilitiesLoader method getListOfVulnerabilitiesFiles.
/**
* Returns a {@code List} of resources files with {@code fileName} and {@code fileExtension} contained in the
* {@code directory}.
*
* @return the list of resources files contained in the {@code directory}
* @see LocaleUtils#createResourceFilesPattern(String, String)
*/
private List<String> getListOfVulnerabilitiesFiles() {
final Pattern filePattern = LocaleUtils.createResourceFilesPattern(fileName, fileExtension);
final List<String> fileNames = new ArrayList<>();
try {
Files.walkFileTree(directory, Collections.<FileVisitOption>emptySet(), 1, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String fileName = file.getFileName().toString();
if (filePattern.matcher(fileName).matches()) {
fileNames.add(fileName);
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
logger.error("An error occurred while walking directory: " + directory, e);
}
return fileNames;
}
use of java.nio.file.FileVisitResult in project alluxio by Alluxio.
the class FileUtils method deletePathRecursively.
/**
* Deletes a path recursively.
*
* @param path pathname to be deleted
* @throws IOException when fails to delete
*/
public static void deletePathRecursively(String path) throws IOException {
Path root = Paths.get(path);
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@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) {
Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
throw e;
}
}
});
}
Aggregations