本文整理汇总了Java中java.nio.file.FileVisitor.visitFile方法的典型用法代码示例。如果您正苦于以下问题:Java FileVisitor.visitFile方法的具体用法?Java FileVisitor.visitFile怎么用?Java FileVisitor.visitFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.FileVisitor
的用法示例。
在下文中一共展示了FileVisitor.visitFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTrackingList
import java.nio.file.FileVisitor; //导入方法依赖的package包/类
@Test
public void testTrackingList() throws Exception {
final Path path = fileSystem.getPath("/var/log/syslog");
Files.createDirectories(path.getParent());
Files.createFile(path);
final PathSet pathSet = new GlobPathSet("/var/log", "syslog", new GlobPathSet.FileTreeWalker() {
@Override
public void walk(Path basePath, FileVisitor<Path> visitor) throws IOException {
visitor.visitFile(path, attributes);
}
}, fileSystem);
final Set<Path> paths = pathSet.getPaths();
assertEquals(path.getParent(), pathSet.getRootPath());
assertEquals(1, paths.size());
assertTrue(paths.contains(fileSystem.getPath("/var/log/syslog")));
}
示例2: testTrackingListWithGlobEdgeCases
import java.nio.file.FileVisitor; //导入方法依赖的package包/类
@Test
public void testTrackingListWithGlobEdgeCases() throws Exception {
final String file1 = "/var/log/ups?art/graylog-collector.log";
final Path path = fileSystem.getPath(file1);
Files.createDirectories(path.getParent());
final PathSet pathSet = new GlobPathSet("/var/log/ups?art", "*.{log,gz}", new GlobPathSet.FileTreeWalker() {
@Override
public void walk(Path basePath, FileVisitor<Path> visitor) throws IOException {
visitor.visitFile(path, attributes);
}
}, fileSystem);
final Set<Path> paths = pathSet.getPaths();
assertEquals(path.getParent(), pathSet.getRootPath());
assertEquals(1, paths.size());
assertTrue(paths.contains(path));
}
示例3: execute
import java.nio.file.FileVisitor; //导入方法依赖的package包/类
@Override
public boolean execute(final FileVisitor<Path> visitor) throws IOException {
final List<PathWithAttributes> sortedPaths = getSortedPaths();
trace("Sorted paths:", sortedPaths);
for (final PathWithAttributes element : sortedPaths) {
try {
visitor.visitFile(element.getPath(), element.getAttributes());
} catch (final IOException ioex) {
LOGGER.error("Error in post-rollover Delete when visiting {}", element.getPath(), ioex);
visitor.visitFileFailed(element.getPath(), ioex);
}
}
// TODO return (visitor.success || ignoreProcessingFailure)
return true; // do not abort rollover even if processing failed
}
示例4: testTrackingListWithGlob
import java.nio.file.FileVisitor; //导入方法依赖的package包/类
@Test
public void testTrackingListWithGlob() throws Exception {
final String file1 = "/var/log/upstart/graylog-collector.log";
final String file2 = "/var/log/test/compressed.log.1.gz";
final String file3 = "/var/log/foo/bar/baz/test.log";
final String file4 = "/var/log/test.log";
Files.createDirectories(fileSystem.getPath(file1).getParent());
Files.createDirectories(fileSystem.getPath(file2).getParent());
Files.createDirectories(fileSystem.getPath(file3).getParent());
Files.createDirectories(fileSystem.getPath(file4).getParent());
final PathSet list = new GlobPathSet("/var/log", "**/*.{log,gz}", new GlobPathSet.FileTreeWalker() {
@Override
public void walk(Path basePath, FileVisitor<Path> visitor) throws IOException {
visitor.visitFile(fileSystem.getPath(file1), attributes);
visitor.visitFile(fileSystem.getPath(file2), attributes);
visitor.visitFile(fileSystem.getPath(file3), attributes);
visitor.visitFile(fileSystem.getPath(file4), attributes);
}
}, fileSystem);
final Set<Path> paths = list.getPaths();
assertEquals(fileSystem.getPath("/var/log"), list.getRootPath());
assertEquals(3, paths.size());
assertTrue(paths.contains(fileSystem.getPath(file1)));
assertTrue(paths.contains(fileSystem.getPath(file2)));
assertTrue(paths.contains(fileSystem.getPath(file3)));
assertFalse(paths.contains(fileSystem.getPath(file4)));
}
示例5: walkNodeTree
import java.nio.file.FileVisitor; //导入方法依赖的package包/类
private void walkNodeTree(FileVisitor<Map.Entry<String, WorkspaceNode>> visitor)
throws IOException{
Stack<Iterator<Map.Entry<String, WorkspaceNode>>> iterators = new Stack<>();
Stack<Map.Entry<String, WorkspaceNode>> groups = new Stack<>();
iterators.push(this.children.entrySet().iterator());
while (!iterators.isEmpty()) {
if (!iterators.peek().hasNext()) {
if (groups.isEmpty()) {
break;
}
visitor.postVisitDirectory(groups.pop(), null);
iterators.pop();
continue;
}
Map.Entry<String, WorkspaceNode> nextEntry = iterators.peek().next();
WorkspaceNode nextNode = nextEntry.getValue();
if (nextNode instanceof WorkspaceGroup) {
visitor.preVisitDirectory(nextEntry, null);
WorkspaceGroup nextGroup = (WorkspaceGroup) nextNode;
groups.push(nextEntry);
iterators.push(nextGroup.getChildren().entrySet().iterator());
} else if (nextNode instanceof WorkspaceFileRef) {
visitor.visitFile(nextEntry, null);
} else {
// Unreachable
throw new HumanReadableException(
"Expected a workspace to only contain groups and file references");
}
}
}
示例6: walkRelativeFileTree
import java.nio.file.FileVisitor; //导入方法依赖的package包/类
/**
* TODO(natthu): (1) Also traverse the directories. (2) Do not ignore return value of
* {@code fileVisitor}.
*/
@Override
public void walkRelativeFileTree(Path path, FileVisitor<Path> fileVisitor) throws IOException {
Preconditions.checkArgument(!fileContents.containsKey(path),
"FakeProjectFilesystem only supports walkRelativeFileTree over directories.");
for (Path file : getFilesUnderDir(path)) {
fileVisitor.visitFile(file, DEFAULT_FILE_ATTRIBUTES);
}
}
示例7: walkNodeTree
import java.nio.file.FileVisitor; //导入方法依赖的package包/类
private void walkNodeTree(FileVisitor<Map.Entry<String, WorkspaceNode>> visitor)
throws IOException {
Stack<Iterator<Map.Entry<String, WorkspaceNode>>> iterators = new Stack<>();
Stack<Map.Entry<String, WorkspaceNode>> groups = new Stack<>();
iterators.push(this.children.entrySet().iterator());
while (!iterators.isEmpty()) {
if (!iterators.peek().hasNext()) {
if (groups.isEmpty()) {
break;
}
visitor.postVisitDirectory(groups.pop(), null);
iterators.pop();
continue;
}
Map.Entry<String, WorkspaceNode> nextEntry = iterators.peek().next();
WorkspaceNode nextNode = nextEntry.getValue();
if (nextNode instanceof WorkspaceGroup) {
visitor.preVisitDirectory(nextEntry, null);
WorkspaceGroup nextGroup = (WorkspaceGroup) nextNode;
groups.push(nextEntry);
iterators.push(nextGroup.getChildren().entrySet().iterator());
} else if (nextNode instanceof WorkspaceFileRef) {
visitor.visitFile(nextEntry, null);
} else {
// Unreachable
throw new HumanReadableException(
"Expected a workspace to only contain groups and file references");
}
}
}