org.uberfire.java.nio.file.Files.walkFileTree()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中org.uberfire.java.nio.file.Files.walkFileTree()方法的一些代码示例,展示了Files.walkFileTree()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.walkFileTree()方法的具体详情如下:
包路径:org.uberfire.java.nio.file.Files
类名称:Files
方法名:walkFileTree

Files.walkFileTree介绍

暂无

代码示例

代码示例来源:origin: kiegroup/appformer

private void copyFolders(final org.uberfire.java.nio.file.Path nioTargetRepositoryRoot,
             final org.uberfire.java.nio.file.Path originRepositoryRoot) {
  final RecursiveCopier copier = new RecursiveCopier(originRepositoryRoot,
                            nioTargetRepositoryRoot);
  Files.walkFileTree(originRepositoryRoot,
            copier);
}

代码示例来源:origin: kiegroup/appformer

private void removeRegistry(final Path path) {
  walkFileTree(path,
         new SimpleFileVisitor<Path>() {
           @Override
           public FileVisitResult visitFile(final Path file,
                           final BasicFileAttributes attrs) throws IOException {
             try {
               checkNotNull("file",
                     file);
               checkNotNull("attrs",
                     attrs);
               if (file.getFileName().toString().endsWith(".registry.js") && attrs.isRegularFile()) {
                 final org.uberfire.backend.vfs.Path path = convert(file);
                 getIoService().delete(file);
               }
             } catch (final Exception ex) {
               return FileVisitResult.TERMINATE;
             }
             return FileVisitResult.CONTINUE;
           }
         });
}

代码示例来源:origin: org.uberfire/vfs-api

/**
 * @throws IllegalArgumentException
 * @throws IOException
 * @throws SecurityException
 * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path, java.nio.file.FileVisitor)">Original JavaDoc</a>
 */
public static Path walkFileTree(final Path start, final FileVisitor<Path> visitor)
    throws IllegalArgumentException, IOException, SecurityException {
  checkNotNull("start", start);
  checkNotNull("visitor", visitor);
  final Set<FileVisitOption> options = emptySet();
  return walkFileTree(start, options, Integer.MAX_VALUE, visitor);
}

代码示例来源:origin: kiegroup/appformer

/**
 * @throws IllegalArgumentException
 * @throws IOException
 * @throws SecurityException
 * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path, java.nio.file.FileVisitor)">Original JavaDoc</a>
 */
public static Path walkFileTree(final Path start,
                final FileVisitor<Path> visitor)
    throws IllegalArgumentException, IOException, SecurityException {
  checkNotNull("start",
         start);
  checkNotNull("visitor",
         visitor);
  final Set<FileVisitOption> options = emptySet();
  return walkFileTree(start,
            options,
            Integer.MAX_VALUE,
            visitor);
}

代码示例来源:origin: org.uberfire/uberfire-nio2-api

/**
 * @throws IllegalArgumentException
 * @throws IOException
 * @throws SecurityException
 * @see <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#walkFileTree(java.nio.file.Path, java.nio.file.FileVisitor)">Original JavaDoc</a>
 */
public static Path walkFileTree(final Path start,
                final FileVisitor<Path> visitor)
    throws IllegalArgumentException, IOException, SecurityException {
  checkNotNull("start",
         start);
  checkNotNull("visitor",
         visitor);
  final Set<FileVisitOption> options = emptySet();
  return walkFileTree(start,
            options,
            Integer.MAX_VALUE,
            visitor);
}

代码示例来源:origin: kiegroup/appformer

if (ioService.exists(perspectivesPath)) {
  walkFileTree(perspectivesPath,
         new SimpleFileVisitor<Path>() {
           public FileVisitResult visitFile(final Path file,

代码示例来源:origin: org.dashbuilder/dashbuilder-dataset-cdi

public Collection<DataSetDef> listDataSetDefs() {
  final Collection<DataSetDef> result = new ArrayList<>();
  if (ioService.exists(root)) {
    walkFileTree(checkNotNull("root",
                 root),
           new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile(final Path file,
                             final BasicFileAttributes attrs) throws IOException {
               try {
                 checkNotNull("file",
                       file);
                 checkNotNull("attrs",
                       attrs);
                 if (file.getFileName().toString().endsWith(DATASET_EXT) && attrs.isRegularFile()) {
                   String json = ioService.readAllString(file);
                   DataSetDef def = getDataSetDefJsonMarshaller().fromJson(json);
                   result.add(def);
                 }
               } catch (final Exception e) {
                 log.error("Data set definition read error: " + file.getFileName(),
                      e);
                 return FileVisitResult.TERMINATE;
               }
               return FileVisitResult.CONTINUE;
             }
           });
  }
  return result;
}

代码示例来源:origin: org.uberfire/uberfire-perspective-editor-backend

@Override
public Collection<String> listPerspectives() {
  final Collection<String> result = new ArrayList<String>();
  final Path perspectivesDir = fileSystem.getPath( PERSPECTIVE_EDITOR );
  if ( ioService.exists( perspectivesDir ) ) {
    walkFileTree( checkNotNull( "root", perspectivesDir ),
           new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile( final Path file,
                              final BasicFileAttributes attrs ) throws IOException {
               try {
                 checkNotNull( "file", file );
                 checkNotNull( "attrs", attrs );
                 if ( attrs.isRegularFile() ) {
                   final org.uberfire.backend.vfs.Path path = convert( file );
                   result.add( file.getFileName().toString() );
                 }
               } catch ( final Exception ex ) {
                 return FileVisitResult.TERMINATE;
               }
               return FileVisitResult.CONTINUE;
             }
           } );
  }
  return result;
}

代码示例来源:origin: org.kie.uberfire/kie-uberfire-runtime-plugins-backend

@Override
public Collection<Plugin> listPlugins() {
  final Collection<Plugin> result = new ArrayList<Plugin>();
  final Path plugins = fileSystem.getPath( "plugins", "/" );
  if ( ioService.exists( plugins ) ) {
    walkFileTree( checkNotNull( "root", plugins ),
           new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile( final Path file,
                              final BasicFileAttributes attrs ) throws IOException {
               try {
                 checkNotNull( "file", file );
                 checkNotNull( "attrs", attrs );
                 if ( file.getFileName().toString().endsWith( ".plugin" ) && attrs.isRegularFile() ) {
                   final org.uberfire.backend.vfs.Path path = convert( file );
                   result.add( new Plugin( file.getParent().getFileName().toString(), TypeConverterUtil.fromPath( path ), path ) );
                 }
               } catch ( final Exception ex ) {
                 return FileVisitResult.TERMINATE;
               }
               return FileVisitResult.CONTINUE;
             }
           } );
  }
  return result;
}

代码示例来源:origin: kiegroup/appformer

private Collection<RuntimePlugin> listRuntimePlugins(Path path) {
  final Collection<RuntimePlugin> result = new ArrayList<RuntimePlugin>();
  if (getIoService().exists(path)) {
    walkFileTree(checkNotNull("path",
                 path),
           new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile(final Path file,
                             final BasicFileAttributes attrs) throws IOException {
               try {
                 checkNotNull("file",
                       file);
                 checkNotNull("attrs",
                       attrs);
                 if (attrs.isRegularFile()) {
                   result.addAll(buildPluginRuntimePlugins(file));
                 }
               } catch (final Exception ex) {
                 logger.error("An unexpected exception was thrown: ",
                       ex);
                 return FileVisitResult.TERMINATE;
               }
               return FileVisitResult.CONTINUE;
             }
           });
  }
  return result;
}

代码示例来源:origin: kiegroup/appformer

@Override
public Collection<LayoutEditorModel> listLayoutEditor(final PluginType pluginType) {
  final Collection<LayoutEditorModel> result = new ArrayList<LayoutEditorModel>();
  if (getIoService().exists(root)) {
    walkFileTree(checkNotNull("root",
                 root),
           new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile(final Path file,
                             final BasicFileAttributes attrs) throws IOException {
               try {
                 checkNotNull("file",
                       file);
                 checkNotNull("attrs",
                       attrs);
                 if (file.getFileName().toString().equalsIgnoreCase(pluginType.toString().toLowerCase()) && attrs.isRegularFile()) {
                   final LayoutEditorModel layoutEditorModel = getLayoutEditor(convert(file),
                                                 pluginType);
                   result.add(layoutEditorModel);
                 }
               } catch (final Exception ex) {
                 return FileVisitResult.TERMINATE;
               }
               return FileVisitResult.CONTINUE;
             }
           });
  }
  return result;
}

代码示例来源:origin: kiegroup/appformer

@Override
public Collection<Plugin> listPlugins() {
  final Collection<Plugin> result = new ArrayList<>();
  if (getIoService().exists(root)) {
    walkFileTree(checkNotNull("root",
                 root),
           new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile(final Path file,
                             final BasicFileAttributes attrs) throws IOException {
               try {
                 checkNotNull("file",
                       file);
                 checkNotNull("attrs",
                       attrs);
                 if (file.getFileName().toString().endsWith(".plugin") && attrs.isRegularFile()) {
                   final org.uberfire.backend.vfs.Path path = convert(file);
                   result.add(new Plugin(file.getParent().getFileName().toString(),
                              TypeConverterUtil.fromPath(path),
                              path));
                 }
               } catch (final Exception ex) {
                 return FileVisitResult.TERMINATE;
               }
               return FileVisitResult.CONTINUE;
             }
           });
  }
  return result;
}

代码示例来源:origin: org.kie.uberfire/kie-uberfire-runtime-plugins-backend

@Override
public Collection<DynamicMenu> listDynamicMenus() {
  final Collection<DynamicMenu> result = new ArrayList<DynamicMenu>();
  final Path plugins = fileSystem.getPath( "plugins", "/" );
  if ( ioService.exists( plugins ) ) {
    walkFileTree( checkNotNull( "root", plugins ),
           new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult visitFile( final Path file,
                              final BasicFileAttributes attrs ) throws IOException {
               try {
                 checkNotNull( "file", file );
                 checkNotNull( "attrs", attrs );
                 if ( file.getFileName().toString().equalsIgnoreCase( "info.dynamic" ) && attrs.isRegularFile() ) {
                   final String pluginName = file.getParent().getFileName().toString();
                   result.add( new DynamicMenu( pluginName, PluginType.DYNAMIC_MENU, convert( file.getParent() ), loadMenuItems( pluginName ) ) );
                 }
               } catch ( final Exception ex ) {
                 return FileVisitResult.TERMINATE;
               }
               return FileVisitResult.CONTINUE;
             }
           } );
  }
  return result;
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testWalkerDeep2() {
  final Path dir = newTempDir(null);
  final Path subDir = newTempDir(dir);
  final Path subSubDir = newTempDir(subDir);
  newTempDir(subSubDir);
  cleanupVisitor();
  Files.walkFileTree(dir,
            simple);
  assertThat(preDir.get()).isEqualTo(4);
  assertThat(postDir.get()).isEqualTo(4);
  assertThat(fileC.get()).isEqualTo(0);
  assertThat(failFile.get()).isEqualTo(0);
}

代码示例来源:origin: org.kie.workbench/kie-wb-common-cli-forms-migration

Files.walkFileTree(Paths.convert(workspaceProject.getRootPath()), new SimpleFileVisitor<org.uberfire.java.nio.file.Path>() {
  @Override
  public FileVisitResult visitFile(org.uberfire.java.nio.file.Path visitedPath, BasicFileAttributes attrs) throws IOException {

代码示例来源:origin: kiegroup/appformer

@Test
public void testWalker() {
  final Path dir = newTempDir(null);
  final Path file1 = Files.createTempFile(dir,
                      "foo",
                      "bar");
  Files.createTempFile(dir,
             "foo",
             "bar");
  cleanupVisitor();
  Files.walkFileTree(dir,
            simple);
  assertThat(preDir.get()).isEqualTo(1);
  assertThat(postDir.get()).isEqualTo(1);
  assertThat(fileC.get()).isEqualTo(2);
  assertThat(failFile.get()).isEqualTo(0);
  cleanupVisitor();
  Files.walkFileTree(file1,
            simple);
  assertThat(preDir.get()).isEqualTo(0);
  assertThat(postDir.get()).isEqualTo(0);
  assertThat(fileC.get()).isEqualTo(1);
  assertThat(failFile.get()).isEqualTo(0);
}

代码示例来源:origin: org.kie.workbench/kie-wb-common-cli-forms-migration

protected void readWorkspaceBPMNModels() {
  BPMNAnalyzer analyzer = new BPMNAnalyzer();
  Files.walkFileTree(Paths.convert(migrationContext.getWorkspaceProject().getRootPath()), new SimpleFileVisitor<Path>() {
    @Override
    public FileVisitResult visitFile(org.uberfire.java.nio.file.Path visitedPath, BasicFileAttributes attrs) throws IOException {
      org.uberfire.backend.vfs.Path visitedVFSPath = Paths.convert(visitedPath);
      String fileName = visitedVFSPath.getFileName();
      File file = visitedPath.toFile();
      if (file.isFile()) {
        if (fileName.endsWith("." + FormsMigrationConstants.BPMN_EXTENSION) || fileName.endsWith("." + FormsMigrationConstants.BPMN2_EXTENSION)) {
          try {
            BPMNProcess process = analyzer.read(migrationContext.getMigrationServicesCDIWrapper().getIOService().newInputStream(visitedPath));
            if (process != null) {
              workspaceBPMNFormModels.addAll(process.getFormModels());
            } else {
              migrationContext.getSystem().console().format(FormsMigrationConstants.BPMN_PARSING_ERROR, FormsMigrationConstants.WARNING, fileName);
            }
          } catch (Exception ex) {
            migrationContext.getSystem().console().format(FormsMigrationConstants.BPMN_PARSING_ERROR, FormsMigrationConstants.WARNING, fileName);
          }
        }
      }
      return FileVisitResult.CONTINUE;
    }
  });
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testWalkerDeep1() {
  final Path dir = newTempDir(null);
  final Path subDir = newTempDir(dir);
  final Path subSubDir = newTempDir(subDir);
  final Path subSubSubDir = newTempDir(subSubDir);
  Files.createTempFile(dir,
             "foo",
             "bar");
  Files.createTempFile(dir,
             "foo",
             "bar");
  cleanupVisitor();
  Files.walkFileTree(dir,
            simple);
  assertThat(preDir.get()).isEqualTo(4);
  assertThat(postDir.get()).isEqualTo(4);
  assertThat(fileC.get()).isEqualTo(2);
  assertThat(failFile.get()).isEqualTo(0);
}

代码示例来源:origin: org.dashbuilder/dashbuilder-dataset-cdi

public void deleteTempFiles() {
  Path tempPath = getTempPath();
  if (ioService.exists(tempPath)) {
    ioService.startBatch(fileSystem,
               new CommentedOption("system",
                         "Delete temporal files"));
    try {
      walkFileTree(tempPath,
             new SimpleFileVisitor<Path>() {
               @Override
               public FileVisitResult postVisitDirectory(Path dir,
                                    IOException exc) throws IOException {
                 Files.delete(dir);
                 return FileVisitResult.CONTINUE;
               }
               @Override
               public FileVisitResult visitFile(Path file,
                               BasicFileAttributes attrs) throws IOException {
                 Files.delete(file);
                 return FileVisitResult.CONTINUE;
               }
             });
    } finally {
      ioService.endBatch();
    }
  }
}

代码示例来源:origin: kiegroup/appformer

public void deleteTempFiles() {
  Path tempPath = getTempPath();
  if (ioService.exists(tempPath)) {
    ioService.startBatch(fileSystem,
               new CommentedOption("system",
                         "Delete temporal files"));
    try {
      walkFileTree(tempPath,
             new SimpleFileVisitor<Path>() {
               @Override
               public FileVisitResult postVisitDirectory(Path dir,
                                    IOException exc) throws IOException {
                 Files.delete(dir);
                 return FileVisitResult.CONTINUE;
               }
               @Override
               public FileVisitResult visitFile(Path file,
                               BasicFileAttributes attrs) throws IOException {
                 Files.delete(file);
                 return FileVisitResult.CONTINUE;
               }
             });
    } finally {
      ioService.endBatch();
    }
  }
}

相关文章