]> source.dussan.org Git - poi.git/commitdiff
Correct zero byte entry support in NPOIFS
authorNick Burch <nick@apache.org>
Mon, 11 May 2015 17:53:59 +0000 (17:53 +0000)
committerNick Burch <nick@apache.org>
Mon, 11 May 2015 17:53:59 +0000 (17:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678778 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java

index 7846ed0dfc4744a14a90ad196327fc3c29180a02..9492c2598339fbfeeee6b2b53fadac9b0c31fb89 100644 (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;
    }
    
index b4e3b79af48385e14a98ac6a439bf51829210fc1..144437483324b448869cdda8a4ec5c19a91ccd74 100644 (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);