本文整理匯總了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);
}
}
示例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;
}
});
}
示例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;
}
}
});
}
}
示例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);
}
}
示例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;
}
});
}
示例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;
}
示例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;
}
示例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;
}
});
}
示例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);
}
});
}
}
示例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);
}
}
示例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;
}
});
}
}
示例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);
}
}
示例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());
}
}
示例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;
}
});
}
示例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());
}
}
}