Skip to content

Commit 4bc9111

Browse files
EcljpseB0Tjukzi
authored andcommitted
IFile.createOrReplace() example usage
1 parent 3007284 commit 4bc9111

File tree

5 files changed

+10
-26
lines changed

5 files changed

+10
-26
lines changed

team/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/BufferedResourceNode.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*******************************************************************************/
1414
package org.eclipse.compare.internal;
1515

16-
import java.io.ByteArrayInputStream;
1716
import java.io.IOException;
1817
import java.io.InputStream;
1918

@@ -73,18 +72,10 @@ public void commit(IProgressMonitor pm) throws CoreException {
7372
return;
7473
}
7574
IResource resource = getResource();
76-
if (resource instanceof IFile) {
75+
if (resource instanceof IFile file) {
7776
byte[] bytes = getContent();
78-
try (ByteArrayInputStream is = new ByteArrayInputStream(bytes)) {
79-
IFile file = (IFile) resource;
80-
if (file.exists())
81-
file.setContents(is, false, true, pm);
82-
else
83-
file.create(is, false, pm);
84-
fDirty = false;
85-
} catch (IOException closeException) {
86-
// Silently ignored
87-
}
77+
file.createOrReplace(bytes, false, false, true, pm);
78+
fDirty = false;
8879
}
8980
}
9081
}

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceTypedElement.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*******************************************************************************/
1414
package org.eclipse.team.internal.ui.synchronize;
1515

16-
import java.io.ByteArrayInputStream;
17-
import java.io.IOException;
1816
import java.io.InputStream;
1917

2018
import org.eclipse.compare.ISharedDocumentAdapter;
@@ -93,16 +91,11 @@ public void commit(IProgressMonitor monitor) throws CoreException {
9391
saveDocument(true, monitor);
9492
} else {
9593
IResource resource = getResource();
96-
if (resource instanceof IFile) {
97-
try (ByteArrayInputStream is = new ByteArrayInputStream(getContent())) {
98-
IFile file = (IFile) resource;
99-
if (file.exists())
100-
file.setContents(is, false, true, monitor);
101-
else
102-
file.create(is, false, monitor);
94+
if (resource instanceof IFile file) {
95+
byte[] content = getContent();
96+
try {
97+
file.createOrReplace(content, false, false, true, monitor);
10398
fDirty = false;
104-
} catch (IOException closeException) {
105-
// ignored
10699
} finally {
107100
fireContentChanged();
108101
}

team/examples/org.eclipse.team.examples.filesystem/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.team.examples.filesystem; singleton:=true
5-
Bundle-Version: 3.7.400.qualifier
5+
Bundle-Version: 3.7.500.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Export-Package: org.eclipse.team.examples.filesystem,

team/examples/org.eclipse.team.examples.filesystem/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<relativePath>../../</relativePath>
1919
</parent>
2020
<artifactId>org.eclipse.team.examples.filesystem</artifactId>
21-
<version>3.7.400-SNAPSHOT</version>
21+
<version>3.7.500-SNAPSHOT</version>
2222
<packaging>eclipse-plugin</packaging>
2323
<build>
2424
<plugins>

team/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public void appendText(IFile file, String text, boolean prepend) throws CoreExce
584584
if (!prepend) {
585585
buffer.append(System.getProperty("line.separator") + text);
586586
}
587-
file.setContents(new ByteArrayInputStream(buffer.toString().getBytes()), false, false, null);
587+
file.setContents(buffer.toString().getBytes(), false, false, null);
588588
}
589589

590590
public static String getFileContents(IFile file) throws IOException, CoreException {

0 commit comments

Comments
 (0)