Skip to content

Commit

Permalink
close Files.list
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis95 committed May 3, 2022
1 parent 71079a2 commit e1e8dfb
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;

import static io.zulia.message.ZuliaQuery.FetchType.META;
Expand Down Expand Up @@ -139,12 +139,20 @@ public static void index(String inputDir, String recordsFilename, String idField

// ensure the file was extractable
if (Files.exists(destDir.toPath())) {
List<Path> tempFiles = Files.list(destDir.toPath()).collect(Collectors.toList());

List<Path> tempFiles;
try (Stream<Path> sp = Files.list(destDir.toPath())) {
tempFiles = sp.toList();
}
for (Path path : tempFiles) {
if (path.toFile().isDirectory()) {
try {

List<Path> filesPaths = Files.list(path).collect(Collectors.toList());
List<Path> filesPaths;
try (Stream<Path> sp = Files.list(path)) {
filesPaths = sp.toList();
}

Document meta = null;
byte[] associatedBytes = new byte[0];
String filename = null;
Expand Down Expand Up @@ -182,7 +190,9 @@ public static void index(String inputDir, String recordsFilename, String idField
}

// clean up temp work
Files.walk(destDir.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
try (Stream<Path> walk = Files.walk(destDir.toPath())) {
walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}

}
else {
Expand Down Expand Up @@ -284,6 +294,4 @@ private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOExc
return destFile;
}



}

0 comments on commit e1e8dfb

Please sign in to comment.