Skip to content

Commit b396c16

Browse files
committed
[java] A bit more safe way to use File.walk, the created Stream should be closed
1 parent 8664401 commit b396c16

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

java/client/src/org/openqa/selenium/tools/javadoc/JavadocJarMaker.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Locale;
4343
import java.util.Set;
4444
import java.util.stream.Collectors;
45+
import java.util.stream.Stream;
4546
import java.util.zip.ZipEntry;
4647
import java.util.zip.ZipInputStream;
4748
import java.util.zip.ZipOutputStream;
@@ -132,9 +133,9 @@ public static void main(String[] args) throws IOException {
132133
}
133134

134135
try (OutputStream os = Files.newOutputStream(out);
135-
ZipOutputStream zos = new ZipOutputStream(os)) {
136-
Files.walk(outputTo)
137-
.sorted(Comparator.naturalOrder())
136+
ZipOutputStream zos = new ZipOutputStream(os);
137+
Stream<Path> walk = Files.walk(outputTo)) {
138+
walk.sorted(Comparator.naturalOrder())
138139
.forEachOrdered(path -> {
139140
if (path.equals(outputTo)) {
140141
return;
@@ -163,9 +164,8 @@ public static void main(String[] args) throws IOException {
163164
}
164165
} finally {
165166
tempDirs.forEach(d -> {
166-
try {
167-
Files.walk(d)
168-
.sorted(Comparator.reverseOrder())
167+
try (Stream<Path> walk = Files.walk(d)) {
168+
walk.sorted(Comparator.reverseOrder())
169169
.map(Path::toFile)
170170
.forEach(File::delete);
171171
} catch (IOException e) {

0 commit comments

Comments
 (0)