When writing the mini-stream, set the size of it on the root property #58061
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1689505 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
08b74eb15e
commit
e942647b66
@ -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:");
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user