Merge pull request #365 from lujiefsi/JRTExtractor

resource leak due to Files.walk
This commit is contained in:
Konloch 2021-10-26 22:54:17 -07:00 committed by GitHub
commit 36515d09d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,9 +18,11 @@ import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@ -28,8 +30,9 @@ public class JRTExtractor {
public static void extractRT(String path) throws Throwable {
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
try (ZipOutputStream zipStream = new ZipOutputStream(Files.newOutputStream(Paths.get(path)))) {
Files.walk(fs.getPath("/")).forEach(p -> {
try (ZipOutputStream zipStream = new ZipOutputStream(Files.newOutputStream(Paths.get(path)));
Stream<Path> stream = Files.walk(fs.getPath("/"))) {
stream.forEach(p -> {
if (!Files.isRegularFile(p)) {
return;
}