Skip to content

Commit 64f88ca

Browse files
EcljpseB0Tjukzi
authored andcommitted
use IFile bulk API
1 parent 3ad19a5 commit 64f88ca

File tree

7 files changed

+14
-25
lines changed

7 files changed

+14
-25
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,8 @@ public void delete(IResource target, int flags, IProgressMonitor monitor) throws
424424
* are not considered.
425425
*/
426426
private boolean descriptionChanged(IFile descriptionFile, byte[] newContents) {
427-
//buffer size: twice the description length, but maximum 8KB
428-
int bufsize = newContents.length > 4096 ? 8192 : newContents.length * 2;
429-
try (
430-
InputStream oldStream = new BufferedInputStream(descriptionFile.getContents(true), bufsize);
431-
) {
427+
try {
428+
InputStream oldStream = new ByteArrayInputStream(descriptionFile.readAllBytes());
432429
InputStream newStream = new ByteArrayInputStream(newContents);
433430
//compare streams char by char, ignoring line endings
434431
int newChar = newStream.read();

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/FilteredResourceTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static org.eclipse.core.tests.resources.ResourceTestUtil.removeFromWorkspace;
2525
import static org.junit.Assert.assertThrows;
2626

27-
import java.io.ByteArrayInputStream;
2827
import java.io.ByteArrayOutputStream;
2928
import java.io.File;
3029
import java.io.IOException;
@@ -488,9 +487,7 @@ private void modifyFileInWorkspace(final IFile file) throws IOException, CoreExc
488487
fileInputStream.transferTo(originalContentStream);
489488
String originalContent = new String(originalContentStream.toByteArray(), StandardCharsets.UTF_8);
490489
String newContent = originalContent + "w";
491-
ByteArrayInputStream modifiedContentStream = new ByteArrayInputStream(
492-
newContent.getBytes(StandardCharsets.UTF_8));
493-
file.setContents(modifiedContentStream, false, false, null);
490+
file.setContents(newContent.getBytes(StandardCharsets.UTF_8), false, false, null);
494491
}
495492
}
496493

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/IProjectTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import static org.junit.Assert.assertTrue;
4040
import static org.junit.Assume.assumeTrue;
4141

42-
import java.io.ByteArrayInputStream;
4342
import org.eclipse.core.filesystem.EFS;
4443
import org.eclipse.core.filesystem.IFileStore;
4544
import org.eclipse.core.internal.resources.Resource;
@@ -2550,7 +2549,7 @@ public void testProjectDeletion_Bug347220() throws CoreException {
25502549

25512550
// modify the file to create an entry in the history
25522551
monitor.prepare();
2553-
file.setContents(new ByteArrayInputStream(createRandomString().getBytes()), true, true, monitor);
2552+
file.setContents(createRandomString().getBytes(), true, true, monitor);
25542553
monitor.assertUsedUp();
25552554

25562555
// delete the project and check that its metadata is also deleted

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/LinkedResourceWithPathVariableTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public void testFileVariableRemoved() throws Exception {
273273
assertNotNull("5.1", file.getLocation());
274274
assertExistsInFileSystem(file);
275275
// the contents must be the original ones
276-
assertTrue("5.3", compareContent(file.getContents(true), createInputStream("contents for a file")));
276+
assertEquals("5.3", "contents for a file", file.readString());
277277
}
278278

279279
/**
@@ -330,7 +330,7 @@ public void testFileProjectVariableRemoved() throws Exception {
330330
assertNotNull("5.1", file.getLocation());
331331
assertExistsInFileSystem(file);
332332
// the contents must be the original ones
333-
assertTrue("5.3", compareContent(file.getContents(true), createInputStream("contents for a file")));
333+
assertEquals("5.3", "contents for a file", file.readString());
334334
}
335335

336336
/**
@@ -509,7 +509,7 @@ public void testFileProjectRelativeVariableRemoved() throws Exception {
509509
assertDoesNotExistInWorkspace(file);
510510

511511
file.createLink(variableBasedLocation, IResource.ALLOW_MISSING_LOCAL, null);
512-
file.setContents(createInputStream("contents for a file"), IResource.FORCE, null);
512+
file.setContents("contents for a file".getBytes(), IResource.FORCE, null);
513513

514514
// now the file exists in both workspace and file system
515515
assertExistsInWorkspace(file);
@@ -545,7 +545,7 @@ public void testFileProjectRelativeVariableRemoved() throws Exception {
545545
assertNotNull("5.1", file.getLocation());
546546
assertExistsInFileSystem(file);
547547
// the contents must be the original ones
548-
assertTrue("5.3", compareContent(file.getContents(true), createInputStream("contents for a file")));
548+
assertEquals("5.3", "contents for a file", file.readString());
549549
}
550550

551551
/**
@@ -859,7 +859,7 @@ public void testVariableChanged() throws Exception {
859859
assertExistsInWorkspace(file);
860860
assertExistsInFileSystem(file);
861861
// the contents must be the original ones
862-
assertTrue("5.3", compareContent(file.getContents(true), createInputStream("contents for a file")));
862+
assertEquals("5.3", "contents for a file", file.readString());
863863
}
864864

865865
/**
@@ -925,7 +925,7 @@ public void testProjectVariableChanged() throws Exception {
925925
assertExistsInWorkspace(file);
926926
assertExistsInFileSystem(file);
927927
// the contents must be the original ones
928-
assertTrue("5.3", compareContent(file.getContents(true), createInputStream("contents for a file")));
928+
assertEquals("5.3", "contents for a file", file.readString());
929929
}
930930

931931
/**

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public void setUp() throws Exception {
319319
assertTrue(fileTarget.exists());
320320
String testString = createRandomString();
321321
monitor = new FussyProgressMonitor();
322-
fileTarget.setContents(createInputStream(testString), true, false, monitor);
322+
fileTarget.setContents(testString.getBytes(), true, false, monitor);
323323
monitor.assertUsedUp();
324324
try (InputStream content = fileTarget.getContents(false)) {
325325
assertTrue("get not equal set", compareContent(content, createInputStream(testString)));

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/Bug_303517.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,14 @@ public void testGetContentsTrue() throws Exception {
134134

135135
// Touch on file-system
136136
touchInFilesystem(f);
137-
try (InputStream in = f.getContents(true)) {
138-
}
137+
f.readAllBytes();
139138

140139
// Wait for auto-refresh to happen
141140
Job.getJobManager().wakeUp(ResourcesPlugin.FAMILY_AUTO_REFRESH);
142141
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_REFRESH, createTestMonitor());
143142

144143
// File is now in sync.
145-
try (InputStream in = f.getContents()) {
146-
}
144+
f.readAllBytes();
147145

148146
// Test that getContent(true) on an out-if-sync deleted file throws a CoreException
149147
// with IResourceStatus.RESOURCE_NOT_FOUND error code.

resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IResourceTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,7 @@ public void testGetContents_1GBZD4S() throws Throwable {
471471
});
472472
IResourceChangeListener listener = event -> {
473473
listenerInMainThreadCallback.set(() -> {
474-
try (InputStream is = target.getContents(true)) {
475-
assertTrue("4.0", compareContent(createInputStream(newContents), is));
476-
}
474+
assertEquals("4.0", newContents, target.readString());
477475
});
478476
};
479477
try {

0 commit comments

Comments
 (0)