Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-05-25 13:38:32 +0000
committerKarsten Thoms2019-09-25 18:52:27 +0000
commit46ff79e0c747ec2308cff542015e4b82d6882472 (patch)
tree8402cbf7e54a5fa2c1adb7f9bdd3fbd604ddfd25 /examples
parentc869c9dfb29c62db5a39b440b425eea6bb85caac (diff)
downloadeclipse.platform.team-46ff79e0c747ec2308cff542015e4b82d6882472.tar.gz
eclipse.platform.team-46ff79e0c747ec2308cff542015e4b82d6882472.tar.xz
eclipse.platform.team-46ff79e0c747ec2308cff542015e4b82d6882472.zip
Use try-with-resourcesI20190926-0625
Convert try finally block to try-with-resources Change-Id: Iff35bb041daf77cd29f9c17ee931c8b2de186e4c Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
Diffstat (limited to 'examples')
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java24
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java5
2 files changed, 10 insertions, 19 deletions
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 46276b40a..91afa6e69 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 @@ public class FileSystemOperations {
// 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 e85f5fff1..f7a8b7e41 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 class PessimisticFilesystemProvider extends RepositoryProvider {
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();
}

Back to the top