Skip to content

Commit

Permalink
IFile.createOrReplace() example usage
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jun 14, 2024
1 parent 3007284 commit 4bc9111
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.compare.internal;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

Expand Down Expand Up @@ -73,18 +72,10 @@ public void commit(IProgressMonitor pm) throws CoreException {
return;
}
IResource resource = getResource();
if (resource instanceof IFile) {
if (resource instanceof IFile file) {
byte[] bytes = getContent();
try (ByteArrayInputStream is = new ByteArrayInputStream(bytes)) {
IFile file = (IFile) resource;
if (file.exists())
file.setContents(is, false, true, pm);
else
file.create(is, false, pm);
fDirty = false;
} catch (IOException closeException) {
// Silently ignored
}
file.createOrReplace(bytes, false, false, true, pm);
fDirty = false;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.synchronize;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.eclipse.compare.ISharedDocumentAdapter;
Expand Down Expand Up @@ -93,16 +91,11 @@ public void commit(IProgressMonitor monitor) throws CoreException {
saveDocument(true, monitor);
} else {
IResource resource = getResource();
if (resource instanceof IFile) {
try (ByteArrayInputStream is = new ByteArrayInputStream(getContent())) {
IFile file = (IFile) resource;
if (file.exists())
file.setContents(is, false, true, monitor);
else
file.create(is, false, monitor);
if (resource instanceof IFile file) {
byte[] content = getContent();
try {
file.createOrReplace(content, false, false, true, monitor);
fDirty = false;
} catch (IOException closeException) {
// ignored
} finally {
fireContentChanged();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.team.examples.filesystem; singleton:=true
Bundle-Version: 3.7.400.qualifier
Bundle-Version: 3.7.500.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.team.examples.filesystem,
Expand Down
2 changes: 1 addition & 1 deletion team/examples/org.eclipse.team.examples.filesystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<relativePath>../../</relativePath>
</parent>
<artifactId>org.eclipse.team.examples.filesystem</artifactId>
<version>3.7.400-SNAPSHOT</version>
<version>3.7.500-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public void appendText(IFile file, String text, boolean prepend) throws CoreExce
if (!prepend) {
buffer.append(System.getProperty("line.separator") + text);
}
file.setContents(new ByteArrayInputStream(buffer.toString().getBytes()), false, false, null);
file.setContents(buffer.toString().getBytes(), false, false, null);
}

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

0 comments on commit 4bc9111

Please sign in to comment.