diff --git a/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java b/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java index 7846ed0df..9492c2598 100644 --- a/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java +++ b/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java @@ -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; } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java index b4e3b79af..144437483 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java @@ -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);