本文整理了Java中java.nio.file.Files.find()
方法的一些代码示例,展示了Files.find()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.find()
方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:find
暂无
代码示例来源:origin: apache/nifi
protected Stream<Path> getPathStream(final Path basePath, final int maxDepth, final BiPredicate<Path, BasicFileAttributes> matcher) throws IOException {
return Files.find(basePath, maxDepth, matcher, FileVisitOption.FOLLOW_LINKS);
}
代码示例来源:origin: Vedenin/useful-java-links
Stream<Path> streamFromFind = Files.find(Paths.get(""), 10, (p,a) -> true);
System.out.println("streamFromFind = " + streamFromFind.collect(Collectors.toList())); // print list of files
代码示例来源:origin: OpenHFT/Chronicle-Queue
@Test
public void testToEndOnDeletedQueueFiles() throws IOException {
if (OS.isWindows()) {
System.err.println("#460 Cannot test delete after close on windows");
return;
}
File dir = getTmpDir();
try (ChronicleQueue q = builder(dir, wireType).build()) {
ExcerptAppender append = q.acquireAppender();
append.writeDocument(w -> w.write(() -> "test").text("before text"));
ExcerptTailer tailer = q.createTailer();
// move to the end even though it doesn't exist yet.
tailer.toEnd();
append.writeDocument(w -> w.write(() -> "test").text("text"));
assertTrue(tailer.readDocument(w -> w.read(() -> "test").text("text", Assert::assertEquals)));
Files.find(dir.toPath(), 1, (p, basicFileAttributes) -> p.toString().endsWith("cq4"), FileVisitOption.FOLLOW_LINKS)
.forEach(path -> assertTrue(path.toFile().delete()));
ChronicleQueue q2 = builder(dir, wireType).build();
tailer = q2.createTailer();
tailer.toEnd();
assertEquals(TailerState.UNINITIALISED, tailer.state());
append = q2.acquireAppender();
append.writeDocument(w -> w.write(() -> "test").text("before text"));
assertTrue(tailer.readDocument(w -> w.read(() -> "test").text("before text", Assert::assertEquals)));
}
}
代码示例来源:origin: google/bundletool
/** Tries to locate adb utility under "platform-tools". */
public Optional<Path> locateAdb(Path sdkDir) {
Path platformToolsDir = sdkDir.resolve("platform-tools");
if (!Files.isDirectory(platformToolsDir)) {
return Optional.empty();
}
// Expecting to find one entry.
try (Stream<Path> pathStream =
Files.find(
platformToolsDir,
/* maxDepth= */ 1,
(path, attributes) -> adbPathMatcher.matches(path) && Files.isExecutable(path))) {
return pathStream.findFirst();
} catch (IOException e) {
throw CommandExecutionException.builder()
.withCause(e)
.withMessage("Error while trying to locate adb in SDK dir '%s'.", sdkDir)
.build();
}
}
}
代码示例来源:origin: google/bundletool
try (Stream<Path> aapt2Binaries = Files.find(outputDir, /* maxDepth= */ 3, AAPT2_MATCHER)) {
aapt2 = aapt2Binaries.collect(onlyElement());
Files.find(Paths.get(osDirUrl.toURI()), /* maxDepth= */ 3, AAPT2_MATCHER)) {
Optional<Path> aapt2Path = aapt2Binaries.findFirst();
if (!aapt2Path.isPresent()) {
代码示例来源:origin: aws/aws-sdk-java-v2
private Stream<Path> findModelRoots() throws MojoExecutionException {
try {
return Files.find(codeGenResources.toPath(), 10, this::isModelFile)
.map(Path::getParent)
.sorted(this::modelSharersLast);
} catch (IOException e) {
throw new MojoExecutionException("Failed to find '" + MODEL_FILE + "' files in " + codeGenResources, e);
}
}
代码示例来源:origin: io.thorntail/tools
private static synchronized void find(File moduleDir, DependencyManager dependencyManager) throws IOException {
Files.find(moduleDir.toPath(), 20,
(p, __) -> p.getFileName().toString().equals("module.xml"))
.forEach(dependencyManager::addAdditionalModule);
}
代码示例来源:origin: org.eclipse.che.core/che-core-api-installer
private List<Path> findInstallersDescriptors(Path dir) {
try {
return Files.find(dir, 1, (path, basicFileAttributes) -> path.toString().endsWith(".json"))
.collect(Collectors.toList());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
代码示例来源:origin: OpenNMS/opennms
private List<File> getRulesFiles() throws IOException {
final Path droolsRulesRoot = rulesFolder.toPath();
if (!droolsRulesRoot.toFile().isDirectory()) {
throw new IllegalStateException("Expected to find Drools rules for alarmd in '" + droolsRulesRoot
+ "' but the path is not a directory! Aborting.");
}
return Files.find(droolsRulesRoot, 3, (path, attrs) -> attrs.isRegularFile()
&& path.toString().endsWith(".drl"))
.map(Path::toFile)
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());
}
代码示例来源:origin: org.opennms/opennms-alarmd
private List<File> getRulesFiles() throws IOException {
final Path droolsRulesRoot = rulesFolder.toPath();
if (!droolsRulesRoot.toFile().isDirectory()) {
throw new IllegalStateException("Expected to find Drools rules for alarmd in '" + droolsRulesRoot
+ "' but the path is not a directory! Aborting.");
}
return Files.find(droolsRulesRoot, 3, (path, attrs) -> attrs.isRegularFile()
&& path.toString().endsWith(".drl"))
.map(Path::toFile)
.sorted(Comparator.naturalOrder())
.collect(Collectors.toList());
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-engine
/**
* Collect all the files in a directory and its subdirectories
*
* @param dir directory
*/
private List<String> getFilesInDirectory(final Path dir) throws IOException {
final List<String> paths = new ArrayList<>();
final BiPredicate<Path, BasicFileAttributes> matcher =
(filePath, fileAttr) -> fileAttr.isRegularFile();
Files.find(dir, Integer.MAX_VALUE, matcher).forEachOrdered(p -> paths.add(p.toString()));
return paths;
}
}
代码示例来源:origin: kousen/java_8_recipes
public static void main(String[] args) {
try (Stream<Path> paths = Files.find(Paths.get("src/main/java"), Integer.MAX_VALUE,
(path, attributes) -> !attributes.isDirectory() && path.toString().contains("fileio"))) {
paths.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: com.yahoo.vespa/filedistribution
public static File compress(File directory, File outputFile) throws IOException {
return compress(directory, Files.find(Paths.get(directory.getAbsolutePath()),
recurseDepth,
(p, basicFileAttributes) -> basicFileAttributes.isRegularFile())
.map(Path::toFile).collect(Collectors.toList()), outputFile);
}
代码示例来源:origin: com.yahoo.vespa/filedistribution
public static byte[] compress(File directory) throws IOException {
return compress(directory, Files.find(Paths.get(directory.getAbsolutePath()),
recurseDepth,
(p, basicFileAttributes) -> basicFileAttributes.isRegularFile())
.map(Path::toFile).collect(Collectors.toList()));
}
代码示例来源:origin: com.github.robozonky/robozonky-common
public static Optional<File> findFolder(final String folderName) {
final Path root = new File(System.getProperty("user.dir")).toPath();
return Try.withResources(() -> Files.find(root, 1, (path, attr) -> attr.isDirectory()))
.of(s -> s.map(Path::toFile)
.filter(f -> Objects.equals(f.getName(), folderName))
.findFirst())
.getOrElseGet(ex -> {
FileUtil.LOGGER.warn("Exception while walking file tree.", ex);
return Optional.empty();
});
}
代码示例来源:origin: RoboZonky/robozonky
public static Optional<File> findFolder(final String folderName) {
final Path root = new File(System.getProperty("user.dir")).toPath();
return Try.withResources(() -> Files.find(root, 1, (path, attr) -> attr.isDirectory()))
.of(s -> s.map(Path::toFile)
.filter(f -> Objects.equals(f.getName(), folderName))
.findFirst())
.getOrElseGet(ex -> {
LOGGER.warn("Exception while walking file tree.", ex);
return Optional.empty();
});
}
代码示例来源:origin: de.unijena.bioinf.ms/gibbs_sampling
public static Map<String, List<FragmentsCandidate>> parseMFCandidatesEval(Path treeDir, Path mgfFile, int maxCandidates, int workercount, boolean ignoreSilicon) throws IOException {
System.out.println(treeDir.toString());
Path[] trees = Files.find(treeDir, 2, (path, basicFileAttributes) -> path.toString().endsWith(".json")).toArray(s -> new Path[s]);
System.out.println("number "+trees.length);
final MsExperimentParser parser = new MsExperimentParser();
List<Ms2Experiment> allExperiments = parser.getParser(mgfFile.toFile()).parseFromFile(mgfFile.toFile());
Ms2Dataset dataset = new MutableMs2Dataset(allExperiments, "default", Double.NaN, (new Sirius("default")).getMs2Analyzer().getDefaultProfile());
Ms2DatasetPreprocessor preprocessor = new Ms2DatasetPreprocessor(true);
dataset = preprocessor.preprocess(dataset);
// return parseMFCandidates(trees, allExperiments, maxCandidates, workercount, ignoreSilicon);
return parseMFCandidatesEval(trees, dataset.getExperiments(), maxCandidates, workercount, ignoreSilicon);
}
代码示例来源:origin: de.unijena.bioinf.ms/gibbs_sampling
public static Map<String, List<FragmentsCandidate>> parseMFCandidates(Path treeDir, Path mgfFile, int maxCandidates, int workercount, boolean ignoreSilicon) throws IOException {
System.out.println(treeDir.toString());
Path[] trees = Files.find(treeDir, 2, (path, basicFileAttributes) -> path.toString().endsWith(".json")).toArray(s -> new Path[s]);
final MsExperimentParser parser = new MsExperimentParser();
List<Ms2Experiment> allExperiments = parser.getParser(mgfFile.toFile()).parseFromFile(mgfFile.toFile());
Ms2Dataset dataset = new MutableMs2Dataset(allExperiments, "default", Double.NaN, (new Sirius("default")).getMs2Analyzer().getDefaultProfile());
Ms2DatasetPreprocessor preprocessor = new Ms2DatasetPreprocessor(true);
dataset = preprocessor.preprocess(dataset);
// return parseMFCandidates(trees, allExperiments, maxCandidates, workercount, ignoreSilicon);
return parseMFCandidates(trees, dataset.getExperiments(), maxCandidates, workercount, ignoreSilicon);
}
代码示例来源:origin: apache/archiva
protected List<ArtifactMetadata> getArtifactMetadataFromDir( String repoId, String projectName, Path repoDir, Path vDir ) throws IOException
{
Maven2RepositoryPathTranslator translator = new Maven2RepositoryPathTranslator( new ArrayList<>( ) );
return Files.find(vDir, 1,
(path, basicFileAttributes) -> basicFileAttributes.isRegularFile() && path.getFileName().toString().startsWith(projectName))
.map( path ->
translator.getArtifactForPath( repoId, repoDir.relativize( path ).toString() )
).collect( Collectors.toList());
}
}
代码示例来源:origin: EvoSuite/evosuite
private void verifyLogFilesExist(Path targetProject, String className) throws Exception{
Path dir = getESFolder(targetProject);
Path tmp = Files.find(dir,1, (p,a) -> p.getFileName().toString().startsWith("tmp_")).findFirst().get();
Path logs = tmp.resolve("logs").resolve(className);
assertTrue(Files.exists(logs.resolve("std_err_CLIENT.log")));
assertTrue(Files.exists(logs.resolve("std_err_MASTER.log")));
assertTrue(Files.exists(logs.resolve("std_out_CLIENT.log")));
assertTrue(Files.exists(logs.resolve("std_out_MASTER.log")));
}
内容来源于网络,如有侵权,请联系作者删除!