Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAtaul Ahmad2017-07-17 14:49:44 -0400
committerAlexander Kurtakov2017-07-18 02:38:15 -0400
commit3e47faa229a8e5a2cadb0f5b9c853ed0c6981448 (patch)
treed16fe1fcea47793c07918a0f2d8c182d0f19b44e
parent352230c0303585a1388b9bcb744d91e4ff889cc6 (diff)
downloadeclipse.platform.text-3e47faa229a8e5a2cadb0f5b9c853ed0c6981448.tar.gz
eclipse.platform.text-3e47faa229a8e5a2cadb0f5b9c853ed0c6981448.tar.xz
eclipse.platform.text-3e47faa229a8e5a2cadb0f5b9c853ed0c6981448.zip
Bug 519778 - org.eclipse.search.tests should use try-with-resources
Change-Id: I2ff1b0e128723c41772aa956e5acda83ebb5338c Signed-off-by: Ataul Ahmad <ataul@ahmadsoft.de>
-rw-r--r--org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java54
-rw-r--r--org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java9
2 files changed, 16 insertions, 47 deletions
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java
index 160ac8fe9..20550b158 100644
--- a/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java
+++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/FileTool.java
@@ -61,25 +61,12 @@ public class FileTool {
String entryName = entry.getName();
File file = new File(dstDir, changeSeparator(entryName, '/', File.separatorChar));
file.getParentFile().mkdirs();
- InputStream src = null;
- OutputStream dst = null;
- try {
- src = zipFile.getInputStream(entry);
- dst = new FileOutputStream(file);
+
+ try (
+ InputStream src = zipFile.getInputStream(entry);
+ OutputStream dst = new FileOutputStream(file);
+ ) {
transferData(src, dst);
- } finally {
- if(dst != null){
- try {
- dst.close();
- } catch(IOException e){
- }
- }
- if(src != null){
- try {
- src.close();
- } catch(IOException e){
- }
- }
}
}
} finally {
@@ -116,25 +103,12 @@ 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){
- try {
- os.close();
- } catch(IOException e){
- }
- }
- if(is != null){
- try {
- is.close();
- } catch(IOException e){
- }
- }
}
}
@@ -215,14 +189,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) {
- }
}
}
diff --git a/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java b/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java
index fe28661cc..b9a030b7f 100644
--- a/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java
+++ b/org.eclipse.search.tests/src/org/eclipse/search/tests/ResourceHelper.java
@@ -114,10 +114,11 @@ public class ResourceHelper {
IFile file= folder.getFile(name);
if (contents == null)
contents= ""; //$NON-NLS-1$
- InputStream inputStream= new ByteArrayInputStream(contents.getBytes(encoding));
- file.create(inputStream, true, NULL_MONITOR);
- file.setCharset(encoding, null);
- inputStream.close();
+ try (InputStream inputStream= new ByteArrayInputStream(contents.getBytes(encoding))) {
+ file.create(inputStream, true, NULL_MONITOR);
+ file.setCharset(encoding, null);
+ }
+
return file;
}

Back to the top