543815: Mylyn should use buffered output streams

Buffered output streams and replaced try-finally with try resource

Change-Id: I504647dc1a608df3502158eded47a917e9be37df
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=543815
Signed-off-by: Natasha Carson <natasha.carson@tasktop.com>
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
index 813942f..d73ae6e 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
@@ -412,8 +412,8 @@
 		taskData.getRoot()
 				.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
 				.setValue("M2");
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
-				null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskData, null, null);
 		assertEquals(ResponseKind.TASK_CREATED, reposonse.getReposonseKind());
 	}
 
@@ -461,8 +461,8 @@
 		TaskMapper mapper1 = new TaskMapper(taskData);
 		connector.getTaskMapping(taskDataSubmit).merge(mapper1);
 
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataSubmit,
-				null, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataSubmit, null, null);
 		assertEquals(ResponseKind.TASK_CREATED, reposonse.getReposonseKind());
 	}
 
@@ -563,7 +563,8 @@
 		assertEquals(
 				IOUtils.toString(
 						CommonTestUtil.getResource(this, actualFixture.getTestDataFolder() + "/taskDataFlags.txt")),
-				flags.toString());	}
+				flags.toString());
+	}
 
 	@Test
 	public void testUpdateTaskData() throws Exception {
@@ -597,8 +598,8 @@
 		changed.add(attribute);
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -636,8 +637,8 @@
 		changed.add(attribute);
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -700,18 +701,13 @@
 		BugzillaRestTaskAttachmentHandler attachmentHandler = new BugzillaRestTaskAttachmentHandler(connector);
 		ITask task = new TaskTask(actualFixture.repository().getConnectorKind(),
 				actualFixture.repository().getRepositoryUrl(), taskId);
-
-		InputStream in = CommonTestUtil.getResource(this, "testdata/icons/bugzilla-logo.gif");
 		File file = File.createTempFile("attachment", null);
 		file.deleteOnExit();
-		OutputStream out = new FileOutputStream(file);
-		try {
-			IOUtils.copy(in, out);
-		} finally {
-			in.close();
-			out.close();
-		}
 
+		try (OutputStream out = new FileOutputStream(file);
+				InputStream in = CommonTestUtil.getResource(this, "testdata/icons/bugzilla-logo.gif")) {
+			IOUtils.copy(in, out);
+		}
 		FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file);
 		attachment.setContentType("image/gif");
 		attachment.setDescription("My Attachment 2");
@@ -774,16 +770,11 @@
 		BugzillaRestTaskAttachmentHandler attachmentHandler = new BugzillaRestTaskAttachmentHandler(connector);
 		ITask task = new TaskTask(actualFixture.repository().getConnectorKind(),
 				actualFixture.repository().getRepositoryUrl(), taskId);
-
-		InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt");
 		File file = File.createTempFile("attachment", null);
 		file.deleteOnExit();
-		OutputStream out = new FileOutputStream(file);
-		try {
+		try (OutputStream out = new FileOutputStream(file);
+				InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt")) {
 			IOUtils.copy(in, out);
-		} finally {
-			in.close();
-			out.close();
 		}
 
 		FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file);
@@ -861,10 +852,11 @@
 		taskData.getRoot()
 				.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
 				.setValue("M2");
-		taskData.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey()).setValue(
-				"admin@mylyn.eclipse.org, tests@mylyn.eclipse.org");
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
-				null);
+		taskData.getRoot()
+				.getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey())
+				.setValue("admin@mylyn.eclipse.org, tests@mylyn.eclipse.org");
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskData, null, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
@@ -914,10 +906,11 @@
 		taskData.getRoot()
 				.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
 				.setValue("M2");
-		taskData.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().BLOCKS.getKey()).setValue(
-				taskIdRel[0] + ", " + taskIdRel[1]);
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
-				null);
+		taskData.getRoot()
+				.getAttribute(BugzillaRestCreateTaskSchema.getDefault().BLOCKS.getKey())
+				.setValue(taskIdRel[0] + ", " + taskIdRel[1]);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskData, null, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
@@ -967,10 +960,11 @@
 		taskData.getRoot()
 				.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
 				.setValue("M2");
-		taskData.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().DEPENDS_ON.getKey()).setValue(
-				taskIdRel[0] + ", " + taskIdRel[1]);
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
-				null);
+		taskData.getRoot()
+				.getAttribute(BugzillaRestCreateTaskSchema.getDefault().DEPENDS_ON.getKey())
+				.setValue(taskIdRel[0] + ", " + taskIdRel[1]);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskData, null, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
@@ -995,8 +989,8 @@
 		changed.add(attribute);
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1045,8 +1039,8 @@
 		changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().BLOCKS.getKey()));
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1093,8 +1087,8 @@
 		changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().BLOCKS.getKey()));
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1142,8 +1136,8 @@
 		changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().DEPENDS_ON.getKey()));
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1191,8 +1185,8 @@
 		changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().DEPENDS_ON.getKey()));
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1268,8 +1262,8 @@
 		}
 
 		//Act
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1385,8 +1379,8 @@
 			}
 		}
 
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1575,8 +1569,8 @@
 			}
 		}
 
-		RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
-				changed, null);
+		RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+				.postTaskData(taskDataGet, changed, null);
 		assertNotNull(reposonse);
 		assertNotNull(reposonse.getReposonseKind());
 		assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1781,15 +1775,11 @@
 		ITask task = new TaskTask(actualFixture.repository().getConnectorKind(),
 				actualFixture.repository().getRepositoryUrl(), taskId);
 
-		InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt");
 		File file = File.createTempFile("attachment", null);
 		file.deleteOnExit();
-		OutputStream out = new FileOutputStream(file);
-		try {
+		try (OutputStream out = new FileOutputStream(file);
+				InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt")) {
 			IOUtils.copy(in, out);
-		} finally {
-			in.close();
-			out.close();
 		}
 
 		FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file);
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
index fca6135..911e170 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
@@ -13,6 +13,7 @@
 
 package org.eclipse.mylyn.internal.bugzilla.core;
 
+import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -1654,9 +1655,8 @@
 							value = a.getValue();
 							if (value.equals("?") && requestee != null) { //$NON-NLS-1$
 								fields.put("requestee_type-" + flagTypeNumber, //$NON-NLS-1$
-										new NameValuePair(
-												"requestee_type-" //$NON-NLS-1$
-														+ flagTypeNumber,
+										new NameValuePair("requestee_type-" //$NON-NLS-1$
+												+ flagTypeNumber,
 												requestee.getValue() != null ? requestee.getValue() : "")); //$NON-NLS-1$
 							}
 						}
@@ -1671,9 +1671,8 @@
 						}
 						if (value.equals("?") && requestee != null) { //$NON-NLS-1$
 							fields.put("requestee-" + flagnumber.getValue(), //$NON-NLS-1$
-									new NameValuePair(
-											"requestee-" //$NON-NLS-1$
-													+ flagnumber.getValue(),
+									new NameValuePair("requestee-" //$NON-NLS-1$
+											+ flagnumber.getValue(),
 											requestee.getValue() != null ? requestee.getValue() : "")); //$NON-NLS-1$
 						}
 					} else if (id.startsWith(TaskAttribute.PREFIX_COMMENT)) {
@@ -2687,14 +2686,14 @@
 		GzipGetMethod method = null;
 		try {
 			method = getConnect(loginUrl, monitor);
-			InputStream input = null;
 
 			File file = new File(changeSeparator(transFile, '/', File.separatorChar));
 			file.getParentFile().mkdirs();
 
-			FileOutputStream output = new FileOutputStream(transFile);
-			input = getResponseStream(method, monitor);
-			transferData(input, output);
+			try (InputStream input = getResponseStream(method, monitor);
+					BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(transFile))) {
+				transferData(input, output);
+			}
 		} finally {
 			if (method != null) {
 				WebUtil.releaseConnection(method, monitor);
@@ -2706,6 +2705,7 @@
 		return connector;
 	}
 
+	@SuppressWarnings("restriction")
 	public TaskRepository getTaskRepository() {
 		if (location instanceof TaskRepositoryLocation) {
 			return ((TaskRepositoryLocation) location).getTaskRepository();
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
index 7148fd4..714bd8e 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.mylyn.internal.bugzilla.core;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -206,15 +207,16 @@
 			if (isComplete) {
 				Date completionDate = null;
 
-				List<TaskAttribute> taskComments = taskData.getAttributeMapper().getAttributesByType(taskData,
-						TaskAttribute.TYPE_COMMENT);
+				List<TaskAttribute> taskComments = taskData.getAttributeMapper()
+						.getAttributesByType(taskData, TaskAttribute.TYPE_COMMENT);
 				if (taskComments != null && taskComments.size() > 0) {
 					TaskAttribute lastComment = taskComments.get(taskComments.size() - 1);
 					if (lastComment != null) {
 						TaskAttribute attributeCommentDate = lastComment.getMappedAttribute(TaskAttribute.COMMENT_DATE);
 						if (attributeCommentDate != null) {
 							try {
-								completionDate = new SimpleDateFormat(COMMENT_FORMAT).parse(attributeCommentDate.getValue());
+								completionDate = new SimpleDateFormat(COMMENT_FORMAT)
+										.parse(attributeCommentDate.getValue());
 							} catch (ParseException e) {
 								// ignore
 							}
@@ -224,8 +226,8 @@
 
 				if (completionDate == null) {
 					// Use last modified date
-					TaskAttribute attributeLastModified = taskData.getRoot().getMappedAttribute(
-							TaskAttribute.DATE_MODIFICATION);
+					TaskAttribute attributeLastModified = taskData.getRoot()
+							.getMappedAttribute(TaskAttribute.DATE_MODIFICATION);
 					if (attributeLastModified != null && attributeLastModified.getValue().length() > 0) {
 						completionDate = taskData.getAttributeMapper().getDateValue(attributeLastModified);
 					}
@@ -277,8 +279,8 @@
 
 		monitor = Policy.monitorFor(monitor);
 		try {
-			monitor.beginTask(Messages.BugzillaRepositoryConnector_checking_for_changed_tasks, session.getTasks()
-					.size());
+			monitor.beginTask(Messages.BugzillaRepositoryConnector_checking_for_changed_tasks,
+					session.getTasks().size());
 
 			if (repository.getSynchronizationTimeStamp() == null) {
 				for (ITask task : session.getTasks()) {
@@ -331,15 +333,16 @@
 		} catch (UnsupportedEncodingException e) {
 			throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
 					"Repository configured with unsupported encoding: " + repository.getCharacterEncoding() //$NON-NLS-1$
-					+ "\n\n Unable to determine changed tasks.", e)); //$NON-NLS-1$
+							+ "\n\n Unable to determine changed tasks.", //$NON-NLS-1$
+					e));
 		} finally {
 			monitor.done();
 		}
 	}
 
 	private void queryForChanged(final TaskRepository repository, Set<ITask> changedTasks, String urlQueryString,
-			ISynchronizationSession syncSession, IProgressMonitor monitor) throws UnsupportedEncodingException,
-			CoreException {
+			ISynchronizationSession syncSession, IProgressMonitor monitor)
+			throws UnsupportedEncodingException, CoreException {
 
 		HashMap<String, ITask> taskById = new HashMap<String, ITask>();
 		for (ITask task : syncSession.getTasks()) {
@@ -403,8 +406,8 @@
 			return new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, IStatus.INFO,
 					Messages.BugzillaRepositoryConnector_Unrecognized_response_from_server, e);
 		} catch (IOException e) {
-			return new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, IStatus.ERROR, MessageFormat.format(
-					Messages.BugzillaRepositoryConnector_Check_repository_configuration, e.getMessage()), e);
+			return new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, IStatus.ERROR, MessageFormat
+					.format(Messages.BugzillaRepositoryConnector_Check_repository_configuration, e.getMessage()), e);
 		} catch (CoreException e) {
 			return e.getStatus();
 		} finally {
@@ -460,7 +463,8 @@
 	}
 
 	@Override
-	public void updateRepositoryConfiguration(TaskRepository repository, IProgressMonitor monitor) throws CoreException {
+	public void updateRepositoryConfiguration(TaskRepository repository, IProgressMonitor monitor)
+			throws CoreException {
 		if (repository != null) {
 			getRepositoryConfiguration(repository, true, monitor);
 		}
@@ -663,7 +667,8 @@
 
 			@Override
 			public PriorityLevel getPriorityLevel() {
-				RepositoryConfiguration repositoryConfiguration = BugzillaRepositoryConnector.this.getRepositoryConfiguration(taskData.getRepositoryUrl());
+				RepositoryConfiguration repositoryConfiguration = BugzillaRepositoryConnector.this
+						.getRepositoryConfiguration(taskData.getRepositoryUrl());
 				String priority = getPriority();
 				if (repositoryConfiguration == null) {
 					// When we did not have the configuration we only can use the standard Priorities
@@ -694,8 +699,8 @@
 					}
 				}
 			} catch (Exception e) {
-				StatusHandler.log(new Status(IStatus.INFO, BugzillaCorePlugin.ID_PLUGIN,
-						ERROR_INCOMPATIBLE_CONFIGURATION));
+				StatusHandler
+						.log(new Status(IStatus.INFO, BugzillaCorePlugin.ID_PLUGIN, ERROR_INCOMPATIBLE_CONFIGURATION));
 				try {
 					if (in != null) {
 						in.close();
@@ -779,7 +784,7 @@
 				if (configuration == null) {
 					throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
 							RepositoryStatus.ERROR_INTERNAL, "Failed to retrieve repository configuration for " //$NON-NLS-1$
-							+ repository.getRepositoryUrl().toString()));
+									+ repository.getRepositoryUrl().toString()));
 
 				}
 				return configuration;
@@ -818,32 +823,26 @@
 	/** public for testing */
 	public void writeRepositoryConfigFile() {
 		if (repositoryConfigurationFile != null) {
-			ObjectOutputStream out = null;
 			try {
 				Set<RepositoryConfiguration> tempConfigs;
 				synchronized (repositoryConfigurations) {
 					tempConfigs = new HashSet<RepositoryConfiguration>(repositoryConfigurations.values());
 				}
+
 				if (tempConfigs.size() > 0) {
-					out = new ObjectOutputStream(new FileOutputStream(repositoryConfigurationFile));
-					out.writeInt(tempConfigs.size());
-					for (RepositoryConfiguration repositoryConfiguration : tempConfigs) {
-						if (repositoryConfiguration != null) {
-							out.writeObject(repositoryConfiguration);
+					try (ObjectOutputStream out = new ObjectOutputStream(
+							new BufferedOutputStream(new FileOutputStream(repositoryConfigurationFile)))) {
+						out.writeInt(tempConfigs.size());
+						for (RepositoryConfiguration repositoryConfiguration : tempConfigs) {
+							if (repositoryConfiguration != null) {
+								out.writeObject(repositoryConfiguration);
+							}
 						}
 					}
 				}
 			} catch (IOException e) {
 				StatusHandler.log(new Status(IStatus.WARNING, BugzillaCorePlugin.ID_PLUGIN, 0,
 						"Failed to write repository configuration cache", e)); //$NON-NLS-1$
-			} finally {
-				if (out != null) {
-					try {
-						out.close();
-					} catch (IOException e) {
-						// ignore
-					}
-				}
 			}
 		}
 	}
@@ -860,8 +859,8 @@
 		// set both or none
 		if (null != os && null != platform) {
 			TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
-			TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
-					BugzillaAttribute.REP_PLATFORM.getKey());
+			TaskAttribute platformAttribute = newBugModel.getRoot()
+					.getAttribute(BugzillaAttribute.REP_PLATFORM.getKey());
 
 			// TODO something can still go wrong when the allowed values on the repository change...
 			opSysAttribute.setValue(os);
@@ -879,8 +878,8 @@
 			// Check that the result is in Values, if it is not, set it to other
 			// Defaults to the first of each (sorted) list All, All
 			TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
-			TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
-					BugzillaAttribute.REP_PLATFORM.getKey());
+			TaskAttribute platformAttribute = newBugModel.getRoot()
+					.getAttribute(BugzillaAttribute.REP_PLATFORM.getKey());
 
 			String OS = Platform.getOS();
 			String platform = Platform.getOSArch();
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java
index a9a1ec3..743945e 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java
@@ -58,8 +58,9 @@
 
 	@SuppressWarnings("null")
 	public void testUpdateAttachmentFlags() throws Exception {
-		TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "update of Attachment Flags",
-				"description for testUpdateAttachmentFlags");
+		TaskData taskData = BugzillaFixture.current()
+				.createTask(PrivilegeLevel.USER, "update of Attachment Flags",
+						"description for testUpdateAttachmentFlags");
 		assertNotNull(taskData);
 		int numAttached = taskData.getAttributeMapper()
 				.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
@@ -349,8 +350,8 @@
 
 		taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), client);
 		assertNotNull(taskData);
-		List<TaskAttribute> attachmentAttrs = taskData.getAttributeMapper().getAttributesByType(taskData,
-				TaskAttribute.TYPE_ATTACHMENT);
+		List<TaskAttribute> attachmentAttrs = taskData.getAttributeMapper()
+				.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT);
 		assertEquals(1, attachmentAttrs.size());
 
 		attachmentMapper = TaskAttachmentMapper.createFrom(attachmentAttrs.get(0));
@@ -506,8 +507,8 @@
 		boolean isObsolete[] = { false, true, false, true };
 
 		int index = 0;
-		for (TaskAttribute attribute : taskData.getAttributeMapper().getAttributesByType(taskData,
-				TaskAttribute.TYPE_ATTACHMENT)) {
+		for (TaskAttribute attribute : taskData.getAttributeMapper()
+				.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)) {
 			assertTrue(validateAttachmentAttributes(taskData, attribute, isPatch[index], isObsolete[index], task));
 			index++;
 		}
@@ -551,8 +552,9 @@
 			attachmentMapper.setComment("Context attachment failure Test");
 			attachmentMapper.applyTo(attrAttachment);
 
-			connector.getTaskAttachmentHandler().postContent(repository, task, attachment,
-					attachmentMapper.getComment(), attrAttachment, new NullProgressMonitor());
+			connector.getTaskAttachmentHandler()
+					.postContent(repository, task, attachment, attachmentMapper.getComment(), attrAttachment,
+							new NullProgressMonitor());
 		} catch (CoreException e) {
 			assertTrue(BugzillaTestSupportUtil.isInvalidLogon(e));
 			assertEquals(SynchronizationState.SYNCHRONIZED, task.getSynchronizationState());
@@ -562,8 +564,9 @@
 	}
 
 	public void testDownloadAttachmentFile() throws Exception {
-		TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "update of Attachment Flags",
-				"description for testUpdateAttachmentFlags");
+		TaskData taskData = BugzillaFixture.current()
+				.createTask(PrivilegeLevel.USER, "update of Attachment Flags",
+						"description for testUpdateAttachmentFlags");
 		assertNotNull(taskData);
 		int numAttached = taskData.getAttributeMapper()
 				.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
@@ -609,11 +612,8 @@
 		ITaskAttachment taskAttachment;
 		taskAttachment = new TaskAttachment(repository, iTask, attachmentAttribute);
 
-		OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
-		try {
+		try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
 			AttachmentUtil.downloadAttachment(taskAttachment, out, new NullProgressMonitor());
-		} finally {
-			out.close();
 		}
 		FileInputStream raf = new FileInputStream(file);
 
@@ -630,8 +630,9 @@
 	}
 
 	public void testDownloadNonExsistingAttachmentFile() throws Exception {
-		TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "update of Attachment Flags",
-				"description for testUpdateAttachmentFlags");
+		TaskData taskData = BugzillaFixture.current()
+				.createTask(PrivilegeLevel.USER, "update of Attachment Flags",
+						"description for testUpdateAttachmentFlags");
 		assertNotNull(taskData);
 		int numAttached = taskData.getAttributeMapper()
 				.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
@@ -678,14 +679,11 @@
 		ITaskAttachment taskAttachment;
 		taskAttachment = new TaskAttachment(repository, iTask, attachmentAttribute);
 
-		OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
-		try {
+		try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
 			AttachmentUtil.downloadAttachment(taskAttachment, out, new NullProgressMonitor());
 		} catch (CoreException e) {
 			String message = e.getMessage();
 			assertTrue(message.startsWith("invalid attachment id: "));
-		} finally {
-			out.close();
 		}
 	}
 }
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java
index 252373c..428a1df 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java
@@ -10,6 +10,7 @@
  *******************************************************************************/
 package org.eclipse.mylyn.tasks.core;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -160,9 +161,8 @@
 			return;
 		}
 
-		ObjectOutputStream out = null;
-		try {
-			out = new ObjectOutputStream(new FileOutputStream(cacheFile));
+		try (ObjectOutputStream out = new ObjectOutputStream(
+				new BufferedOutputStream(new FileOutputStream(cacheFile)))) {
 			out.writeInt(respoitoryConfigurationByUrl.size());
 			for (String url : respoitoryConfigurationByUrl.keySet()) {
 				out.writeObject(url);
@@ -170,14 +170,6 @@
 			}
 		} catch (IOException e) {
 			handleError("The respository configuration cache could not be written", e); //$NON-NLS-1$
-		} finally {
-			if (out != null) {
-				try {
-					out.close();
-				} catch (IOException e) {
-					// ignore
-				}
-			}
 		}
 	}
 
diff --git a/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java b/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java
index c131733..b8bd0ba 100644
--- a/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java
+++ b/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java
@@ -13,6 +13,7 @@
 
 import static org.junit.Assert.assertTrue;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -50,15 +51,12 @@
 	private void corruptFile(File file) throws IOException {
 		Random random = new Random(123);
 		long length = file.length();
-		OutputStream stream = new FileOutputStream(file);
-		try {
+		try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) {
 			byte[] bytes = new byte[1];
 			for (long i = 0; i < length; ++i) {
 				random.nextBytes(bytes);
 				stream.write(bytes[0]);
 			}
-		} finally {
-			stream.close();
 		}
 	}
 
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java
index 51b5f98..b30562f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.mylyn.internal.tasks.ui;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -82,9 +83,9 @@
 		file.deleteOnExit();
 
 		boolean ok = false;
-		FileOutputStream fos = null;
+		BufferedOutputStream fos = null;
 		try {
-			fos = new FileOutputStream(file);
+			fos = new BufferedOutputStream(new FileOutputStream(file));
 			AttachmentUtil.downloadAttachment(attachment, fos, monitor);
 			ok = true;
 
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java
index a0e72cd..7aed65c 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.mylyn.internal.tasks.ui.wizards;
 
+import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -67,7 +68,7 @@
 
 /**
  * A wizard to add a new attachment to a task report.
- * 
+ *
  * @since 3.0
  * @author Steffen Pingel
  */
@@ -216,11 +217,8 @@
 						ImageLoader loader = new ImageLoader();
 						loader.data = new ImageData[] { image.getImageData() };
 						// TODO create image in memory?
-						FileOutputStream out = new FileOutputStream(file);
-						try {
+						try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
 							loader.save(out, SWT.IMAGE_PNG);
-						} finally {
-							out.close();
 						}
 					} finally {
 						image.dispose();
@@ -314,8 +312,8 @@
 		previewPage = new AttachmentPreviewPage(model);
 		addPage(previewPage);
 
-		AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(model.getTaskRepository()
-				.getConnectorKind());
+		AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin
+				.getConnectorUi(model.getTaskRepository().getConnectorKind());
 		editPage = connectorUi.getTaskAttachmentPage(model);
 		addPage(editPage);
 
@@ -352,8 +350,8 @@
 	@Override
 	public boolean performFinish() {
 		SubmitJob job = TasksUiInternal.getJobFactory()
-				.createSubmitTaskAttachmentJob(connector, model.getTaskRepository(), model.getTask(),
-						model.getSource(), model.getComment(), model.getAttribute());
+				.createSubmitTaskAttachmentJob(connector, model.getTaskRepository(), model.getTask(), model.getSource(),
+						model.getComment(), model.getAttribute());
 		final boolean attachContext = model.getAttachContext();
 		job.addSubmitJobListener(new SubmitJobListener() {
 			@Override
@@ -420,7 +418,8 @@
 			return job.getStatus() == null;
 		} catch (InvocationTargetException e) {
 			StatusManager.getManager()
-					.handle(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unexpected error", e), StatusManager.SHOW | StatusManager.LOG); //$NON-NLS-1$
+					.handle(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unexpected error", e), //$NON-NLS-1$
+							StatusManager.SHOW | StatusManager.LOG);
 			return false;
 		} catch (InterruptedException e) {
 			// canceled
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
index 99af02c..e6c22b1 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
@@ -11,6 +11,7 @@
 
 package org.eclipse.mylyn.internal.trac.core;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -33,7 +34,7 @@
 
 /**
  * Caches {@link ITracClient} objects.
- * 
+ *
  * @author Steffen Pingel
  */
 public class TracClientManager implements IRepositoryListener {
@@ -134,10 +135,8 @@
 		if (cacheFile == null) {
 			return;
 		}
-
-		ObjectOutputStream out = null;
-		try {
-			out = new ObjectOutputStream(new FileOutputStream(cacheFile));
+		try (ObjectOutputStream out = new ObjectOutputStream(
+				new BufferedOutputStream(new FileOutputStream(cacheFile)))) {
 			out.writeInt(clientDataByUrl.size());
 			for (String url : clientDataByUrl.keySet()) {
 				out.writeObject(url);
@@ -146,14 +145,6 @@
 		} catch (IOException e) {
 			StatusHandler.log(new Status(IStatus.WARNING, TracCorePlugin.ID_PLUGIN,
 					"The Trac respository configuration cache could not be written", e)); //$NON-NLS-1$
-		} finally {
-			if (out != null) {
-				try {
-					out.close();
-				} catch (IOException e) {
-					// ignore
-				}
-			}
 		}
 	}
 
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java
index fe3ea5e..f268ffa 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java
@@ -17,8 +17,6 @@
 import java.io.OutputStream;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource;
 import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector;
 import org.eclipse.mylyn.internal.trac.core.client.ITracClient;
@@ -31,6 +29,8 @@
 import org.eclipse.mylyn.trac.tests.support.TracHarness;
 import org.eclipse.mylyn.trac.tests.support.TracTestUtil;
 
+import junit.framework.TestCase;
+
 /**
  * @author Steffen Pingel
  */
@@ -79,22 +79,16 @@
 		ITask task = harness.createTask("GetContent");
 		File file = File.createTempFile("attachment", null);
 		file.deleteOnExit();
-		OutputStream out = new FileOutputStream(file);
-		try {
+		try (OutputStream out = new FileOutputStream(file)) {
 			out.write("Mylar".getBytes());
-		} finally {
-			out.close();
 		}
 		attachmentHandler.postContent(repository, task, new FileTaskAttachmentSource(file), "comment", null, null);
 
 		ITracClient client = connector.getClientManager().getTracClient(repository);
-		InputStream in = client.getAttachmentData(Integer.parseInt(task.getTaskId()), file.getName(), null);
-		try {
+		try (InputStream in = client.getAttachmentData(Integer.parseInt(task.getTaskId()), file.getName(), null)) {
 			byte[] result = new byte[5];
 			in.read(result);
 			assertEquals("Mylar", new String(result));
-		} finally {
-			in.close();
 		}
 	}