@NotNull private List<String> listDirectory(Path path) throws IOException { List<String> result = new ArrayList<>(); Files.newDirectoryStream(path, filter) .forEach(x -> result.add(x.toString())); return result; }
@NotNull private List<String> listParentDirectory(Path path) throws IOException { List<String> result = new ArrayList<>(); Path parent = path.getParent(); Files.newDirectoryStream(parent, p -> { if (p.toString().startsWith(path.toString())) { if (p.toFile().isFile()) { return p.toString().endsWith(".jar"); } return true; } return false; }).forEach(x -> result.add(x.toString())); return result; }
public static void eachEbinPath(@NotNull String homePath, @NotNull Consumer<Path> ebinPathConsumer) { Path lib = Paths.get(homePath, "lib"); try (DirectoryStream<Path> libDirectoryStream = Files.newDirectoryStream(lib, path -> Files.isDirectory(path))) { libDirectoryStream.forEach( app -> { try (DirectoryStream<Path> ebinDirectoryStream = Files.newDirectoryStream(app, "ebin")) { ebinDirectoryStream.forEach(ebinPathConsumer); } catch (IOException ioException) { LOGGER.error(ioException); } } ); } catch (IOException ioException) { LOGGER.error(ioException); } }
private static void cleanupOldSpillFiles(Path path) { try (DirectoryStream<Path> stream = newDirectoryStream(path, SPILL_FILE_GLOB)) { stream.forEach(spillFile -> { try { log.info("Deleting old spill file: " + spillFile); delete(spillFile); } catch (Exception e) { log.warn("Could not cleanup old spill file: " + spillFile); } }); } catch (IOException e) { log.warn(e, "Error cleaning spill files"); } }
/** * @param annotation The annotation * @param classes The classes * @param file The file */ protected void traverseFile(String annotation, List<Class> classes, File file) { if (file.isDirectory()) { try (DirectoryStream<Path> dirs = Files.newDirectoryStream(file.toPath())) { dirs.forEach(path -> { File f = path.toFile(); if (f.isDirectory()) { traverseFile(annotation, classes, f); } else { scanFile(annotation, f, classes); } }); } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring directory [" + file + "] due to I/O error: " + e.getMessage(), e); } } } else { scanFile(annotation, file, classes); } }
public static Offloaders searchForOffloaders(String connectorsDirectory) throws IOException { Path path = Paths.get(connectorsDirectory).toAbsolutePath(); log.info("Searching for offloaders in {}", path); Offloaders offloaders = new Offloaders(); if (!path.toFile().exists()) { log.warn("Offloaders archive directory not found"); return offloaders; } try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, "*.nar")) { stream.forEach(archive -> { try { OffloaderDefinition definition = getOffloaderDefinition(archive.toString()); log.info("Found offloader {} from {}", definition, archive); if (!StringUtils.isEmpty(definition.getOffloaderFactoryClass())) { // Validate offloader factory class to be present and of the right type Pair<NarClassLoader, LedgerOffloaderFactory> offloaderFactoryPair = getOffloaderFactory(archive.toString()); if (null != offloaderFactoryPair) { offloaders.getOffloaders().add(offloaderFactoryPair); } } } catch (Throwable t) { log.warn("Failed to load offloader from {}", archive, t); } }); } log.info("Found and loaded {} offloaders", offloaders.getOffloaders().size()); return offloaders; }
private void deleteTempPacksIdx() { Path packDir = repo.getObjectDatabase().getPackDirectory().toPath(); Instant threshold = Instant.now().minus(1, ChronoUnit.DAYS); if (!Files.exists(packDir)) { return; } try (DirectoryStream<Path> stream = Files.newDirectoryStream(packDir, "gc_*_tmp")) { //$NON-NLS-1$ stream.forEach(t -> { try { Instant lastModified = Files.getLastModifiedTime(t) .toInstant(); if (lastModified.isBefore(threshold)) { Files.deleteIfExists(t); } } catch (IOException e) { LOG.error(e.getMessage(), e); } }); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
private List<Path> getZipFiles() throws IOException { List<Path> files = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, JavadocDaoUncached::isZipFile)) { stream.forEach(files::add); } return files; }
/** * Glob files using the real glob pattern. */ public static List<Path> globFiles(Path rootFolder, String glob) { ArrayList<Path> paths = new ArrayList<>(); try { Files.newDirectoryStream(rootFolder, glob).forEach(paths::add); } catch (IOException ignored) {} return paths; }
private static void doFilterAndPrintPath(Predicate<Path> pred) { try { newDirectoryStream(PATH).forEach(p -> { if (pred.test(p)) { out.println(p.getFileName()); } }); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); } }
private void doFilterAndPrintPath(Predicate<Path> pred) { try { newDirectoryStream(path).forEach(p -> { if (pred.test(p)) { out.println(p.getFileName()); } }); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } }
private static List<File> getLibs(Path dir) throws IOException { Filter<Path> filter = path -> { String name = path.getFileName().toString(); return name.endsWith(".jar") || name.endsWith(".zip") || name.endsWith(".aar"); }; List<File> files = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) { stream.forEach(p -> files.add(p.toFile())); } return files; }
private static List<File> getLibs(Path dir) throws IOException { Filter<Path> filter = path -> { String name = path.getFileName().toString(); return name.endsWith(".jar") || name.endsWith(".zip") || name.endsWith(".aar"); }; List<File> files = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) { stream.forEach(p -> files.add(p.toFile())); } return files; }
@VisibleForTesting List<String> getFileNamesMatchingPattern(Path directory, String matcherPattern) throws IOException { final List<String> files = new ArrayList<>(); final PathMatcher pathMatcher = FileSystems.getDefault() .getPathMatcher(matcherPattern); try (DirectoryStream<Path> dirStream = Files.newDirectoryStream( directory, pathMatcher::matches)) { dirStream.forEach(filePath -> files.add(filePath.getFileName().toString())); } files.sort(Comparator.naturalOrder()); return files; }
/** Return the filenames of all matching files in the configuration directory (absolute paths returned ). */ public static List<String> existingConfigurationFile(String baseFilename) { try { List<String> paths = new ArrayList<>() ; try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiWebapp.dirConfiguration, baseFilename+".*") ) { stream.forEach((p)-> paths.add(FusekiWebapp.dirConfiguration.resolve(p).toString() )); } return paths ; } catch (IOException ex) { throw new InternalErrorException("Failed to read configuration directory "+FusekiWebapp.dirConfiguration) ; } } }
public Collection<Integer> getI2CBuses() { try { List<Integer> i2c_buses = new ArrayList<>(); Files.newDirectoryStream(Paths.get("/dev"), "i2c-*") .forEach(path -> i2c_buses.add(Integer.valueOf(path.toString().split("-")[1]))); return i2c_buses; } catch (IOException e) { Logger.error(e, "Error: {}", e); return null; } }
public static void clearDirectory(String path) throws IOException { Path directory = Paths.get(path); Files.newDirectoryStream(directory).forEach(file -> { try { if (Files.isDirectory(file)) { clearDirectory(file.toAbsolutePath().toString()); } Files.delete(file); } catch (IOException e) { throw new UncheckedIOException(e); } }); }
/** Return the filenames of all matching files in the configuration directory (absolute paths returned ). */ public static List<String> existingConfigurationFile(String baseFilename) { try { List<String> paths = new ArrayList<>() ; try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiWebapp.dirConfiguration, baseFilename+".*") ) { stream.forEach((p)-> paths.add(FusekiWebapp.dirConfiguration.resolve(p).toString() )); } return paths ; } catch (IOException ex) { throw new InternalErrorException("Failed to read configuration directory "+FusekiWebapp.dirConfiguration) ; } } }
public NetConfig(String v2Path) throws IOException { Files.newDirectoryStream(Paths.get(v2Path), path -> path.toString().endsWith(".yaml")) .forEach(fileName-> { addNode(NodeInfo.loadYaml(fileName)); }); }
@Nonnull private ArrayList<URI> resolveLogsURIs() { final ArrayList<URI> uris = new ArrayList<>(); try { Path logDir = resolveLogDirPath(); DirectoryStream<Path> children = Files.newDirectoryStream(logDir); children.forEach(path -> uris.add(path.toUri())); children.close(); } catch (IOException ex) { getLogger().error(ex.getMessage(), ex); } return uris; }