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:");
* 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();
ByteBuffer block = getBlockAt(bat.getOurBlockIndex());
BlockAllocationTableWriter.writeBlock(bat, block);
}
-
- // SBATs
- _mini_store.syncWithDataSource();
}
/**
}
/**
- * 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);
}
}
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();
}