Make TarFile implement closeable.

And deal with it using try-with-resources.

Change-Id: I0389ab78f2aefe157378f2378f39564deee0c125
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
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 17dfd95..6f17bc0 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 @@
 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 @@
 					}
 				}
 			}
-		} 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 ef93fcb..31bdbec 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 @@
 /**
  * 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 @@
 	 * 
 	 * @throws IOException if the file cannot be successfully closed
 	 */
+	@Override
 	public void close() throws IOException {
 		entryEnumerationStream.close();
 		if (internalEntryStream != null)