Skip to content

Commit

Permalink
'#1861 Closes directory streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdalla committed Oct 25, 2023
1 parent b06c9e4 commit d0b1a01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions iped-utils/src/main/java/iped/utils/fsw/FileAttributes.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d0b1a01

Please sign in to comment.