JS: reset file size to 0 when creating FileOutputStream

Fix #558
This commit is contained in:
Alexey Andreev 2021-03-06 19:38:49 +03:00
parent 6ef841a560
commit ddf194af31
2 changed files with 22 additions and 0 deletions

View File

@ -63,6 +63,8 @@ public class InMemoryVirtualFile extends AbstractInMemoryVirtualFile {
{
if (append) {
pos = size;
} else if (writable) {
size = 0;
}
}

View File

@ -283,6 +283,26 @@ public class FileOutputStreamTest {
fos.close();
}
@Test
public void repeatedWrite() throws IOException {
f = new File(System.getProperty("user.home"), "test.txt");
fos = new FileOutputStream(f);
fos.write("A very long test string for purposes of testing.".getBytes());
fos.close();
fos = new FileOutputStream(f);
fos.write("A short string.".getBytes());
fos.close();
int length = (int) f.length();
byte[] bytes = new byte[length];
fis = new FileInputStream(f);
fis.read(bytes, 0, length);
String str = new String(bytes);
assertEquals("A short string.", str);
}
@After
public void tearDown() throws Exception {
if (f != null) {