From 2878f690239a0c4c6347cb02ab5143c75f94fb59 Mon Sep 17 00:00:00 2001 From: shartte Date: Sat, 9 Mar 2024 19:14:15 +0100 Subject: [PATCH] Close output stream after writing files in CopyingFileTreeVisitor (#128) --- .../gradle/util/CopyingFileTreeVisitor.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/src/main/java/net/neoforged/gradle/util/CopyingFileTreeVisitor.java b/utils/src/main/java/net/neoforged/gradle/util/CopyingFileTreeVisitor.java index 52d7742b9..9c7467e7c 100644 --- a/utils/src/main/java/net/neoforged/gradle/util/CopyingFileTreeVisitor.java +++ b/utils/src/main/java/net/neoforged/gradle/util/CopyingFileTreeVisitor.java @@ -6,13 +6,9 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; public class CopyingFileTreeVisitor implements FileVisitor { @@ -85,7 +81,11 @@ public void visitFile(FileVisitDetails fileDetails) { final Path target = directory.resolve(fileDetails.getRelativePath().getPathString()); try { Files.createDirectories(target.getParent()); - fileDetails.copyTo(Files.newOutputStream(target)); + } catch (IOException e) { + throw new RuntimeException("Could not create parent directories for: " + target, e); + } + try (OutputStream out = Files.newOutputStream(target)) { + fileDetails.copyTo(out); } catch (IOException e) { throw new RuntimeException("Could not create file: " + target, e); }