]> source.dussan.org Git - poi.git/commitdiff
When writing the mini-stream, set the size of it on the root property #58061
authorNick Burch <nick@apache.org>
Mon, 6 Jul 2015 21:39:42 +0000 (21:39 +0000)
committerNick Burch <nick@apache.org>
Mon, 6 Jul 2015 21:39:42 +0000 (21:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1689505 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/dev/POIFSHeaderDumper.java
src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
src/java/org/apache/poi/poifs/filesystem/NPOIFSMiniStore.java
src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java

index 54ab231493a7926627804d4c638504dbe3b4748d..e321c8b9b70a65afe3ab5d1415d327e3c0ca8dd7 100644 (file)
@@ -160,6 +160,7 @@ public class POIFSHeaderDumper {
 
     public static void displayPropertiesSummary(PropertyTable properties) {
         System.out.println("Mini Stream starts at " + properties.getRoot().getStartBlock());
+        System.out.println("Mini Stream length is " + properties.getRoot().getSize());
         System.out.println();
         
         System.out.println("Properties and their block start:");
index f7e19137a62859b759a90e626a43d5009c90f088..c27ba3cd1404782c70083ad55f58f1cfb8e28cf3 100644 (file)
@@ -766,6 +766,10 @@ public class NPOIFSFileSystem extends BlockStore
      *  to their backing blocks 
      */
     private void syncWithDataSource() throws IOException {
+        // Mini Stream + SBATs first, as mini-stream details have
+        //  to be stored in the Root Property
+        _mini_store.syncWithDataSource();
+        
         // Properties
         NPOIFSStream propStream = new NPOIFSStream(this, _header.getPropertyStart());
         _property_table.preWrite();
@@ -786,9 +790,6 @@ public class NPOIFSFileSystem extends BlockStore
            ByteBuffer block = getBlockAt(bat.getOurBlockIndex());
            BlockAllocationTableWriter.writeBlock(bat, block);
         }
-       
-       // SBATs
-       _mini_store.syncWithDataSource();
     }
     
     /**
index 308ae15c74bd4ecb3cef974920de25d3b1790510..b784058bc56bb8ff6a64b3ac07637dcec1897103 100644 (file)
@@ -242,12 +242,24 @@ public class NPOIFSMiniStore extends BlockStore
     }
     
     /**
-     * Writes the SBATs to their backing blocks
+     * Writes the SBATs to their backing blocks, and updates
+     *  the mini-stream size in the properties. Stream size is
+     *  based on full blocks used, not the data within the streams
      */
     protected void syncWithDataSource() throws IOException {
-       for(BATBlock sbat : _sbat_blocks) {
+       int blocksUsed = 0;
+       for (BATBlock sbat : _sbat_blocks) {
           ByteBuffer block = _filesystem.getBlockAt(sbat.getOurBlockIndex());
           BlockAllocationTableWriter.writeBlock(sbat, block);
+          
+          if (!sbat.hasFreeSectors()) {
+              blocksUsed += _filesystem.getBigBlockSizeDetails().getBATEntriesPerBlock();
+          } else {
+              blocksUsed += sbat.getUsedSectors(false);
+          }
        }
+       // Set the size on the root in terms of the number of SBAT blocks
+       // RootProperty.setSize does the sbat -> bytes conversion for us
+       _filesystem._get_property_table().getRoot().setSize(blocksUsed);
     }
 }
index a476233ec729affbb8a1585540ad1757ef884f9e..ed598ed6cc0c3e840cd04163eb23892d47751ba0 100644 (file)
@@ -1428,6 +1428,10 @@ public final class TestNPOIFSFileSystem {
        emptyDoc = (DocumentEntry)testDir.getEntry("empty-3");
        assertContentsMatches(empty, emptyDoc);
        
+       // Check that a mini-stream was assigned, with one block used
+       assertEquals(3, testDir.getProperty().getStartBlock()); 
+       assertEquals(64, testDir.getProperty().getSize()); 
+       
        // All done
        fs.close();
    }