Correct zero byte entry support in NPOIFS

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2015-05-11 17:53:59 +00:00
parent 0d95d3df70
commit 1945dfc00c
2 changed files with 6 additions and 3 deletions

View File

@ -143,8 +143,12 @@ public final class NPOIFSDocument implements POIFSViewable {
os.write(buf, 0, readBytes);
}
os.close();
// If this is an empty document, write a single byte
// to force a block allocation for this document
if (length == 0) os.write(0);
// Tidy and return the length
os.close();
return length;
}

View File

@ -41,7 +41,6 @@ import org.apache.poi.poifs.property.Property;
import org.apache.poi.poifs.property.RootProperty;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
import org.junit.Ignore;
import org.junit.Test;
/**
@ -1307,7 +1306,6 @@ public final class TestNPOIFSFileSystem {
assertContentsMatches(main4106, normDoc);
}
@Ignore
@Test
public void writeZeroLengthEntries() throws Exception {
NPOIFSFileSystem fs = new NPOIFSFileSystem();
@ -1350,6 +1348,7 @@ public final class TestNPOIFSFileSystem {
// Save and re-check
fs = writeOutAndReadBack(fs);
testDir = fs.getRoot();
miniDoc = (DocumentEntry)testDir.getEntry("Mini2");
assertContentsMatches(mini2, miniDoc);