Polish "Use try-with-resources to close resources automatically"

- Apply code formatting
- Use try-with-resources in many other places that were missed in the
  pull request

Closes gh-8045
This commit is contained in:
Andy Wilkinson
2017-05-23 17:24:01 +01:00
parent 3e797c326a
commit d5438c299c
78 changed files with 284 additions and 703 deletions

View File

@@ -79,8 +79,7 @@ public final class CommandLineInvoker {
}
})[0];
ZipInputStream input = new ZipInputStream(new FileInputStream(zip));
try {
try (ZipInputStream input = new ZipInputStream(new FileInputStream(zip))) {
ZipEntry entry;
while ((entry = input.getNextEntry()) != null) {
File file = new File(unpacked, entry.getName());
@@ -89,22 +88,15 @@ public final class CommandLineInvoker {
}
else {
file.getParentFile().mkdirs();
FileOutputStream output = new FileOutputStream(file);
try {
try (FileOutputStream output = new FileOutputStream(file)) {
StreamUtils.copy(input, output);
if (entry.getName().endsWith("/bin/spring")) {
file.setExecutable(true);
}
}
finally {
output.close();
}
}
}
}
finally {
input.close();
}
}
File bin = new File(unpacked.listFiles()[0], "bin");
File launchScript = new File(bin, isWindows() ? "spring.bat" : "spring");