List of usage examples for java.nio.file Files list
public static Stream<Path> list(Path dir) throws IOException
From source file:org.apache.geode.management.internal.cli.util.LogExporter.java
private List<Path> findFiles(Path workingDir, Predicate<Path> fileSelector) throws IOException { Stream<Path> selectedFiles/* = null */; if (!workingDir.toFile().isDirectory()) { return Collections.emptyList(); }/*from w w w . j ava 2s . c o m*/ selectedFiles = Files.list(workingDir).filter(fileSelector).filter(this.logFilter::acceptsFile); return selectedFiles.collect(toList()); }
From source file:com.facebook.buck.io.filesystem.impl.DefaultProjectFilesystemTest.java
@Test public void testSymlinkForceCanDeleteDirectory() throws IOException { Path realFileDir = Files.createDirectory(tmp.getRoot().resolve("realfile")); Files.createFile(realFileDir.resolve("file")); Files.createFile(realFileDir.resolve("file2")); Path symlinkDir = Files.createDirectory(tmp.getRoot().resolve("symlink")); Files.createFile(symlinkDir.resolve("junk")); filesystem.createSymLink(symlinkDir, realFileDir, true); try (Stream<Path> paths = Files.list(symlinkDir)) { List<Path> filesFound = paths.collect(Collectors.toList()); assertThat(filesFound, containsInAnyOrder(symlinkDir.resolve("file"), symlinkDir.resolve("file2"))); }// ww w . j a va 2s. co m }
From source file:org.ballerinalang.composer.service.workspace.local.LocalFSWorkspace.java
/** * {@inheritDoc}// w w w . ja va 2 s.c o m */ @Override public JsonArray listFilesInPath(String path, List<String> extensions) throws IOException { Path ioPath = Paths.get(path); JsonArray dirs = new JsonArray(); Iterator<Path> iterator = Files.list(ioPath).iterator(); while (iterator.hasNext()) { Path next = iterator.next(); if ((Files.isDirectory(next) || Files.isRegularFile(next)) && !Files.isHidden(next) && !isWindowsSystemFile(next)) { JsonObject jsnObj = getJsonObjForFile(next, true); if (Files.isRegularFile(next)) { Path fileName = next.getFileName(); SuffixFileFilter fileFilter = new SuffixFileFilter(extensions, IOCase.INSENSITIVE); if (null != fileName && fileFilter.accept(next.toFile())) { dirs.add(jsnObj); } } else { dirs.add(jsnObj); } } } return dirs; }
From source file:org.kalaider.desktop.scheduler.runner.Runner.java
private static URL[] getUrlsInDirectory(Path dir) throws Exception { try {// ww w . ja v a 2 s . co m dir = dir.toRealPath(); } catch (IOException ex) { LOG.fatal("Unable to access directory.", ex); return new URL[0]; } return Files.list(dir).collect(ArrayList::new, (list, path) -> { try { list.add(path.toUri().toURL()); } catch (MalformedURLException ex) { LOG.warn("Unable to create URL from path.", ex); } }, ArrayList::addAll).toArray(new URL[0]); }
From source file:com.fizzed.stork.deploy.Archive.java
static public void packEntry(ArchiveOutputStream aos, Path dirOrFile, String base, boolean appendName) throws IOException { String entryName = base;//from ww w . j a v a 2s . c om if (appendName) { if (!entryName.equals("")) { if (!entryName.endsWith("/")) { entryName += "/" + dirOrFile.getFileName(); } else { entryName += dirOrFile.getFileName(); } } else { entryName += dirOrFile.getFileName(); } } ArchiveEntry entry = aos.createArchiveEntry(dirOrFile.toFile(), entryName); if (Files.isRegularFile(dirOrFile)) { if (entry instanceof TarArchiveEntry && Files.isExecutable(dirOrFile)) { // -rwxr-xr-x ((TarArchiveEntry) entry).setMode(493); } else { // keep default mode } } aos.putArchiveEntry(entry); if (Files.isRegularFile(dirOrFile)) { Files.copy(dirOrFile, aos); aos.closeArchiveEntry(); } else { aos.closeArchiveEntry(); List<Path> children = Files.list(dirOrFile).collect(Collectors.toList()); if (children != null) { for (Path childFile : children) { packEntry(aos, childFile, entryName + "/", true); } } } }
From source file:com.qwazr.library.archiver.ArchiverTool.java
public void decompress_dir(final Path sourceDir, String sourceExtension, final Path destDir, final String destExtension) throws IOException, CompressorException { if (!Files.exists(sourceDir)) throw new FileNotFoundException("The source directory does not exist: " + sourceDir.toAbsolutePath()); if (!Files.exists(destDir)) throw new FileNotFoundException( "The destination directory does not exist: " + destDir.toAbsolutePath()); final Path[] sourceFiles; try (final Stream<Path> stream = Files.list(sourceDir)) { sourceFiles = stream.filter(p -> Files.isRegularFile(p)).toArray(Path[]::new); }/*from www . j a v a2 s . c om*/ if (sourceFiles == null) return; for (Path sourceFile : sourceFiles) { final String fileName = sourceFile.getFileName().toString(); final String ext = FilenameUtils.getExtension(fileName); if (!sourceExtension.equals(ext)) continue; String newName = FilenameUtils.getBaseName(fileName); if (destExtension != null) newName += '.' + destExtension; final Path destFile = destDir.resolve(newName); if (Files.exists(destFile)) continue; decompress(sourceFile, destFile); } }
From source file:org.esa.s2tbx.dataio.gdal.GDALInstaller.java
private static void fixUpPermissions(Path destPath) throws IOException { Stream<Path> files = Files.list(destPath); files.forEach(path -> {/* ww w .j a v a 2 s .co m*/ if (Files.isDirectory(path)) { try { fixUpPermissions(path); } catch (IOException e) { logger.log(Level.SEVERE, "GDAL configuration error: failed to fix permissions on " + path, e); } } else { setExecutablePermissions(path); } }); }
From source file:org.opendatakit.briefcase.reused.UncheckedFiles.java
public static Stream<Path> list(Path dir) { try {//from www. j ava 2s . c om return Files.list(dir); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.apache.flink.tests.util.FlinkDistribution.java
public Stream<String> searchAllLogs(Pattern pattern, Function<Matcher, String> matchProcessor) throws IOException { final List<String> matches = new ArrayList<>(2); try (Stream<Path> logFilesStream = Files.list(log)) { final Iterator<Path> logFiles = logFilesStream.iterator(); while (logFiles.hasNext()) { final Path logFile = logFiles.next(); if (!logFile.getFileName().toString().endsWith(".log")) { // ignore logs for previous runs that have a number suffix continue; }/*from w w w. j a va 2 s .c o m*/ try (BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(logFile.toFile()), StandardCharsets.UTF_8))) { String line; while ((line = br.readLine()) != null) { Matcher matcher = pattern.matcher(line); if (matcher.matches()) { matches.add(matchProcessor.apply(matcher)); } } } } } return matches.stream(); }
From source file:org.talend.dataprep.folder.store.file.FileSystemFolderRepository.java
@Override public void removeFolderEntry(String folderId, String contentId, FolderContentType contentType) { if (contentType == null) { throw new IllegalArgumentException( "The content type of the folder entry to be removed cannot be null."); }//from ww w.j a v a2s.c o m final FolderPath folderPath = fromId(folderId); try { Path path = pathsConverter.toPath(folderPath); try (Stream<Path> paths = Files.list(path)) { paths // .filter(pathFound -> !Files.isDirectory(pathFound)) // .filter(pathFile -> matches(pathFile, contentId, contentType)) // .forEach(deleteFile()); } } catch (IOException e) { throw new TDPException(UNABLE_TO_REMOVE_FOLDER_ENTRY, e, build().put("path", folderPath)); } }