Skip to content

Commit

Permalink
Close output stream after writing files in CopyingFileTreeVisitor (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Mar 9, 2024
1 parent 2467789 commit 2878f69
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 2878f69

Please sign in to comment.