diff --git a/iped-utils/src/main/java/iped/utils/FileInputStreamFactory.java b/iped-utils/src/main/java/iped/utils/FileInputStreamFactory.java index f2d603b186..7e5b9fe679 100644 --- a/iped-utils/src/main/java/iped/utils/FileInputStreamFactory.java +++ b/iped-utils/src/main/java/iped/utils/FileInputStreamFactory.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.NotDirectoryException; @@ -56,8 +57,7 @@ public Path getPath(String subPath) { } boolean isDirectory(String path) { - try { - Files.newDirectoryStream(Path.of(path)); + try (DirectoryStream ds = Files.newDirectoryStream(Path.of(path))) { } catch (NotDirectoryException ioe) { return false; } catch (IOException e) { diff --git a/iped-utils/src/main/java/iped/utils/fsw/FileAttributes.java b/iped-utils/src/main/java/iped/utils/fsw/FileAttributes.java index 60271c672a..83bd570092 100644 --- a/iped-utils/src/main/java/iped/utils/fsw/FileAttributes.java +++ b/iped-utils/src/main/java/iped/utils/fsw/FileAttributes.java @@ -1,5 +1,6 @@ package iped.utils.fsw; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.NotDirectoryException; import java.nio.file.attribute.BasicFileAttributes; @@ -36,8 +37,8 @@ public boolean isRegularFile() { @Override public boolean isDirectory() { - try { - Files.newDirectoryStream(path); + try (DirectoryStream ds = Files.newDirectoryStream(path)) { + Files.newDirectoryStream(path); } catch (NotDirectoryException ioe) { return false; } catch (Exception e) {