Refine search
private List<IOException> tryRemoveDirectoryContents(@Nonnull Path path) { Path normalized = path.normalize(); List<IOException> accumulatedErrors = new ArrayList<>(); if (!Files.isDirectory(normalized)) return accumulatedErrors; try (DirectoryStream<Path> children = Files.newDirectoryStream(normalized)) { for (Path child : children) { accumulatedErrors.addAll(tryRemoveRecursive(child)); } } catch (IOException e) { accumulatedErrors.add(e); } return accumulatedErrors; }
private static DirectoryStream<Path> list(Path dir) throws IOException { return Files.newDirectoryStream(dir, entry -> !DirectoryLock.LOCK_FILE_NAME.equals(entry.getFileName().toString())); } }
private void forEachTopologyDistDir(ConsumePathAndId consumer) throws IOException { Path stormCodeRoot = Paths.get(ConfigUtils.supervisorStormDistRoot(conf)); if (Files.exists(stormCodeRoot) && Files.isDirectory(stormCodeRoot)) { try (DirectoryStream<Path> children = Files.newDirectoryStream(stormCodeRoot)) { for (Path child : children) { if (Files.isDirectory(child)) { String topologyId = child.getFileName().toString(); consumer.accept(child, topologyId); } } } } }
@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; }
if (Files.isDirectory(path)) { try { try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { for (Path innerPath : stream) { boolean res = delete(innerPath); try { new JarFile(path.toString(), false).close();
/** * 复制目录 */ public static void copyDir(@NotNull Path from, @NotNull Path to) throws IOException { Validate.isTrue(isDirExists(from), "%s is not exist or not a dir", from); Validate.notNull(to); makesureDirExists(to); try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(from)) { for (Path path : dirStream) { copy(path, to.resolve(path.getFileName())); } } }
private void copyRecursively( Path source, Path target ) throws IOException { try ( DirectoryStream<Path> directoryStream = Files.newDirectoryStream( source ) ) { for ( Path sourcePath : directoryStream ) { Path targetPath = target.resolve( sourcePath.getFileName() ); if ( Files.isDirectory( sourcePath ) ) { Files.createDirectories( targetPath ); copyRecursively( sourcePath, targetPath ); } else { Files.copy( sourcePath, targetPath, REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES ); } } } }
static void processConfigOptions(String rootDir, String module, String packageName, String pathPrefix, ThrowingConsumer<Class<?>, IOException> classConsumer) throws IOException, ClassNotFoundException { Path configDir = Paths.get(rootDir, module, pathPrefix, packageName.replaceAll("\\.", "/")); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configDir)) { for (Path entry : stream) { String fileName = entry.getFileName().toString(); Matcher matcher = CLASS_NAME_PATTERN.matcher(fileName); if (matcher.matches()) { final String className = packageName + '.' + matcher.group(CLASS_NAME_GROUP); if (!EXCLUSIONS.contains(className)) { Class<?> optionsClass = Class.forName(className); classConsumer.accept(optionsClass); } } } } }
Preconditions.checkArgument(Files.isDirectory(dir), "%s is not a directory", dir); List<Path> newPaths = new ArrayList<>(); for (Path existingPath : paths) { if (Files.isDirectory(existingPath)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(existingPath, globLevel)) { for (Path path : stream) { if (!path.getFileName().toString().startsWith(".")) { newPaths.add(path);
@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; }
private static void findExamples( List<Path> examples, Path dir, DirectoryStream.Filter<Path> filter) throws IOException { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, filter)) { for (Path entry : stream) { if (Files.isDirectory(entry)) { findExamples(examples, entry, filter); } else { examples.add(entry); } } } }
/** * Parse all IGFS log files in specified log directory. * * @param logDir Folder were log files located. * @return List of line with aggregated information by files. */ private List<VisorIgfsProfilerEntry> parse(Path logDir, String igfsName) throws IOException { List<VisorIgfsProfilerEntry> parsedFiles = new ArrayList<>(512); try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(logDir)) { PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:igfs-log-" + igfsName + "-*.csv"); for (Path p : dirStream) { if (matcher.matches(p.getFileName())) { try { parsedFiles.addAll(parseFile(p)); } catch (NoSuchFileException ignored) { // Files was deleted, skip it. } catch (Exception e) { ignite.log().warning("Failed to parse IGFS profiler log file: " + p, e); } } } } return parsedFiles; }
if (Files.isDirectory(path)) { try (DirectoryStream<Path> files = Files.newDirectoryStream(path)) { for (Path file : files) { builder.append(file.getFileName()).append('\n');
public List<String> getBackups() { List<String> theFilenames = new ArrayList<String>(); Path dir = repositoryPath.getParent(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.{"+ fileExtension.substring(1) + "}")) { for (Path entry: stream) { theFilenames.add(entry.getFileName().toString()); } } catch (IOException x) { // IOException can never be thrown by the iteration. // In this snippet, it can // only be thrown by newDirectoryStream. log.warn("Issue getting directory listing for backups in directory: " + x.getMessage()); } return theFilenames; }
if (levels == 0) { try { stream = Files.newDirectoryStream(root, "*.xml"); iterator = stream.iterator(); } catch (IOException e) { } else { try { stream = Files.newDirectoryStream(root, entry -> { final String fileName = entry.getFileName().toString(); return fileName.length() == 1 && !fileName.equals(".") && Files.isDirectory(entry); }); iterator = stream.iterator();
private List<URL> jarsInDirectory(final Path directory) { final DirectoryStream.Filter<Path> pathFilter = entry -> Files.isRegularFile(entry) && entry.toString().endsWith(".jar"); try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, pathFilter)) { return StreamSupport.stream(stream.spliterator(), false) .filter(Files::isRegularFile) .map(this::toUrlSafe) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()); } catch (IOException e) { LOGGER.error("Could not load plugin: {}", e); return Collections.emptyList(); } }
/** * Insecure recursive delete for file systems that don't support {@code SecureDirectoryStream}. * Returns a collection of exceptions that occurred or null if no exceptions were thrown. */ private static @Nullable Collection<IOException> deleteRecursivelyInsecure(Path path) { Collection<IOException> exceptions = null; try { if (Files.isDirectory(path, NOFOLLOW_LINKS)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { exceptions = deleteDirectoryContentsInsecure(stream); } } // If exceptions is not null, something went wrong trying to delete the contents of the // directory, so we shouldn't try to delete the directory as it will probably fail. if (exceptions == null) { Files.delete(path); } return exceptions; } catch (IOException e) { return addException(exceptions, e); } }
@AfterClass public static void afterClass() throws Exception { long size = 0; try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(DIR))) { for (final Path path : directoryStream) { if (size == 0) { size = Files.size(path); } else { final long fileSize = Files.size(path); assertTrue("Expected size: " + size + " Size of " + path.getFileName() + ": " + fileSize, size == fileSize); } Files.delete(path); } Files.delete(Paths.get(DIR)); } }
@Override public List<Resource> list() { final List<Resource> resources = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) { for (Path child : stream) { resources.add(new PathResource(child, manager, path + file.getFileSystem().getSeparator() + child.getFileName().toString())); } } catch (IOException e) { throw new RuntimeException(e); } return resources; }
if ( !Files.isDirectory( pluginsDirectory ) || !Files.isReadable( pluginsDirectory ) ) try ( final DirectoryStream<Path> ds = Files.newDirectoryStream( pluginsDirectory, new DirectoryStream.Filter<Path>() final String fileName = jarFile.getFileName().toString(); final String canonicalPluginName = fileName.substring( 0, fileName.length() - 4 ).toLowerCase(); // strip extension. try ( final DirectoryStream<Path> ds = Files.newDirectoryStream( pluginsDirectory, new DirectoryStream.Filter<Path>() try ( final DirectoryStream<Path> ds = Files.newDirectoryStream( pluginsDirectory, new DirectoryStream.Filter<Path>() if ( Files.exists( devPluginPath ) && Files.isDirectory( devPluginPath ) )