Replace try with try-with-resources

Update existing try/finally/close blocks to use "try with resources"

See gh-9781
This commit is contained in:
Emanuel Campolo
2017-07-18 12:04:54 -03:00
committed by Phillip Webb
parent 798fe5ed53
commit d16af43664
2 changed files with 4 additions and 16 deletions

View File

@@ -186,8 +186,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
private long getNestedLibraryTime(File file) {
try {
JarFile jarFile = new JarFile(file);
try {
try (JarFile jarFile = new JarFile(file)) {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
@@ -196,9 +195,6 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
}
}
}
finally {
jarFile.close();
}
}
catch (Exception ex) {
// Ignore and just use the source file timestamp
@@ -381,13 +377,9 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
private long size;
CrcAndSize(File file) throws IOException {
FileInputStream inputStream = new FileInputStream(file);
try {
try (FileInputStream inputStream = new FileInputStream(file)) {
load(inputStream);
}
finally {
inputStream.close();
}
}
CrcAndSize(InputStream inputStream) throws IOException {