當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。