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); }
Stream<Path> streamFromFind = Files.find(Paths.get(""), 10, (p,a) -> true); System.out.println("streamFromFind = " + streamFromFind.collect(Collectors.toList())); // print list of files
@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))); } }
/** 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(); } } }
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); } }
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); }
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); } }
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()); }
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()); }
/** * 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; } }
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(); } } }
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); }
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())); }
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(); }); }
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(); }); }
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); }
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); }
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()); } }
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"))); }