diff --git a/zulia-server/src/main/java/io/zulia/server/cmd/common/ZuliaCmdUtil.java b/zulia-server/src/main/java/io/zulia/server/cmd/common/ZuliaCmdUtil.java index f020cbc8..0d47591c 100644 --- a/zulia-server/src/main/java/io/zulia/server/cmd/common/ZuliaCmdUtil.java +++ b/zulia-server/src/main/java/io/zulia/server/cmd/common/ZuliaCmdUtil.java @@ -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; @@ -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 tempFiles = Files.list(destDir.toPath()).collect(Collectors.toList()); + + List tempFiles; + try (Stream sp = Files.list(destDir.toPath())) { + tempFiles = sp.toList(); + } for (Path path : tempFiles) { if (path.toFile().isDirectory()) { try { - List filesPaths = Files.list(path).collect(Collectors.toList()); + List filesPaths; + try (Stream sp = Files.list(path)) { + filesPaths = sp.toList(); + } + Document meta = null; byte[] associatedBytes = new byte[0]; String filename = null; @@ -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 walk = Files.walk(destDir.toPath())) { + walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); + } } else { @@ -284,6 +294,4 @@ private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOExc return destFile; } - - }