List of usage examples for java.nio.file DirectoryStream spliterator
default Spliterator<T> spliterator()
From source file:it.polimi.diceH2020.launcher.FileService.java
public Stream<Path> getBaseSolutionsPath() { String strDir = settings.getSolInstanceDir(); Path dir = FileSystems.getDefault().getPath(strDir); if (Files.notExists(dir)) { Path currentRelativePath = Paths.get(""); dir = FileSystems.getDefault() .getPath(currentRelativePath.toAbsolutePath().toString() + File.pathSeparator + strDir); }/*from ww w .ja v a2 s . co m*/ DirectoryStream<Path> stream; try { stream = Files.newDirectoryStream(dir, "*.{json}"); return StreamSupport.stream(stream.spliterator(), false); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:org.apache.storm.daemon.logviewer.utils.LogCleaner.java
/** * Return the last modified time for all log files in a worker's log dir. * Using stream rather than File.listFiles is to avoid large mem usage * when a directory has too many files.//from w w w .j a v a 2 s. com */ private long lastModifiedTimeWorkerLogdir(File logDir) { long dirModified = logDir.lastModified(); DirectoryStream<Path> dirStream = null; try { dirStream = directoryCleaner.getStreamForDirectory(logDir); } catch (IOException e) { return dirModified; } if (dirStream == null) { return dirModified; } try { return StreamSupport.stream(dirStream.spliterator(), false).reduce(dirModified, (maximum, path) -> { long curr = path.toFile().lastModified(); return curr > maximum ? curr : maximum; }, BinaryOperator.maxBy(Long::compareTo)); } catch (Exception ex) { LOG.error(ex.getMessage(), ex); return dirModified; } finally { if (DirectoryStream.class.isInstance(dirStream)) { IOUtils.closeQuietly(dirStream); } } }