mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-26 19:15:09 +00:00
Use try-with-resources where possible (#6765)
This commit is contained in:
1 parent
88334073e0
commit
76e5c98dd3
5 files changed
+17
-35
No files matched your search
@@ -532,13 +532,10 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||
|
||||
@Override
|
||||
public Integer invoke(File f, VirtualChannel channel) throws IOException {
|
||||
Archiver a = factory.create(out);
|
||||
try {
|
||||
try (Archiver a = factory.create(out)) {
|
||||
scanner.scan(f, ignoringSymlinks(a, verificationRoot, noFollowLinks));
|
||||
} finally {
|
||||
a.close();
|
||||
return a.countEntries();
|
||||
}
|
||||
return a.countEntries();
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -708,10 +705,9 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||
|
||||
private static void unzip(File dir, File zipFile) throws IOException {
|
||||
dir = dir.getAbsoluteFile(); // without absolutization, getParentFile below seems to fail
|
||||
ZipFile zip = new ZipFile(zipFile);
|
||||
Enumeration<ZipEntry> entries = zip.getEntries();
|
||||
|
||||
try {
|
||||
try (ZipFile zip = new ZipFile(zipFile)) {
|
||||
Enumeration<ZipEntry> entries = zip.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry e = entries.nextElement();
|
||||
File f = new File(dir, e.getName());
|
||||
@@ -740,8 +736,6 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||
Files.setLastModifiedTime(Util.fileToPath(f), e.getLastModifiedTime());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
zip.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -922,11 +916,9 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||
* @since 1.292
|
||||
*/
|
||||
public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException {
|
||||
try {
|
||||
try (_in) {
|
||||
final InputStream in = new RemoteInputStream(_in, Flag.GREEDY);
|
||||
act(new UntarFrom(compression, in));
|
||||
} finally {
|
||||
_in.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2947,10 +2939,8 @@ public final class FilePath implements SerializableOnlyOverRemoting {
|
||||
*/
|
||||
private static Integer writeToTar(File baseDir, DirScanner scanner, OutputStream out) throws IOException {
|
||||
Archiver tw = ArchiverFactory.TAR.create(out);
|
||||
try {
|
||||
try (tw) {
|
||||
scanner.scan(baseDir, tw);
|
||||
} finally {
|
||||
tw.close();
|
||||
}
|
||||
return tw.countEntries();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user