当前位置: 首页>>代码示例>>Java>>正文


Java FileVisitor.visitFile方法代码示例

本文整理汇总了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")));
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:20,代码来源:GlobPathSetTest.java

示例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));
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:21,代码来源:GlobPathSetTest.java

示例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
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:DeleteAction.java

示例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)));
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:32,代码来源:GlobPathSetTest.java

示例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");
    }
  }
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:31,代码来源:WorkspaceGenerator.java

示例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);
  }
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:13,代码来源:FakeProjectFilesystem.java

示例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");
    }
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:31,代码来源:WorkspaceGenerator.java


注:本文中的java.nio.file.FileVisitor.visitFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。