private static void z2zmove(FileSystem src, FileSystem dst, String path) throws IOException { Path srcPath = src.getPath(path); Path dstPath = dst.getPath(path); if (Files.isDirectory(srcPath)) { if (!Files.exists(dstPath)) mkdirs(dstPath); try (DirectoryStream<Path> ds = Files.newDirectoryStream(srcPath)) { for (Path child : ds) { z2zmove(src, dst, path + (path.endsWith("/")?"":"/") + child.getFileName()); } } } else { //System.out.println("moving..." + path); Path parent = dstPath.getParent(); if (parent != null && Files.notExists(parent)) mkdirs(parent); Files.move(srcPath, dstPath); } }
public static List<String> findFilesByExtension(final List<String> fileNames, final Path dir, final String extension) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (final Path path : stream) { if (path.toFile().isDirectory()) { if (isBlackListedDirectory(path)) { continue; } findFilesByExtension(fileNames, path, extension); } else if (path.toAbsolutePath().toString().endsWith(extension)) { fileNames.add(path.toAbsolutePath().toString()); } } } catch (final IOException e) { log.log(Level.SEVERE, e.getMessage(), e); } return fileNames; }
@Override public String[] children(String f) { Path p = getPath(f); try (DirectoryStream<Path> dir = Files.newDirectoryStream(p)){ java.util.List<String> result = new ArrayList<>(); for (Path child : dir) { String name = child.getName(child.getNameCount() - 1).toString(); if (name.endsWith("/")) name = name.substring(0, name.length() - 1); result.add(name); } return result.toArray(new String[result.size()]); } catch (IOException ex) { return new String[0]; //huh? } }
public static void deleteHeapTempFiles() { if (Platform.isWindows()) { // this is workaroud for JDK bug #6359560 try { File tempDir = new File(System.getProperty("java.io.tmpdir")); // NOI18N DirectoryStream<Path> files = Files.newDirectoryStream(tempDir.toPath()); try { for (Path p : files) { String fname = p.toFile().getName(); if (fname.startsWith("NBProfiler") && (fname.endsWith(".map") || fname.endsWith(".ref") || fname.endsWith(".gc"))) { // NOI18N Files.delete(p); } } } finally { files.close(); } } catch (IOException ex) { System.err.println("deleteHeapTempFiles failed"); // NOI18N ex.printStackTrace(); } } }
/** * Recurse down a directory tree, checking all child directories. * @param dir * @throws DiskErrorException */ public static void checkDirs(File dir) throws DiskErrorException { checkDir(dir); IOException ex = null; try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(dir.toPath())) { for (java.nio.file.Path entry: stream) { File child = entry.toFile(); if (child.isDirectory()) { checkDirs(child); } } } catch (DirectoryIteratorException de) { ex = de.getCause(); } catch (IOException ie) { ex = ie; } if (ex != null) { throw new DiskErrorException("I/O error when open a directory: " + dir.toString(), ex); } }
/** * Return the complete list of files in a directory as strings.<p/> * * This is better than File#listDir because it does not ignore IOExceptions. * * @param dir The directory to list. * @param filter If non-null, the filter to use when listing * this directory. * @return The list of files in the directory. * * @throws IOException On I/O error */ public static List<String> listDirectory(File dir, FilenameFilter filter) throws IOException { ArrayList<String> list = new ArrayList<String> (); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir.toPath())) { for (Path entry: stream) { String fileName = entry.getFileName().toString(); if ((filter == null) || filter.accept(dir, fileName)) { list.add(fileName); } } } catch (DirectoryIteratorException e) { throw e.getCause(); } return list; }
/** * Scans the hunspell directory and loads all found dictionaries */ private void scanAndLoadDictionaries() throws IOException { if (Files.isDirectory(hunspellDir)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(hunspellDir)) { for (Path file : stream) { if (Files.isDirectory(file)) { try (DirectoryStream<Path> inner = Files.newDirectoryStream(hunspellDir.resolve(file), "*.dic")) { if (inner.iterator().hasNext()) { // just making sure it's indeed a dictionary dir try { dictionaries.getUnchecked(file.getFileName().toString()); } catch (UncheckedExecutionException e) { // The cache loader throws unchecked exception (see #loadDictionary()), // here we simply report the exception and continue loading the dictionaries logger.error("exception while loading dictionary {}", file.getFileName(), e); } } } } } } } }
private List<Path> getClassPaths(String cpaths) { if (cpaths.isEmpty()) { return Collections.emptyList(); } List<Path> paths = new ArrayList<>(); for (String p : cpaths.split(File.pathSeparator)) { if (p.length() > 0) { // wildcard to parse all JAR files e.g. -classpath dir/* int i = p.lastIndexOf(".*"); if (i > 0) { Path dir = Paths.get(p.substring(0, i)); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.jar")) { for (Path entry : stream) { paths.add(entry); } } catch (IOException e) { throw new UncheckedIOException(e); } } else { paths.add(Paths.get(p)); } } } return paths; }
@Test @SuppressWarnings("unchecked") public void doNothingWhenPathCannotBeParsed() throws Exception { mockStatic(Files.class); when(validator.isValid(path)).thenReturn(true); DirectoryStream<Path> directoryStream = mock(DirectoryStream.class); when(Files.newDirectoryStream(path, "*.xml")).thenReturn(directoryStream); Iterator<Path> iterator = mock(Iterator.class); when(directoryStream.iterator()).thenReturn(iterator); when(iterator.hasNext()).thenReturn(true, false); Path file = mock(Path.class); when(iterator.next()).thenReturn(file); when(xmlParser.parseXml(file)).thenReturn(Optional.empty()); scheduledFileReader.parseXmlFiles(); verifyZeroInteractions(service); verifyStatic(Files.class); Files.newDirectoryStream(path, "*.xml"); }
@Override public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException { // using MapBuilder and not ImmutableMap.Builder as it seems like File#listFiles might return duplicate files! MapBuilder<String, BlobMetaData> builder = MapBuilder.newMapBuilder(); blobNamePrefix = blobNamePrefix == null ? "" : blobNamePrefix; try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, blobNamePrefix + "*")) { for (Path file : stream) { final BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class); if (attrs.isRegularFile()) { builder.put(file.getFileName().toString(), new PlainBlobMetaData(file.getFileName().toString(), attrs.size())); } } } return builder.immutableMap(); }
/** * Returns the json files found within the directory provided as argument. * Files are looked up in the classpath, or optionally from {@code fileSystem} if its not null. */ public static Set<Path> findJsonSpec(FileSystem fileSystem, String optionalPathPrefix, String path) throws IOException { Path dir = resolveFile(fileSystem, optionalPathPrefix, path, null); if (!Files.isDirectory(dir)) { throw new NotDirectoryException(path); } Set<Path> jsonFiles = new HashSet<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path item : stream) { if (item.toString().endsWith(JSON_SUFFIX)) { jsonFiles.add(item); } } } if (jsonFiles.isEmpty()) { throw new NoSuchFileException(path, null, "no json files found"); } return jsonFiles; }
@Override public List<Node> getChildren() { if (!isDirectory()) throw new IllegalArgumentException("not a directory: " + getNameString()); if (children == null) { List<Node> list = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { for (Path p : stream) { p = explodedModulesDir.relativize(p); String pName = MODULES + nativeSlashToFrontSlash(p.toString()); Node node = findNode(pName); if (node != null) { // findNode may choose to hide certain files! list.add(node); } } } catch (IOException x) { return null; } children = list; } return children; }
/** * Returns all folder names in ${data.paths}/nodes/{node.id}/indices folder */ public Set<String> availableIndexFolders() throws IOException { if (nodePaths == null || locks == null) { throw new IllegalStateException("node is not configured to store local location"); } assertEnvIsLocked(); Set<String> indexFolders = new HashSet<>(); for (NodePath nodePath : nodePaths) { Path indicesLocation = nodePath.indicesPath; if (Files.isDirectory(indicesLocation)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(indicesLocation)) { for (Path index : stream) { if (Files.isDirectory(index)) { indexFolders.add(index.getFileName().toString()); } } } } } return indexFolders; }
private void cleanupOldFiles(final String prefix, final String currentStateFile, Path[] locations) throws IOException { final DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { final String entryFileName = entry.getFileName().toString(); return Files.isRegularFile(entry) && entryFileName.startsWith(prefix) // only state files && currentStateFile.equals(entryFileName) == false; // keep the current state file around } }; // now clean up the old files for (Path dataLocation : locations) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(dataLocation.resolve(STATE_DIR_NAME), filter)) { for (Path stateFile : stream) { Files.deleteIfExists(stateFile); } } } }
long findMaxStateId(final String prefix, Path... locations) throws IOException { long maxId = -1; for (Path dataLocation : locations) { final Path resolve = dataLocation.resolve(STATE_DIR_NAME); if (Files.exists(resolve)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(resolve, prefix + "*")) { for (Path stateFile : stream) { final Matcher matcher = stateFilePattern.matcher(stateFile.getFileName().toString()); if (matcher.matches()) { final long id = Long.parseLong(matcher.group(1)); maxId = Math.max(maxId, id); } } } } } return maxId; }
PollingWatchKey(Path dir, PollingWatchService watcher, Object fileKey) throws IOException { super(dir, watcher); this.fileKey = fileKey; this.valid = true; this.tickCount = 0; this.entries = new HashMap<Path,CacheEntry>(); // get the initial entries in the directory try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry: stream) { // don't follow links long lastModified = Files.getLastModifiedTime(entry, LinkOption.NOFOLLOW_LINKS).toMillis(); entries.put(entry.getFileName(), new CacheEntry(lastModified, tickCount)); } } catch (DirectoryIteratorException e) { throw e.getCause(); } }
/** Copies the files from {@code tmpBinDir} into {@code destBinDir}, along with permissions from dest dirs parent. */ private void installBin(PluginInfo info, Path tmpBinDir, Path destBinDir) throws Exception { if (Files.isDirectory(tmpBinDir) == false) { throw new UserException(ExitCodes.IO_ERROR, "bin in plugin " + info.getName() + " is not a directory"); } Files.createDirectory(destBinDir); setFileAttributes(destBinDir, BIN_DIR_PERMS); try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpBinDir)) { for (Path srcFile : stream) { if (Files.isDirectory(srcFile)) { throw new UserException( ExitCodes.DATA_ERROR, "Directories not allowed in bin dir for plugin " + info.getName() + ", found " + srcFile.getFileName()); } Path destFile = destBinDir.resolve(tmpBinDir.relativize(srcFile)); Files.copy(srcFile, destFile); setFileAttributes(destFile, BIN_FILES_PERMS); } } IOUtils.rm(tmpBinDir); // clean up what we just copied }
/** * 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. */ @Nullable private static 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); } }
private List<Path> findFilesToCorruptOnNode(final String nodeName, final ShardId shardId) throws IOException { List<Path> files = new ArrayList<>(); for (Path path : internalCluster().getInstance(NodeEnvironment.class, nodeName).availableShardPaths(shardId)) { path = path.resolve("index"); if (Files.exists(path)) { // multi data path might only have one path in use try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { for (Path item : stream) { if (item.getFileName().toString().startsWith("segments_")) { files.add(item); } } } } } return files; }
static void verifyInvokerBytecodeGenerator() throws Exception { int count = 0; int mcount = 0; try (DirectoryStream<Path> ds = newDirectoryStream(new File(".").toPath(), // filter in lambda proxy classes "A$I$$Lambda$?.class")) { for (Path p : ds) { System.out.println(p.toFile()); ClassFile cf = ClassFile.read(p.toFile()); // Check those methods implementing Supplier.get mcount += checkMethod(cf, "get"); count++; } } if (count < 3) { throw new RuntimeException("unexpected number of files, " + "expected atleast 3 files, but got only " + count); } if (mcount < 3) { throw new RuntimeException("unexpected number of methods, " + "expected atleast 3 methods, but got only " + mcount); } }
private List<Path> listFiles(Path sourceDirectory, DirectoryStream.Filter<Path> filter) { List<Path> files = new ArrayList<Path>(); try (DirectoryStream<Path> paths = (filter != null) ? Files.newDirectoryStream(sourceDirectory, filter) : Files.newDirectoryStream(sourceDirectory)) { for (Iterator<Path> it = paths.iterator(); it.hasNext();) { files.add(it.next()); } } catch (IOException e) { log.error(e.getMessage()); } return files; }
@Test(dataProvider = "packagesLinkedDirs") public void dirStreamPackagesDirTest(String dirName) throws IOException { FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); Path path = fs.getPath(dirName); int childCount = 0, dirPrefixOkayCount = 0; try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(path)) { for (Path child : dirStream) { childCount++; if (child.toString().startsWith(dirName)) { dirPrefixOkayCount++; } } } assertTrue(childCount != 0); assertEquals(dirPrefixOkayCount, childCount); }
public void testDirectoryStreamAllItems() throws IOException { Path newDirectory = DIRECTORY_STREAM_FILE_DIR; List<String> dirGlob = new LinkedList<String>(); DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory); try { for (Path path: directoryContents) { // Just check we aren't getting hidden files if (path.toString().endsWith("txt")) { dirGlob.add(path.toString()); } } } finally { directoryContents.close(); } if(!ReiserSpotter.getIsReiser()){ assertEquals("Checking for correct number of files return (no filter) found " + Arrays.toString(dirGlob.toArray()) + " actual total list is " + Arrays.toString(files.toArray()), NUMBER_OF_FILES, dirGlob.size()); } }
static void verifyInvokerBytecodeGenerator() throws Exception { int count = 0; int mcount = 0; try (DirectoryStream<Path> ds = newDirectoryStream(new File(".").toPath(), // filter in lambda proxy classes "A$I$$Lambda$*.class")) { for (Path p : ds) { System.out.println(p.toFile()); ClassFile cf = ClassFile.read(p.toFile()); // Check those methods implementing Supplier.get mcount += checkMethod(cf, "get"); count++; } } if (count < 3) { throw new RuntimeException("unexpected number of files, " + "expected atleast 3 files, but got only " + count); } if (mcount < 3) { throw new RuntimeException("unexpected number of methods, " + "expected atleast 3 methods, but got only " + mcount); } }
public void testDirectoryStreamGlobSomeItems() throws IOException { final int EXPECTED_NUMBER_OF_FILES = 1; Path newDirectory = DIRECTORY_STREAM_FILE_DIR; List<String> dirGlob = new LinkedList<String>(); DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory, "*1.txt"); try { for (Path path: directoryContents) { dirGlob.add(path.toString()); } } finally { directoryContents.close(); } if(!ReiserSpotter.getIsReiser()){ assertEquals("Checking for correct number of files return (globbed on ends in '1') found " + Arrays.toString(dirGlob.toArray()) + " actual total list is (from which we expect a subset)" + Arrays.toString(files.toArray()), EXPECTED_NUMBER_OF_FILES, dirGlob.size()); } }
public void testDirectoryStreamFilterAllItems() throws IOException { final int EXPECTED_NUMBER_OF_FILES = 10; Path newDirectory = DIRECTORY_STREAM_FILE_DIR; List<String> dirGlob = new LinkedList<String>(); DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory, new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { return true; } }); try { for (Path path: directoryContents) { dirGlob.add(path.toString()); } } finally { directoryContents.close(); } if(!ReiserSpotter.getIsReiser()){ assertEquals("Checking for correct number of files return (filtered on all) found " + Arrays.toString(dirGlob.toArray()) + " actual total list is " + Arrays.toString(files.toArray()), EXPECTED_NUMBER_OF_FILES, dirGlob.size()); } }
private List<Path> getDirectoryEntries(Path directory) throws IOException { List<Path> entries = new ArrayList<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) { for (Path entry : directoryStream) { if (Files.isDirectory(entry)) { List<Path> subEntries = getDirectoryEntries(entry); entries.addAll(subEntries); } else { entries.add(entry); } } } return entries; }
@Override Iterable<Set<Location>> listLocationsForModules() throws IOException { if (!listed && outputDir != null) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(outputDir)) { for (Path p : stream) { getLocationForModule(p.getFileName().toString()); } } listed = true; } if (moduleTable == null || moduleTable.isEmpty()) return Collections.emptySet(); return Collections.singleton(moduleTable.locations()); }
/** * Package accessible constructor. From configuration context it represents a single * <code>filegroup</code> and encapsulates the corresponding <code>filePattern</code>. * <code>filePattern</code> consists of two parts: first part has to be a valid path to an * existing parent directory, second part has to be a valid regex * {@link java.util.regex.Pattern} that match any non-hidden file names within parent directory * . A valid example for filePattern is <code>/dir0/dir1/.*</code> given * <code>/dir0/dir1</code> is an existing directory structure readable by the running user. * <p></p> * An instance of this class is created for each fileGroup * * @param fileGroup arbitrary name of the group given by the config * @param filePattern parent directory plus regex pattern. No wildcards are allowed in directory * name * @param cachePatternMatching default true, recommended in every setup especially with huge * parent directories. Don't set when local system clock is not used * for stamping mtime (eg: remote filesystems) * @see TaildirSourceConfigurationConstants */ TaildirMatcher(String fileGroup, String filePattern, boolean cachePatternMatching) { // store whatever came from configuration this.fileGroup = fileGroup; this.filePattern = filePattern; this.cachePatternMatching = cachePatternMatching; // calculate final members File f = new File(filePattern); this.parentDir = f.getParentFile(); String regex = f.getName(); final PathMatcher matcher = FS.getPathMatcher("regex:" + regex); this.fileFilter = new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { return matcher.matches(entry.getFileName()) && !Files.isDirectory(entry); } }; // sanity check Preconditions.checkState(parentDir.exists(), "Directory does not exist: " + parentDir.getAbsolutePath()); }
private static Map<String, String> listFormulare(String directory) { Map<String, String> files = new HashMap<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(directory))) { for (Path path : directoryStream) { files.put(path.getFileName().toString(), path.toAbsolutePath().toString()); // TODO change sout to logger System.out.println(path.toAbsolutePath().toString()); } } catch (IOException ex) { logger.error(ex); throw new VaVedemEmailException("Eroare la citire formular"); } return files; }
private static void applyScripts(CQLDataLoader dataLoader, String cqlDir, String pattern) throws IOException, URISyntaxException { URL dirUrl = ClassLoader.getSystemResource(cqlDir); if (dirUrl == null) { // protect for empty directory return; } List<String> scripts = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(dirUrl.toURI()), pattern)) { for (Path entry : stream) { scripts.add(entry.getFileName().toString()); } } Collections.sort(scripts); for (String fileName : scripts) { dataLoader.load(new ClassPathCQLDataSet(cqlDir + fileName, false, false, CASSANDRA_UNIT_KEYSPACE)); } }
public File addMultimedia(File incoming){ try{ DirectoryStream<Path> stream = Files.newDirectoryStream(new File(multimediaLocation).toPath()); List<Integer> files = new ArrayList<Integer>(); for(Path f: stream){ try{ files.add(Integer.parseInt(f.getFileName().toString().substring(0, f.getFileName().toString().lastIndexOf(".")))); }catch(NumberFormatException e){ log.error(e); } } // sort our list so that we can put it back. int max=0; for(Integer i: files){ if(i > max){ max = i; } } log.debug("Incomin file name on add multimedia: " + incoming.getName()); String incomingFileEnd = incoming.getName().substring(incoming.getName().lastIndexOf(".")); File saved = null; saved = copyFile(incoming, new File(multimediaLocation + String.valueOf(max + 1) + incomingFileEnd)); return saved; }catch(IOException ex){ log.error(ex); return null; } }
@Override @FromAnyThread public @Nullable Array<ResourceElement> getChildren(@NotNull final Array<String> extensionFilter, final boolean onlyFolders) { if (!Files.isDirectory(file)) return null; final Array<ResourceElement> elements = ArrayFactory.newArray(ResourceElement.class); try (final DirectoryStream<Path> stream = Files.newDirectoryStream(file)) { stream.forEach(child -> { final String fileName = child.getFileName().toString(); if (fileName.startsWith(".")) { return; } else if (Files.isDirectory(child)) { elements.add(createFor(child)); return; } if (onlyFolders) return; final String extension = FileUtils.getExtension(child); if (extensionFilter.isEmpty() || extensionFilter.contains(extension)) { elements.add(createFor(child)); } }); } catch (final IOException e) { LOGGER.warning(this, e); } return elements; }
@SuppressWarnings("unchecked") protected DirectoryStream<Path> mockDirectoryStream(Path root, List<Path> entries) throws IOException { DirectoryStream<Path> directoryStream = mock(DirectoryStream.class); when(directoryStream.iterator()).thenAnswer((inv) -> entries.iterator()); when(directoryStream.spliterator()).thenAnswer((inv) -> entries.spliterator()); when(root.getFileSystem().provider().newDirectoryStream(eq(root), any())).thenReturn(directoryStream); return directoryStream; }
@Override public List<Path> getChildPaths() { List<Path> childPaths = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path childPath : stream) { childPaths.add(childPath); } } catch (IOException e) { throw new UncheckedIOException(e); } return childPaths; }
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException { triggerEx(dir, "newDirectoryStream"); return wrap(Files.newDirectoryStream(unwrap(dir), filter)); }
/** * @param path The path to scan * @return The direct subdiretories of the provided path */ public static List<Path> subDirectories(Path path) { List<Path> directories = new ArrayList<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path)) { for (Path subPath : directoryStream) { if (!Files.isDirectory(subPath)) { continue; } directories.add(subPath); } } catch (IOException e) { throw new RuntimeException(e); } return directories; }
private long countSubDirs(Path path) throws IOException { try (DirectoryStream<Path> ds = Files.newDirectoryStream(path, Files::isDirectory)) { return Iterables.size(ds); } catch (DirectoryIteratorException e) { throw new IOException(e); } }
@Scheduled(fixedDelayString = "${checking-parameters.processing-interval}") public void parseXmlFiles() { Path path = Paths.get(inputDirectory); if (pathValidator.isValid(path)) { log.debug("Checking directory: {}", path); try (DirectoryStream<Path> stream = getDirectory(path)) { for (Path file : stream) { xmlParser.parseXml(file).ifPresent(service::insertDoc); } } catch (Exception e) { log.error("XML file has invalid format", e); } } }