Skip to content

Commit

Permalink
Merge pull request #298 from hazendaz/master
Browse files Browse the repository at this point in the history
[fix] Correct another leak and combine a try/resources block
  • Loading branch information
hazendaz committed May 7, 2023
2 parents fb26616 + b810504 commit 2aa8f34
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,19 @@ protected void copyExternalResourceTo(String resource, File toFile, Properties v
}

protected static void copyTemplate(File templateFile, File toFile, Properties variables) throws IOException {
copyTemplate(new FileReader(templateFile), toFile, variables);
try (FileReader reader = new FileReader(templateFile)) {
copyTemplate(reader, toFile, variables);
}
}

protected static void copyTemplate(Reader templateReader, File toFile, Properties variables) throws IOException {
VariableReplacer replacer = new VariableReplacer(variables);
try (LineNumberReader reader = new LineNumberReader(templateReader)) {
try (PrintWriter writer = new PrintWriter(new FileWriter(toFile))) {
String line;
while ((line = reader.readLine()) != null) {
line = replacer.replace(line);
writer.println(line);
}
try (LineNumberReader reader = new LineNumberReader(templateReader);
PrintWriter writer = new PrintWriter(new FileWriter(toFile))) {
String line;
while ((line = reader.readLine()) != null) {
line = replacer.replace(line);
writer.println(line);
}
}
}
Expand Down

0 comments on commit 2aa8f34

Please sign in to comment.