Merge branch 'use_try_with_resource' into master

refs #2734
This commit is contained in:
Clément Fournier
2020-08-24 20:33:00 +02:00
2 changed files with 3 additions and 15 deletions

View File

@ -54,9 +54,7 @@ public class FileReporterTest {
}
private String readFile(File file) throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
StringBuilder buffer = new StringBuilder();
String line = reader.readLine();
while (line != null) {
@ -67,10 +65,6 @@ public class FileReporterTest {
}
}
return buffer.toString();
} finally {
if (reader != null) {
reader.close();
}
}
}

View File

@ -39,8 +39,7 @@ public class ZipFileExtractor {
* @throws Exception if any error happens during extraction
*/
public static void extractZipFile(Path zipPath, Path tempDir) throws Exception {
ZipFile zip = new ZipFile(zipPath.toFile());
try {
try (ZipFile zip = new ZipFile(zipPath.toFile())) {
Enumeration<ZipArchiveEntry> entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
@ -57,8 +56,6 @@ public class ZipFileExtractor {
}
}
}
} finally {
zip.close();
}
}
@ -70,15 +67,12 @@ public class ZipFileExtractor {
*/
public static List<String> readZipFile(Path zipPath) throws Exception {
List<String> result = new ArrayList<>();
ZipFile zip = new ZipFile(zipPath.toFile());
try {
try (ZipFile zip = new ZipFile(zipPath.toFile())) {
Enumeration<ZipArchiveEntry> entries = zip.getEntries();
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
result.add(entry.getName());
}
} finally {
zip.close();
}
return result;
}