Use try-with-resources (IDEA-CR-24263)

This commit is contained in:
Dmitry Trofimov
2017-09-25 15:12:30 +02:00
parent 33d89b68ba
commit 3dc2aed999
2 changed files with 7 additions and 16 deletions

View File

@@ -149,15 +149,12 @@ public class TarUtil {
public static void extract(@NotNull File file, @NotNull File outputDir, @Nullable FilenameFilter filenameFilter, boolean overwrite)
throws IOException {
FileInputStream fis = new FileInputStream(file);
GzipCompressorInputStream gcis = new GzipCompressorInputStream(fis);
TarArchiveInputStream tis = new TarArchiveInputStream(gcis);
try {
try (FileInputStream fis = new FileInputStream(file);
GzipCompressorInputStream gcis = new GzipCompressorInputStream(fis);
TarArchiveInputStream tis = new TarArchiveInputStream(gcis)) {
extract(tis, outputDir, filenameFilter, overwrite);
}
finally {
fis.close();
}
}
public static void extract(@NotNull final TarArchiveInputStream tis,
@@ -219,10 +216,8 @@ public class TarUtil {
* update an existing jar file. Adds/replace files specified in relpathToFile map
*/
public static void update(InputStream in, OutputStream out, Map<String, File> relpathToFile) throws IOException {
TarArchiveInputStream tis = new TarArchiveInputStream(in);
TarArchiveOutputStream tos = new TarArchiveOutputStream(out);
try {
try (TarArchiveInputStream tis = new TarArchiveInputStream(in);
TarArchiveOutputStream tos = new TarArchiveOutputStream(out)) {
// put the old entries first, replace if necessary
TarArchiveEntry e;
while ((e = tis.getNextTarEntry()) != null) {
@@ -256,9 +251,5 @@ public class TarUtil {
addFileToTar(tos, file, path, null, null);
}
}
finally {
tis.close();
tos.close();
}
}
}

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
<exclude-output />
<annotation-paths>
<root url="file://$MODULE_DIR$/anno" />