Use try-with-resources

Convert try finally block to try-with-resources

Change-Id: Iff35bb041daf77cd29f9c17ee931c8b2de186e4c
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
diff --git a/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/AbstractMergeViewer.java b/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/AbstractMergeViewer.java
index c898d90..6c5b509 100644
--- a/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/AbstractMergeViewer.java
+++ b/bundles/org.eclipse.compare.win32/src/org/eclipse/compare/internal/win32/AbstractMergeViewer.java
@@ -181,16 +181,13 @@
 	private File createTempFile(InputStream contents) throws IOException {
 		File file = File.createTempFile("compare", ".doc"); //$NON-NLS-1$ //$NON-NLS-2$
 		file.deleteOnExit();
-		OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
-		try {
+		try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
 			byte[] buffer = new byte[1024];
 			int length;
 			while ((length = contents.read(buffer)) != -1) {
 				out.write(buffer, 0, length);
 			}
 			return file;
-		} finally {
-			out.close();
 		}
 	}
 
@@ -270,8 +267,7 @@
 	}
 	
 	protected byte[] asBytes(File file) throws IOException {
-		InputStream in = new BufferedInputStream(new FileInputStream(file));
-		try {
+		try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
 			ByteArrayOutputStream out = new ByteArrayOutputStream();
 			byte[] buffer = new byte[1024];
 			int length;
@@ -280,8 +276,6 @@
 			}
 			out.close();
 			return out.toByteArray();
-		} finally {
-			in.close();
 		}
 	}
 
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
index 805c090..dd13979 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java
@@ -569,12 +569,10 @@
 					} catch (CoreException e) { // in case .project file or folder has been deleted
 						IPath projectPath = stateLocation.append(TMP_PROJECT_NAME);
 						projectPath.toFile().mkdirs();
-						FileOutputStream output = new FileOutputStream(
-								projectPath.append(".project").toOSString()); //$NON-NLS-1$
-						try {
+						try (FileOutputStream output = new FileOutputStream(
+								projectPath.append(".project").toOSString()) //$NON-NLS-1$
+						) {
 							output.write(TMP_PROJECT_FILE.getBytes());
-						} finally {
-							output.close();
 						}
 						project.open(null);
 					}
diff --git a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java
index f213b71..7efee38 100644
--- a/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java
+++ b/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java
@@ -1440,9 +1440,9 @@
 				}
 
 				try{
-					ByteArrayInputStream bis=new ByteArrayInputStream(pkey);
-					c.put(bis, "authorized_keys", null, ChannelSftp.APPEND); //$NON-NLS-1$
-					bis.close();
+					try (ByteArrayInputStream bis = new ByteArrayInputStream(pkey)) {
+						c.put(bis, "authorized_keys", null, ChannelSftp.APPEND); //$NON-NLS-1$
+					}
 					checkPermission(c, "authorized_keys"); //$NON-NLS-1$
 					checkPermission(c, "."); // .ssh //$NON-NLS-1$
 					c.cd(".."); //$NON-NLS-1$
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java
index d25103c..3b51451 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/Team.java
@@ -435,8 +435,7 @@
 		File f = pluginStateLocation.toFile();
 		if (!f.exists()) return false;
 		try {
-			DataInputStream dis = new DataInputStream(new FileInputStream(f));
-			try {
+			try (DataInputStream dis = new DataInputStream(new FileInputStream(f))) {
 				int ignoreCount = 0;
 				try {
 					ignoreCount = dis.readInt();
@@ -450,8 +449,6 @@
 					boolean enabled = dis.readBoolean();
 					globalIgnore.put(pattern, Boolean.valueOf(enabled));
 				}
-			} finally {
-				dis.close();
 			}
 			f.delete();
 		} catch (FileNotFoundException e) {
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java
index 70568ab..7903dd7 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java
@@ -507,9 +507,9 @@
 			File file = pluginStateLocation.toFile();
 			if (file.exists()) {
 				try {
-					DataInputStream dis = new DataInputStream(new FileInputStream(file));
-					readOldState(dis);
-					dis.close();
+					try (DataInputStream dis = new DataInputStream(new FileInputStream(file))) {
+						readOldState(dis);
+					}
 					// The file is no longer needed as the state is
 					// persisted in the user settings
 					file.delete();
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TemplateHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TemplateHandler.java
index dd7783f..22dfd42 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TemplateHandler.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/TemplateHandler.java
@@ -66,18 +66,13 @@
 					IProgressMonitor monitor)
 					throws CVSException {
 
-					try {
-						// Transfer the contents
-						OutputStream out = new ByteArrayOutputStream();
-						try {
-							byte[] buffer = new byte[1024];
-							int read;
-							while ((read = stream.read(buffer)) >= 0) {
-								Policy.checkCanceled(monitor);
-								out.write(buffer, 0, read);
-							}
-						} finally {
-							out.close();
+					try ( // Transfer the contents
+							OutputStream out = new ByteArrayOutputStream()) {
+						byte[] buffer = new byte[1024];
+						int read;
+						while ((read = stream.read(buffer)) >= 0) {
+							Policy.checkCanceled(monitor);
+							out.write(buffer, 0, read);
 						}
 					} catch (IOException e) {
 						throw CVSException.wrapException(e); 
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java
index 5bdbdcc..a6f8c28 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileWriter.java
@@ -491,13 +491,10 @@
 		try {
 			InputStream in = getInputStream(file);
 			if (in != null) {
-				BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512);
-				try {
+				try (BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512)) {
 					String line = reader.readLine();
 					if (line == null) return ""; //$NON-NLS-1$
 					return line;
-				} finally {
-					reader.close();
 				}
 			}
 			return null;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java
index 6ef78e4..3238e3e 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java
@@ -405,13 +405,8 @@
 		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(REPOSITORIES_VIEW_FILE);
 		File file = pluginStateLocation.toFile();
 		if (file.exists()) {
-			try {
-				BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
-				try {
-					readState(is);
-				} finally {
-					is.close();
-				}
+			try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(file))) {
+				readState(is);
 			} catch (IOException e) {
 				CVSUIPlugin.log(IStatus.ERROR, CVSUIMessages.RepositoryManager_ioException, e); 
 			} catch (TeamException e) {
@@ -422,11 +417,8 @@
 			file = oldPluginStateLocation.toFile();
 			if (file.exists()) {
 				try {
-					DataInputStream dis = new DataInputStream(new FileInputStream(file));
-					try {
+					try (DataInputStream dis = new DataInputStream(new FileInputStream(file))) {
 						readOldState(dis);
-					} finally {
-						dis.close();
 					}
 					saveState();
 					file.delete();
@@ -442,13 +434,8 @@
 		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(COMMENT_HIST_FILE);
 		File file = pluginStateLocation.toFile();
 		if (!file.exists()) return;
-		try {
-			BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
-			try {
-				readCommentHistory(is);
-			} finally {
-				is.close();
-			}
+		try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(file))) {
+			readCommentHistory(is);
 		} catch (IOException e) {
 			CVSUIPlugin.log(IStatus.ERROR, CVSUIMessages.RepositoryManager_ioException, e); 
 		} catch (TeamException e) {
@@ -459,13 +446,8 @@
 		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(COMMENT_TEMPLATES_FILE);
 		File file = pluginStateLocation.toFile();
 		if (!file.exists()) return;
-		try {
-			BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
-			try {
-				readCommentTemplates(is);
-			} finally {
-				is.close();
-			}
+		try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(file))) {
+			readCommentTemplates(is);
 		} catch (IOException e) {
 			CVSUIPlugin.log(IStatus.ERROR, CVSUIMessages.RepositoryManager_ioException, e);
 		} catch (TeamException e) {
@@ -478,11 +460,8 @@
 		File tempFile = pluginStateLocation.append(REPOSITORIES_VIEW_FILE + ".tmp").toFile(); //$NON-NLS-1$
 		File stateFile = pluginStateLocation.append(REPOSITORIES_VIEW_FILE).toFile();
 		try {
-			XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile)));
-			try {
+			try (XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile)))) {
 				writeState(writer);
-			} finally {
-				writer.close();
 			}
 			if (stateFile.exists()) {
 				stateFile.delete();
@@ -600,11 +579,8 @@
 		File tempFile = pluginStateLocation.append(COMMENT_HIST_FILE + ".tmp").toFile(); //$NON-NLS-1$
 		File histFile = pluginStateLocation.append(COMMENT_HIST_FILE).toFile();
 		try {
-			XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile)));
-			try {
+			try (XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile)))) {
 				writeCommentHistory(writer);
-			} finally {
-				writer.close();
 			}
 			if (histFile.exists()) {
 				histFile.delete();
@@ -944,12 +920,9 @@
 		File histFile = pluginStateLocation.append(COMMENT_TEMPLATES_FILE)
 				.toFile();
 		try {
-			XMLWriter writer = new XMLWriter(new BufferedOutputStream(
-					new FileOutputStream(tempFile)));
-			try {
+			try (XMLWriter writer = new XMLWriter(new BufferedOutputStream(
+					new FileOutputStream(tempFile)))) {
 				writeCommentTemplates(writer);
-			} finally {
-				writer.close();
 			}
 			if (histFile.exists()) {
 				histFile.delete();
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java
index d8bcb7f..bd87b9d 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java
@@ -235,16 +235,10 @@
 
 	private static XMLMemento stringToXMLMemento(String stringContents)
 			throws InvocationTargetException {
-		StringReader reader = null;
-		try {
-			reader = new StringReader(stringContents);
+		try (StringReader reader = new StringReader(stringContents)) {
 			return XMLMemento.createReadRoot(reader);
 		} catch (WorkbenchException e) {
 			throw new InvocationTargetException(e);
-		} finally {
-			if (reader != null) {
-				reader.close();
-			}
 		}
 	}
 
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeManager.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeManager.java
index 7cd1eb7..2a3cd25 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeManager.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeManager.java
@@ -641,11 +641,8 @@
 			ref.save(participantData);
 		}
 		try {
-			Writer writer = new BufferedWriter(new FileWriter(getStateFile()));
-			try {
+			try (Writer writer = new BufferedWriter(new FileWriter(getStateFile()))) {
 				xmlMemento.save(writer);
-			} finally {
-				writer.close();
 			}
 		} catch (IOException e) {
 			TeamUIPlugin.log(new Status(IStatus.ERROR, TeamUIPlugin.ID, 1, TeamUIMessages.SynchronizeManager_10, e));
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java
index 46276b4..91afa6e 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java
@@ -272,21 +272,15 @@
 			// so nothing needs to be done
 			return;
 		}
-		try {
-			//Copy from the local file to the remote file:
-			InputStream source = null;
-			try {
-				// Get the remote file content.
-				source = remote.getContents();
-				// Set the local file content to be the same as the remote file.
-				if (localFile.exists())
-					localFile.setContents(source, false, false, progress);
-				else
-					localFile.create(source, false, progress);
-			} finally {
-				if (source != null)
-					source.close();
-			}
+		// Copy from the local file to the remote file:
+		// Get the remote file content.
+		try (InputStream source = remote.getContents()) {
+			// Set the local file content to be the same as the remote file.
+			if (localFile.exists())
+				localFile.setContents(source, false, false, progress);
+			else
+				localFile.create(source, false, progress);
+
 			// Mark as read-only to force a checkout before editing
 			localFile.setReadOnly(true);
 			synchronizer.setBaseBytes(localFile, remote.asBytes());
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java
index e85f5ff..f7a8b7e 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java
@@ -602,12 +602,9 @@
 
 	public static String getFileContents(IFile file) throws IOException, CoreException {
 		StringBuilder buf = new StringBuilder();
-		Reader reader = new InputStreamReader(new BufferedInputStream(file.getContents()));
-		try {
+		try (Reader reader = new InputStreamReader(new BufferedInputStream(file.getContents()))) {
 			int c;
 			while ((c = reader.read()) != -1) buf.append((char)c);
-		} finally {
-			reader.close();
 		}
 		return buf.toString();
 	}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java
index bc31802..1f76a79 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/CVSTestSetup.java
@@ -13,17 +13,30 @@
  *******************************************************************************/
 package org.eclipse.team.tests.ccvs.core;
 
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
 
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-
-import org.eclipse.core.runtime.*;
-import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.internal.ccvs.core.CVSStatus;
+import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
 import org.eclipse.team.internal.ccvs.core.connection.CVSCommunicationException;
 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories;
 
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+
 public class CVSTestSetup extends TestSetup {
 	public static final String REPOSITORY_LOCATION;
 	public static final boolean INITIALIZE_REPO;
@@ -62,18 +75,14 @@
 		if (propertiesFile == null) return;
 		File file = new File(propertiesFile);
 		if (file.isDirectory()) file = new File(file, "repository.properties");
-		try {
-			BufferedReader reader = new BufferedReader(new FileReader(file));
-			try {
-				for (String line; (line = reader.readLine()) != null; ) {
-					if (line.startsWith("#")) continue;					
-					int sep = line.indexOf("=");
-					String property = line.substring(0, sep).trim();
-					String value = line.substring(sep + 1).trim();
-					System.setProperty("eclipse.cvs." + property, value);
-				}
-			} finally {
-				reader.close();
+		try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+			for (String line; (line = reader.readLine()) != null;) {
+				if (line.startsWith("#"))
+					continue;
+				int sep = line.indexOf("=");
+				String property = line.substring(0, sep).trim();
+				String value = line.substring(sep + 1).trim();
+				System.setProperty("eclipse.cvs." + property, value);
 			}
 		} catch (Exception e) {
 			System.err.println("Could not read repository properties file: " + file.getAbsolutePath());
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
index a6cdf88..6c22b01 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/EclipseTest.java
@@ -271,12 +271,9 @@
 	
 	public static String getFileContents(IFile file) throws IOException, CoreException {
 		StringBuilder buf = new StringBuilder();
-		Reader reader = new InputStreamReader(new BufferedInputStream(file.getContents()));
-		try {
+		try (Reader reader = new InputStreamReader(new BufferedInputStream(file.getContents()))) {
 			int c;
 			while ((c = reader.read()) != -1) buf.append((char)c);
-		} finally {
-			reader.close();
 		}
 		return buf.toString();		
 	}
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/JUnitTestCase.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/JUnitTestCase.java
index 5e018d7..2cc2d7b 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/JUnitTestCase.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/JUnitTestCase.java
@@ -144,8 +144,7 @@
 	protected static void writeToFile(IFile file, String[] contents)
 			throws IOException, CoreException {
 		ByteArrayOutputStream bos = new ByteArrayOutputStream();
-		PrintStream os = new PrintStream(bos);
-		try {
+		try (PrintStream os = new PrintStream(bos)) {
 			for (String content : contents) {
 				os.println(content);
 			}
@@ -156,8 +155,6 @@
 				mkdirs(file.getParent());
 				file.create(bis, false /*force*/, null);
 			}
-		} finally {
-			os.close();
 		}
 	}
 	
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/compatible/SameResultEnv.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/compatible/SameResultEnv.java
index 1d72833..fe7aed3 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/compatible/SameResultEnv.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/compatible/SameResultEnv.java
@@ -369,22 +369,18 @@
 		assertEquals(mFile1.isReadOnly(), mFile2.isReadOnly());
 					
 		// Compare the content of the files
-		try {
-			InputStream in1 = mFile1.getContents();
-			InputStream in2 = mFile2.getContents();
-			byte[] buffer1 = new byte[(int)mFile1.getSize()];
-			byte[] buffer2 = new byte[(int)mFile2.getSize()];
+		byte[] buffer1 = new byte[(int) mFile1.getSize()];
+		byte[] buffer2 = new byte[(int) mFile2.getSize()];
+		try (InputStream in1 = mFile1.getContents(); InputStream in2 = mFile2.getContents()) {
 			// This is not the right way to do it, because the Stream
 			// may read less than the whole file
 			in1.read(buffer1);
 			in2.read(buffer2);
-			in1.close();
-			in2.close();
-			assertEquals("Length differs for file " + mFile1.getName(), buffer1.length, buffer2.length);
-			assertEquals("Contents differs for file " + mFile1.getName(), new String(buffer1),new String(buffer2));
 		} catch (IOException e) {
 			throw new CVSException("Error in TestCase");
 		}
+		assertEquals("Length differs for file " + mFile1.getName(), buffer1.length, buffer2.length);
+		assertEquals("Contents differs for file " + mFile1.getName(), new String(buffer1),new String(buffer2));
 
 		// We can not do the check, because the reference client does
 		// check out dirty files ?!?
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ModuleTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ModuleTest.java
index 80cfcf3..b3a0b3b 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ModuleTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ModuleTest.java
@@ -82,11 +82,8 @@
 		waitMsec(1000);
 
 		IProject cvsroot = checkoutProject(null, "CVSROOT", null);
-		InputStream in = url.openStream();
-		try {
+		try (InputStream in = url.openStream()) {
 			cvsroot.getFile("modules").setContents(in, false, false, DEFAULT_MONITOR);
-		} finally {
-			in.close();
 		}
 		commitProject(cvsroot);
 		
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ResourceDeltaTest.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ResourceDeltaTest.java
index c4a03dc..cc44611 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ResourceDeltaTest.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/ResourceDeltaTest.java
@@ -156,15 +156,12 @@
 		// wait to ensure the timestamp differs from the one Core has
 		waitMsec(1500);
 		InputStream in = new BufferedInputStream(getRandomContents());
-		OutputStream out = new BufferedOutputStream(new FileOutputStream(ioFile));
-		try {
+		try (OutputStream out = new BufferedOutputStream(new FileOutputStream(ioFile))) {
 			int next = in.read();
 			while (next != -1) {
 				out.write(next);
 				next = in.read();
 			}
-		} finally {
-			out.close();
 		}
 	}
 	
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ProjectSetImporterTests.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ProjectSetImporterTests.java
index 1012510..8e91640 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ProjectSetImporterTests.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/ProjectSetImporterTests.java
@@ -94,10 +94,8 @@
 		IProject project2 = createProject("testImportProject",
 				new String[] { "file.txt", "folder1/", "folder1/a.txt" });
 
-		PrintWriter out = null;
-		try {
-			out = new PrintWriter(new BufferedWriter(new FileWriter(PSF_FILE)),
-					true);
+		try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(PSF_FILE)),
+				true)) {
 
 			out.println(psf_header_0);
 			out.println(psf_header_1);
@@ -123,9 +121,6 @@
 			fail("1.", e.getCause());
 		} catch (IOException e) {
 			fail("2.", e);
-		} finally {
-			if (out != null)
-				out.close();
 		}
 	}
 
@@ -136,11 +131,9 @@
 		IProject project2 = createProject("testBug234149_aFewProviders",
 				new String[0]);
 
-		// create psf with two providers
-		PrintWriter out = null;
-		try {
-			out = new PrintWriter(new BufferedWriter(new FileWriter(PSF_FILE)),
-					true);
+		try ( // create psf with two providers
+				PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(PSF_FILE)),
+						true)) {
 
 			// add first provider to psf
 			out.println(psf_header_0);
@@ -172,9 +165,6 @@
 			fail("1.", e.getCause());
 		} catch (IOException e) {
 			fail("2.", e);
-		} finally {
-			if (out != null)
-				out.close();
 		}
 	}
 
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/BenchmarkUtils.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/BenchmarkUtils.java
index e86cb12..0da2693 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/BenchmarkUtils.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/BenchmarkUtils.java
@@ -156,18 +156,19 @@
 			fileSize = (int) Math.abs(gen.nextGaussian() * variance + meanSize);
 		} while (fileSize > meanSize + variance * 4); // avoid huge files
 		
-		ByteArrayOutputStream os = new ByteArrayOutputStream();
-		String fileName;
-		if (gen.nextInt(100) < probBinary) {
-			fileName = makeUniqueName(gen, "file", "class"); // binary
-			writeRandomBytes(gen, os, fileSize);
-		} else {
-			fileName = makeUniqueName(gen, "file", "txt"); // text
-			writeRandomText(gen, os, fileSize);
+		IFile file;
+		try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
+			String fileName;
+			if (gen.nextInt(100) < probBinary) {
+				fileName = makeUniqueName(gen, "file", "class"); // binary
+				writeRandomBytes(gen, os, fileSize);
+			} else {
+				fileName = makeUniqueName(gen, "file", "txt"); // text
+				writeRandomText(gen, os, fileSize);
+			}	
+			file = parent.getFile(new Path(fileName));
+			file.create(new ByteArrayInputStream(os.toByteArray()), true, new NullProgressMonitor());
 		}
-		IFile file = parent.getFile(new Path(fileName));
-		file.create(new ByteArrayInputStream(os.toByteArray()), true, new NullProgressMonitor());
-		os.close();
 		return file;
 	}
 
@@ -221,10 +222,7 @@
 	 */
 	public static void modifyFile(SequenceGenerator gen, IFile file)
 		throws IOException, CoreException {
-		ByteArrayOutputStream os = new ByteArrayOutputStream();
-		try {
-			InputStream is = file.getContents(true);
-			try {
+		try (ByteArrayOutputStream os = new ByteArrayOutputStream(); InputStream is = file.getContents(true)) {
 				byte[] buffer = new byte[8192];
 				int rsize;
 				boolean changed = false;
@@ -240,11 +238,6 @@
 				}
 				if (! changed) os.write('!'); // make sure we actually did change the file
 				file.setContents(new ByteArrayInputStream(os.toByteArray()), false /*force*/, true /*keepHistory*/, null);
-			} finally {
-				is.close();
-			}
-		} finally {
-			os.close();
 		}
 	}
 	
diff --git a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/Bug152581Test.java b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/Bug152581Test.java
index 239b09c..79f82a9 100644
--- a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/Bug152581Test.java
+++ b/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/benchmark/Bug152581Test.java
@@ -93,8 +93,7 @@
 
 	private IProject createProject(String filename) throws IOException, CoreException {
 		File file = BenchmarkTestSetup.getTestFile(filename + ".txt");
-		InputStream content = getContents(file, "Could not read seed file " + filename + ".txt");
-		try {
+		try (InputStream content = getContents(file, "Could not read seed file " + filename + ".txt")) {
 			BufferedReader reader = new BufferedReader(new InputStreamReader(content));
 			IProject project = getUniqueTestProject(filename);
 			populateProject(reader, project);
@@ -102,8 +101,6 @@
 			// Perform an update to prune any empty directories
 			updateProject(project, null, false);
 			return project;
-		} finally {
-			content.close();
 		}
 	}