diff options
author | Alexander Kurtakov | 2018-07-18 13:59:58 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2018-07-18 15:10:39 +0000 |
commit | ef3fedaa1552b42f3f0d8b2e64334e6cce484353 (patch) | |
tree | 031d05b567274cf8f4aa897014fc1cc526b323b1 | |
parent | 982b689404fbe86e68a1a36dd5460d4183fe9097 (diff) | |
download | eclipse.platform.text-ef3fedaa1552b42f3f0d8b2e64334e6cce484353.tar.gz eclipse.platform.text-ef3fedaa1552b42f3f0d8b2e64334e6cce484353.tar.xz eclipse.platform.text-ef3fedaa1552b42f3f0d8b2e64334e6cce484353.zip |
Try-with-resources warnings fixes in core.filebuffers.tests.
Change-Id: Ic535ad541de1e02e64a720b4624590352718f49d
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
4 files changed, 10 insertions, 33 deletions
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java index 187a75af698..624369a0a73 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForFilesInLinkedFolders.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -110,14 +110,11 @@ public class FileBuffersForFilesInLinkedFolders extends FileBufferFunctions { protected boolean modifyUnderlyingFile() throws Exception { IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); assertTrue(fileStore.fetchInfo().exists()); - OutputStream out= fileStore.openOutputStream(EFS.NONE, null); - try { + try (OutputStream out= fileStore.openOutputStream(EFS.NONE, null)) { out.write("Changed content of file in linked folder".getBytes()); out.flush(); } catch (IOException x) { fail(); - } finally { - out.close(); } IFileInfo fileInfo= fileStore.fetchInfo(); fileInfo.setLastModified(1000); diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java index 4a9bc2dddfa..970c6c72420 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForWorkspaceFiles.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -89,14 +89,11 @@ public class FileBuffersForWorkspaceFiles extends FileBufferFunctions { protected boolean modifyUnderlyingFile() throws Exception { IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); assertTrue(fileStore.fetchInfo().exists()); - OutputStream out= fileStore.openOutputStream(EFS.NONE, null); - try { + try (OutputStream out= fileStore.openOutputStream(EFS.NONE, null)) { out.write("Changed content of workspace file".getBytes()); out.flush(); } catch (IOException x) { fail(); - } finally { - out.close(); } IFileInfo fileInfo= fileStore.fetchInfo(); fileInfo.setLastModified(1000); diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java index d52e6f75b57..347a32a0167 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForWorkspaceFiles.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 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 @@ -89,14 +89,11 @@ public class FileStoreFileBuffersForWorkspaceFiles extends FileBufferFunctions { protected boolean modifyUnderlyingFile() throws Exception { IFileStore fileStore= FileBuffers.getFileStoreAtLocation(getPath()); assertTrue(fileStore.fetchInfo().exists()); - OutputStream out= fileStore.openOutputStream(EFS.NONE, null); - try { + try (OutputStream out= fileStore.openOutputStream(EFS.NONE, null)) { out.write("Changed content of workspace file".getBytes()); out.flush(); } catch (IOException x) { fail(); - } finally { - out.close(); } IFileInfo fileInfo= fileStore.fetchInfo(); fileInfo.setLastModified(1000); diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java index 0e4f3dc282e..52b4f085f6a 100644 --- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java +++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -102,17 +102,9 @@ public class FileTool { */ public static void transferData(File source, File destination) throws IOException { destination.getParentFile().mkdirs(); - InputStream is = null; - OutputStream os = null; - try { - is = new FileInputStream(source); - os = new FileOutputStream(destination); + try (InputStream is= new FileInputStream(source); + OutputStream os= new FileOutputStream(destination)) { transferData(is, os); - } finally { - if(os != null) - os.close(); - if(is != null) - is.close(); } } @@ -196,14 +188,8 @@ public class FileTool { } public static void write(String fileName, StringBuffer content) throws IOException { - Writer writer= new FileWriter(fileName); - try { + try (Writer writer= new FileWriter(fileName)) { writer.write(content.toString()); - } finally { - try { - writer.close(); - } catch (IOException e) { - } } } |