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


Java SimpleFileVisitor类代码示例

本文整理汇总了Java中java.nio.file.SimpleFileVisitor的典型用法代码示例。如果您正苦于以下问题:Java SimpleFileVisitor类的具体用法?Java SimpleFileVisitor怎么用?Java SimpleFileVisitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleFileVisitor类属于java.nio.file包,在下文中一共展示了SimpleFileVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveConfig

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
static void resolveConfig(Environment env, final Settings.Builder settingsBuilder) {

        try {
            Files.walkFileTree(env.configFile(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    String fileName = file.getFileName().toString();
                    if (fileName.startsWith("logging.")) {
                        for (String allowedSuffix : ALLOWED_SUFFIXES) {
                            if (fileName.endsWith(allowedSuffix)) {
                                loadConfig(file, settingsBuilder);
                                break;
                            }
                        }
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ioe) {
            throw new ElasticsearchException("Failed to load logging configuration", ioe);
        }
    }
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:LogConfigurator.java

示例2: recursiveDelete

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
/**
 *
 * @param directory
 * @throws IOException
 */
public static void recursiveDelete(Path directory) throws IOException {
    Files.walkFileTree(directory, 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 exc) throws IOException {

            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}
 
开发者ID:CIRDLES,项目名称:Squid,代码行数:27,代码来源:FileUtilities.java

示例3: ArchiveContainer

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
    this.archivePath = archivePath;
    if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
        Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
        FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
        Assert.checkNonNull(jarFSProvider, "should have been caught before!");
        this.fileSystem = jarFSProvider.newFileSystem(archivePath, env);
    } else {
        this.fileSystem = FileSystems.newFileSystem(archivePath, null);
    }
    packages = new HashMap<>();
    for (Path root : fileSystem.getRootDirectories()) {
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                        if (isValid(dir.getFileName())) {
                            packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir);
                            return FileVisitResult.CONTINUE;
                        } else {
                            return FileVisitResult.SKIP_SUBTREE;
                        }
                    }
                });
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:JavacFileManager.java

示例4: close

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
@Override
public void close() {
    memory.clear();
    try {
        Files.walkFileTree(tmpDir, new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.deleteIfExists(file);
                return super.visitFile(file, attrs);
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.deleteIfExists(dir);
                return super.postVisitDirectory(dir, exc);
            }
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
开发者ID:kenzierocks,项目名称:HardVox,代码行数:23,代码来源:ChunkDataStore.java

示例5: deleteDirectory

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
/**
 * Deletes a directory recursively
 *
 * @param directory
 * @throws IOException
 */
public static void deleteDirectory(Path directory) throws IOException {
    Files.walkFileTree(directory, 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 exc) throws IOException {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:22,代码来源:Paths.java

示例6: deleteDirectory

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
/**
 * Deletes a directory recursively
 *
 * @param directory
 * @return true if deletion succeeds, false otherwise
 */
public static boolean deleteDirectory(Path directory) {
    if (directory != null) {
        try {
            Files.walkFileTree(directory, 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 exc) throws IOException {
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ignored) {
            return false;
        }
    }
    return true;
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:29,代码来源:FileUploadHelper.java

示例7: execute

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
@Override
public boolean execute() {
	File folder=CacheManager.getRootCacheInstance().getPath();
	//System.gc();
	try {
		Files.walkFileTree(folder.toPath(), 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 exc) throws IOException {
				   Files.delete(dir);
				   return FileVisitResult.CONTINUE;
			   }

		   });
	} catch (IOException e) {
		logger.error(e.getMessage());
		return false;
	}
   	super.notifyEvent(new SumoActionEvent(SumoActionEvent.ENDACTION,"cache cleaned...", -1));
	return true;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:27,代码来源:ClearCacheAction.java

示例8: collectFiles

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
private static void collectFiles(final Path dir, final String fileSuffix, final Map<String, Set<Path>> files) throws IOException {
    Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.toString().endsWith(fileSuffix)) {
                String groupName = dir.relativize(file.getParent()).toString();
                Set<Path> filesSet = files.get(groupName);
                if (filesSet == null) {
                    filesSet = new HashSet<>();
                    files.put(groupName, filesSet);
                }
                filesSet.add(file);
            }
            return FileVisitResult.CONTINUE;
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:FileUtils.java

示例9: checkLoggerUsage

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
private static void checkLoggerUsage(Consumer<WrongLoggerUsage> wrongUsageCallback, String... classDirectories)
    throws IOException {
    for (String classDirectory : classDirectories) {
        Path root = Paths.get(classDirectory);
        if (Files.isDirectory(root) == false) {
            throw new IllegalArgumentException(root + " should be an existing directory");
        }
        Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".class")) {
                    try (InputStream in = Files.newInputStream(file)) {
                        ESLoggerUsageChecker.check(wrongUsageCallback, in);
                    }
                }
                return super.visitFile(file, attrs);
            }
        });
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ESLoggerUsageChecker.java

示例10: deleteBlob

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
@Override
public void deleteBlob(String blobName) throws IOException {
    Path blobPath = path.resolve(blobName);
    if (Files.isDirectory(blobPath)) {
        // delete directory recursively as long as it is empty (only contains empty directories),
        // which is the reason we aren't deleting any files, only the directories on the post-visit
        Files.walkFileTree(blobPath, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
        });
    } else {
        Files.delete(blobPath);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:FsBlobContainer.java

示例11: removeDirectoryWithContent

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
public static void removeDirectoryWithContent(Path directory) throws IOException {
	if (Files.isDirectory(directory)) {
		Files.walkFileTree(directory, 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 exc) throws IOException {
				Files.delete(dir);
				return FileVisitResult.CONTINUE;
			}
		});
	}
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:18,代码来源:PathUtils.java

示例12: processSubevents

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
/**
 * Starts watching the subdirectories of the provided directory for changes.
 * @param root Root directory of the subdirectories to register.
 * @throws IOException If a subdirectory cannot be registered.
 * @checkstyle RequireThisCheck (20 lines)
 * @checkstyle NonStaticMethodCheck (20 lines)
 */
private void processSubevents(final Path root) throws IOException {
    try {
        Files.walkFileTree(
            root,
            new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(
                    final Path subdir,
                    final BasicFileAttributes attrs
                ) throws IOException {
                    registerDirectory(subdir);
                    return FileVisitResult.CONTINUE;
                }
            });
    } catch (final IOException ex) {
        throw new IOException("Failed to register subdirectories", ex);
    }
}
 
开发者ID:driver733,项目名称:VKMusicUploader,代码行数:26,代码来源:WatchDirs.java

示例13: indexDocs

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
static void indexDocs(final IndexWriter writer, Path path) throws IOException {
	if (Files.isDirectory(path)) {
		Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
				try {
					indexDoc(writer, file, attrs.lastModifiedTime().toMillis());
				} catch (IOException ignore) {
				}
				return FileVisitResult.CONTINUE;
			}
		}
				);
	} else {
		indexDoc(writer, path, Files.getLastModifiedTime(path).toMillis());
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:18,代码来源:IndexFiles.java

示例14: registerRecursively

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
private void registerRecursively(final Path directory) throws IOException {
    Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult preVisitDirectory(final Path visitedDirectory, final BasicFileAttributes attrs) throws IOException {
            if (!FileSystemWatcher.this.watchedFiles.matchesDirectory(visitedDirectory)) {
                return FileVisitResult.SKIP_SUBTREE;
            }


            final WatchKey key = visitedDirectory.register(watcher,
                    ENTRY_CREATE,
                    ENTRY_MODIFY,
                    ENTRY_DELETE);

            watchedPaths.put(key, visitedDirectory);

            return FileVisitResult.CONTINUE;
        }
    });
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:21,代码来源:FileSystemWatcher.java

示例15: testWalkFileTreeMultiple

import java.nio.file.SimpleFileVisitor; //导入依赖的package包/类
public void testWalkFileTreeMultiple() throws IOException {		
	final int ITERATIONS = 1000;
	Path newDirectory = WALKFILETREE_FILE_DIR;	
	for (int counter=0; counter< ITERATIONS; counter++) {		
		HangNotifier.ping();	
		final List<Path> visitorFiles = new LinkedList<Path>();		
		// Check that we keep returning the same set of files!
		Files.walkFileTree(newDirectory, new SimpleFileVisitor<Path>() {
			@Override
			public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) {
				if (path.toString().endsWith(".txt")) {
					visitorFiles.add(path);
				}
				return FileVisitResult.CONTINUE;
			}
		});

		if(!ReiserSpotter.getIsReiser()){
			assertEquals("Wrong number of files walked on iteration " + counter, NUMBER_OF_FILES, visitorFiles.size());
		}		
	}	
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:23,代码来源:WalkFileTreeTest.java


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