diff options
author | Alexander Kurtakov | 2018-05-02 18:19:47 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2018-05-02 18:19:47 +0000 |
commit | 36478e9a778e174d966e22a4bb23d98fdb31af1d (patch) | |
tree | 17bcb570d2c8a7111932fe991f47bbe0a7b81653 /bundles | |
parent | b5c0b2e4995b37e23c5eed227bb01fcadfa89652 (diff) | |
download | rt.equinox.p2-36478e9a778e174d966e22a4bb23d98fdb31af1d.tar.gz rt.equinox.p2-36478e9a778e174d966e22a4bb23d98fdb31af1d.tar.xz rt.equinox.p2-36478e9a778e174d966e22a4bb23d98fdb31af1d.zip |
Make TarFile implement closeable.
And deal with it using try-with-resources.
Change-Id: I0389ab78f2aefe157378f2378f39564deee0c125
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'bundles')
2 files changed, 5 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java index 17dfd95f9..6f17bc0dd 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 IBM Corporation and others. + * Copyright (c) 2007, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,9 +20,8 @@ import org.eclipse.osgi.util.NLS; public class FileUtils { private static File[] untarFile(File source, File outputDir) throws IOException, TarException { - TarFile tarFile = new TarFile(source); List<File> untarredFiles = new ArrayList<>(); - try { + try (TarFile tarFile = new TarFile(source)) { for (Enumeration<TarEntry> e = tarFile.entries(); e.hasMoreElements();) { TarEntry entry = e.nextElement(); try (InputStream input = tarFile.getInputStream(entry)) { @@ -46,8 +45,6 @@ public class FileUtils { } } } - } finally { - tarFile.close(); } return untarredFiles.toArray(new File[untarredFiles.size()]); } diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/TarFile.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/TarFile.java index ef93fcb82..31bdbec46 100644 --- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/TarFile.java +++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/TarFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corporation and others. + * Copyright (c) 2008, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,7 +17,7 @@ import java.util.zip.GZIPInputStream; /** * Copied from org.eclipse.ui.internal.wizards.datatransfer.TarFile. */ -public class TarFile { +public class TarFile implements Closeable { private File file; private TarInputStream entryEnumerationStream; private TarEntry curEntry; @@ -59,6 +59,7 @@ public class TarFile { * * @throws IOException if the file cannot be successfully closed */ + @Override public void close() throws IOException { entryEnumerationStream.close(); if (internalEntryStream != null) |