From 3fc8bc00f11a32ee20d7aa4ad0615868d8aab684 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Wed, 20 Jan 2016 09:12:14 -0500 Subject: [PATCH] NIFI-1414: Ensure that the DirectoryStream is closed after streaming contents of a directory Signed-off-by: Matt Gilman --- .../nifi/processors/standard/TailFile.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java index 3d6d3a05af..626f7a44ae 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java @@ -535,21 +535,22 @@ public class TailFile extends AbstractProcessor { } final List rolledOffFiles = new ArrayList<>(); - final DirectoryStream dirStream = Files.newDirectoryStream(directory.toPath(), rollingPattern); - for (final Path path : dirStream) { - final File file = path.toFile(); - final long lastMod = file.lastModified(); + try (final DirectoryStream dirStream = Files.newDirectoryStream(directory.toPath(), rollingPattern)) { + for (final Path path : dirStream) { + final File file = path.toFile(); + final long lastMod = file.lastModified(); - if (file.lastModified() < minTimestamp) { - getLogger().debug("Found rolled off file {} but its last modified timestamp is before the cutoff (Last Mod = {}, Cutoff = {}) so will not consume it", - new Object[] {file, lastMod, minTimestamp}); + if (file.lastModified() < minTimestamp) { + getLogger().debug("Found rolled off file {} but its last modified timestamp is before the cutoff (Last Mod = {}, Cutoff = {}) so will not consume it", + new Object[] {file, lastMod, minTimestamp}); - continue; - } else if (file.equals(tailFile)) { - continue; + continue; + } else if (file.equals(tailFile)) { + continue; + } + + rolledOffFiles.add(file); } - - rolledOffFiles.add(file); } // Sort files based on last modified timestamp. If same timestamp, use filename as a secondary sort, as often