]> source.dussan.org Git - poi.git/commitdiff
Put the properties table at block 0, with the first BAT at block 1, to hopefully...
authorNick Burch <nick@apache.org>
Sun, 28 Jun 2015 18:53:21 +0000 (18:53 +0000)
committerNick Burch <nick@apache.org>
Sun, 28 Jun 2015 18:53:21 +0000 (18:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688038 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java
src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSStream.java

index bb5b3a50ed42424fa99c45e489ac602ef32133af..f7e19137a62859b759a90e626a43d5009c90f088 100644 (file)
@@ -115,17 +115,18 @@ public class NPOIFSFileSystem extends BlockStore
     {
        this(true);
        
-        // Mark us as having a single empty BAT at offset 0
+        // Reserve block 0 for the start of the Properties Table
+        // Create a single empty BAT, at pop that at offset 1
         _header.setBATCount(1);
-        _header.setBATArray(new int[] { 0 });
+        _header.setBATArray(new int[] { 1 });
         BATBlock bb = BATBlock.createEmptyBATBlock(bigBlockSize, false);
-        bb.setOurBlockIndex(0);
+        bb.setOurBlockIndex(1);
         _bat_blocks.add(bb);
 
-        setNextBlock(0, POIFSConstants.FAT_SECTOR_BLOCK);
-        setNextBlock(1, POIFSConstants.END_OF_CHAIN);
+        setNextBlock(0, POIFSConstants.END_OF_CHAIN);
+        setNextBlock(1, POIFSConstants.FAT_SECTOR_BLOCK);
 
-        _property_table.setStartBlock(POIFSConstants.END_OF_CHAIN);
+        _property_table.setStartBlock(0);
     }
 
     /**
index 13fef7d8b564407d892bf306459a2cfceecba558..a476233ec729affbb8a1585540ad1757ef884f9e 100644 (file)
@@ -936,27 +936,27 @@ public final class TestNPOIFSFileSystem {
       DocumentEntry miniDoc;
       DocumentEntry normDoc;
       
-      // Initially has a BAT but not SBAT
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
+      // Initially has Properties + BAT but not SBAT
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
       
       // Check that the SBAT is empty
       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getRoot().getProperty().getStartBlock());
       
-      // Check that no properties table has been written yet
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs._get_property_table().getStartBlock());
+      // Check that properties table was given block 0
+      assertEquals(0, fs._get_property_table().getStartBlock());
 
       // Write and read it
       fs = writeOutAndReadBack(fs);
       
-      // Property table entries have been added to the blocks 
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
-      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(3));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getRoot().getProperty().getStartBlock());
-      assertEquals(2, fs._get_property_table().getStartBlock());
+      // No change, SBAT remains empty 
+      assertEquals(POIFSConstants.END_OF_CHAIN,     fs.getNextBlock(0));
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+      assertEquals(POIFSConstants.UNUSED_BLOCK,     fs.getNextBlock(2));
+      assertEquals(POIFSConstants.UNUSED_BLOCK,     fs.getNextBlock(3));
+      assertEquals(POIFSConstants.END_OF_CHAIN,     fs.getRoot().getProperty().getStartBlock());
+      assertEquals(0, fs._get_property_table().getStartBlock());
 
       
       // Put everything within a new directory
@@ -968,19 +968,19 @@ public final class TestNPOIFSFileSystem {
       main4096[4095] = -11;
       testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
 
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+      assertEquals(POIFSConstants.END_OF_CHAIN,     fs.getNextBlock(0));
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+      assertEquals(3, fs.getNextBlock(2));
       assertEquals(4, fs.getNextBlock(3));
       assertEquals(5, fs.getNextBlock(4));
       assertEquals(6, fs.getNextBlock(5));
       assertEquals(7, fs.getNextBlock(6));
       assertEquals(8, fs.getNextBlock(7));
       assertEquals(9, fs.getNextBlock(8));
-      assertEquals(10, fs.getNextBlock(9));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(10));
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(9));
+      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(10));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(11));
-      
+      // SBAT still unused
       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getRoot().getProperty().getStartBlock());
 
       
@@ -990,18 +990,18 @@ public final class TestNPOIFSFileSystem {
       main5124[5123] = -33;
       testDir.createDocument("Normal5124", new ByteArrayInputStream(main5124));
 
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+      assertEquals(POIFSConstants.END_OF_CHAIN,     fs.getNextBlock(0));
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+      assertEquals(3, fs.getNextBlock(2));
       assertEquals(4, fs.getNextBlock(3));
       assertEquals(5, fs.getNextBlock(4));
       assertEquals(6, fs.getNextBlock(5));
       assertEquals(7, fs.getNextBlock(6));
       assertEquals(8, fs.getNextBlock(7));
       assertEquals(9, fs.getNextBlock(8));
-      assertEquals(10, fs.getNextBlock(9));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(10));
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(9));
 
+      assertEquals(11, fs.getNextBlock(10));
       assertEquals(12, fs.getNextBlock(11));
       assertEquals(13, fs.getNextBlock(12));
       assertEquals(14, fs.getNextBlock(13));
@@ -1011,8 +1011,8 @@ public final class TestNPOIFSFileSystem {
       assertEquals(18, fs.getNextBlock(17));
       assertEquals(19, fs.getNextBlock(18));
       assertEquals(20, fs.getNextBlock(19));
-      assertEquals(21, fs.getNextBlock(20));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(21));
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(20));
+      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(21));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(22));
 
       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getRoot().getProperty().getStartBlock());
@@ -1023,18 +1023,18 @@ public final class TestNPOIFSFileSystem {
       testDir.createDocument("Mini", new ByteArrayInputStream(mini));
       
       // Mini stream will get one block for fat + one block for data
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+      assertEquals(POIFSConstants.END_OF_CHAIN,     fs.getNextBlock(0));
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+      assertEquals(3, fs.getNextBlock(2));
       assertEquals(4, fs.getNextBlock(3));
       assertEquals(5, fs.getNextBlock(4));
       assertEquals(6, fs.getNextBlock(5));
       assertEquals(7, fs.getNextBlock(6));
       assertEquals(8, fs.getNextBlock(7));
       assertEquals(9, fs.getNextBlock(8));
-      assertEquals(10, fs.getNextBlock(9));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(10));
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(9));
 
+      assertEquals(11, fs.getNextBlock(10));
       assertEquals(12, fs.getNextBlock(11));
       assertEquals(13, fs.getNextBlock(12));
       assertEquals(14, fs.getNextBlock(13));
@@ -1044,15 +1044,14 @@ public final class TestNPOIFSFileSystem {
       assertEquals(18, fs.getNextBlock(17));
       assertEquals(19, fs.getNextBlock(18));
       assertEquals(20, fs.getNextBlock(19));
-      assertEquals(21, fs.getNextBlock(20));
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(20));
       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(21));
       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(22));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(23));
-      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(24));
+      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(23));
 
       // Check the mini stream location was set
-      // (22 is mini fat, 23 is first mini stream block)
-      assertEquals(23, fs.getRoot().getProperty().getStartBlock());
+      // (21 is mini fat, 22 is first mini stream block)
+      assertEquals(22, fs.getRoot().getProperty().getStartBlock());
       
       
       // Write and read back
@@ -1061,28 +1060,28 @@ public final class TestNPOIFSFileSystem {
       
       // Check the header has the right points in it
       assertEquals(1, header.getBATCount());
-      assertEquals(0, header.getBATArray()[0]);
-      assertEquals(2, header.getPropertyStart());
+      assertEquals(1, header.getBATArray()[0]);
+      assertEquals(0, header.getPropertyStart());
       assertEquals(1, header.getSBATCount());
-      assertEquals(22, header.getSBATStart());
-      assertEquals(23, fs._get_property_table().getRoot().getStartBlock());
+      assertEquals(21, header.getSBATStart());
+      assertEquals(22, fs._get_property_table().getRoot().getStartBlock());
       
       // Block use should be almost the same, except the properties
       //  stream will have grown out to cover 2 blocks
       // Check the block use is all unchanged
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-      assertEquals(24, fs.getNextBlock(2)); // Properties now extends over 2 blocks
+      assertEquals(23, fs.getNextBlock(0)); // Properties now extends over 2 blocks
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
       
+      assertEquals(3, fs.getNextBlock(2));
       assertEquals(4, fs.getNextBlock(3));
       assertEquals(5, fs.getNextBlock(4));
       assertEquals(6, fs.getNextBlock(5));
       assertEquals(7, fs.getNextBlock(6));
       assertEquals(8, fs.getNextBlock(7));
       assertEquals(9, fs.getNextBlock(8));
-      assertEquals(10, fs.getNextBlock(9));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(10)); // End of normal4096
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(9)); // End of normal4096
 
+      assertEquals(11, fs.getNextBlock(10));
       assertEquals(12, fs.getNextBlock(11));
       assertEquals(13, fs.getNextBlock(12));
       assertEquals(14, fs.getNextBlock(13));
@@ -1092,13 +1091,12 @@ public final class TestNPOIFSFileSystem {
       assertEquals(18, fs.getNextBlock(17));
       assertEquals(19, fs.getNextBlock(18));
       assertEquals(20, fs.getNextBlock(19));
-      assertEquals(21, fs.getNextBlock(20));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(21)); // End of normal5124 
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(20)); // End of normal5124 
       
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(22)); // Mini Stream FAT
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(23)); // Mini Stream data
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(24)); // Properties #2
-      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(25));
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(21)); // Mini Stream FAT
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(22)); // Mini Stream data
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(23)); // Properties #2
+      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(24));
 
       
       // Check some data
@@ -1124,19 +1122,19 @@ public final class TestNPOIFSFileSystem {
       // Check - will have un-used sectors now
       fs = writeOutAndReadBack(fs);
       
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // Props back in 1 block
+      assertEquals(POIFSConstants.END_OF_CHAIN,     fs.getNextBlock(0)); // Props back in 1 block
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
       
+      assertEquals(3, fs.getNextBlock(2));
       assertEquals(4, fs.getNextBlock(3));
       assertEquals(5, fs.getNextBlock(4));
       assertEquals(6, fs.getNextBlock(5));
       assertEquals(7, fs.getNextBlock(6));
       assertEquals(8, fs.getNextBlock(7));
       assertEquals(9, fs.getNextBlock(8));
-      assertEquals(10, fs.getNextBlock(9));
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(10)); // End of normal4096
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(9)); // End of normal4096
 
+      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(10));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(11));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(12));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(13));
@@ -1147,11 +1145,11 @@ public final class TestNPOIFSFileSystem {
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(18));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(19));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(20));
-      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(21));
       
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(22)); // Mini Stream FAT
-      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(23)); // Mini Stream data
-      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(24)); // Properties gone
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(21)); // Mini Stream FAT
+      assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(22)); // Mini Stream data
+      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(23)); // Properties gone
+      assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(24));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(25));
       
       // All done
@@ -1165,20 +1163,20 @@ public final class TestNPOIFSFileSystem {
        DocumentEntry normDoc;
        HeaderBlock hdr;
        
-       // Initially has BAT + Properties but nothing else
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
+       // Initially has Properties + BAT but nothing else
+       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
        assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
        
        hdr = writeOutAndReadHeader(fs);
        // No mini stream, and no xbats
        // Will have fat then properties stream
        assertEquals(1, hdr.getBATCount());
-       assertEquals(0, hdr.getBATArray()[0]);
-       assertEquals(2, hdr.getPropertyStart());
+       assertEquals(1, hdr.getBATArray()[0]);
+       assertEquals(0, hdr.getPropertyStart());
        assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getSBATStart());
        assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
-       assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*4, fs.size());
+       assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*3, fs.size());
        
        
        // Get a clean filesystem to start with
@@ -1201,8 +1199,8 @@ public final class TestNPOIFSFileSystem {
 
        
        // Check the mini stream was added, then the main stream
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1)); 
+       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1)); 
        assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // Mini Fat
        assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini Stream
        assertEquals(5,                           fs.getNextBlock(4)); // Main Stream
@@ -1232,15 +1230,15 @@ public final class TestNPOIFSFileSystem {
        // Check the header details - will have the sbat near the start,
        //  then the properties at the end
        assertEquals(1, hdr.getBATCount());
-       assertEquals(0, hdr.getBATArray()[0]);
+       assertEquals(1, hdr.getBATArray()[0]);
        assertEquals(2, hdr.getSBATStart());
-       assertEquals(12, hdr.getPropertyStart());
+       assertEquals(0, hdr.getPropertyStart());
        assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
        
        // Check the block allocation is unchanged, other than
        //  the properties stream going in at the end
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
+       assertEquals(12,                          fs.getNextBlock(0)); // Properties
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
        assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
        assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
        assertEquals(5,                           fs.getNextBlock(4));
@@ -1251,10 +1249,9 @@ public final class TestNPOIFSFileSystem {
        assertEquals(10,                          fs.getNextBlock(9));
        assertEquals(11,                          fs.getNextBlock(10));
        assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(11));
-       assertEquals(13,                          fs.getNextBlock(12));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(13));
-       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(14));
-       assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*15, fs.size());
+       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(12));
+       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(13));
+       assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*14, fs.size());
        
        
        // Check the data
index 04454229073770fd4d44adae2c65d3285350283d..f420683c379039b9d51ac75963d20c11d35d605d 100644 (file)
@@ -338,10 +338,10 @@ public final class TestNPOIFSMiniStore extends TestCase {
        NPOIFSFileSystem fs = new NPOIFSFileSystem();
        NPOIFSMiniStore ministore = fs.getMiniStore();
 
-       // Initially has BAT + Properties but nothing else
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
+       // Initially has Properties + BAT but nothing else
+       assertEquals(POIFSConstants.END_OF_CHAIN,     fs.getNextBlock(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+       assertEquals(POIFSConstants.UNUSED_BLOCK,     fs.getNextBlock(2));
        // Ministore has no blocks, so can't iterate until used
        try {
            ministore.getNextBlock(0);
@@ -355,27 +355,27 @@ public final class TestNPOIFSMiniStore extends TestCase {
        fs.getRoot().createDocument("mini", new ByteArrayInputStream(data));
        
        // Should now have a mini-fat and a mini-stream
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
-       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
-       assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
-       assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    fs.getNextBlock(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,fs.getNextBlock(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    fs.getNextBlock(2));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    fs.getNextBlock(3));
+       assertEquals(POIFSConstants.UNUSED_BLOCK,    fs.getNextBlock(4));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    ministore.getNextBlock(0));
+       assertEquals(POIFSConstants.UNUSED_BLOCK,    ministore.getNextBlock(1));
        
        // Re-fetch the mini store, and add it a second time
        ministore = fs.getMiniStore();
        fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data));
        
        // Main unchanged, ministore has a second
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(1));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
-       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
-       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
-       assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(1));
-       assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(2));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    fs.getNextBlock(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,fs.getNextBlock(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    fs.getNextBlock(2));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    fs.getNextBlock(3));
+       assertEquals(POIFSConstants.UNUSED_BLOCK,    fs.getNextBlock(4));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    ministore.getNextBlock(0));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    ministore.getNextBlock(1));
+       assertEquals(POIFSConstants.UNUSED_BLOCK,    ministore.getNextBlock(2));
 
        // Done
        fs.close();
index 1dcdba1ca2b7d41f4ac985e6947536cd812ce854..f1c8c180ae31d60e15208e6c71559a9926e80e39 100644 (file)
@@ -860,12 +860,12 @@ public final class TestNPOIFSStream extends TestCase {
       NPOIFSFileSystem fs = new NPOIFSFileSystem();
       NPOIFSStream stream = new NPOIFSStream(fs);
       
-      // Check our filesystem has a BAT and the Properties
+      // Check our filesystem has Properties then BAT
       assertEquals(2, fs.getFreeBlock());
       BATBlock bat = fs.getBATBlockAndIndex(0).getBlock();
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
-      assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(2));
+      assertEquals(POIFSConstants.END_OF_CHAIN,    bat.getValueAt(0));
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
+      assertEquals(POIFSConstants.UNUSED_BLOCK,    bat.getValueAt(2));
       
       // Check the stream as-is
       assertEquals(POIFSConstants.END_OF_CHAIN, stream.getStartBlock());
@@ -887,11 +887,11 @@ public final class TestNPOIFSStream extends TestCase {
       // Check now
       assertEquals(4, fs.getFreeBlock());
       bat = fs.getBATBlockAndIndex(0).getBlock();
-      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-      assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
-      assertEquals(3,                           bat.getValueAt(2));
-      assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3));
-      assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(4));
+      assertEquals(POIFSConstants.END_OF_CHAIN,    bat.getValueAt(0));
+      assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
+      assertEquals(3,                              bat.getValueAt(2));
+      assertEquals(POIFSConstants.END_OF_CHAIN,    bat.getValueAt(3));
+      assertEquals(POIFSConstants.UNUSED_BLOCK,    bat.getValueAt(4));
       
       
       Iterator<ByteBuffer> it = stream.getBlockIterator();
@@ -927,11 +927,11 @@ public final class TestNPOIFSStream extends TestCase {
    public void testWriteThenReplace() throws Exception {
        NPOIFSFileSystem fs = new NPOIFSFileSystem();
 
-       // Starts empty
+       // Starts empty, other that Properties and BAT
        BATBlock bat = fs.getBATBlockAndIndex(0).getBlock();
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
-       assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(2));
+       assertEquals(POIFSConstants.END_OF_CHAIN,    bat.getValueAt(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
+       assertEquals(POIFSConstants.UNUSED_BLOCK,    bat.getValueAt(2));
 
        // Write something that uses a main stream
        byte[] main4106 = new byte[4106];
@@ -941,8 +941,8 @@ public final class TestNPOIFSStream extends TestCase {
                "Normal", new ByteArrayInputStream(main4106));
        
        // Should have used 9 blocks
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
        assertEquals(3,                           bat.getValueAt(2));
        assertEquals(4,                           bat.getValueAt(3));
        assertEquals(5,                           bat.getValueAt(4));
@@ -969,8 +969,8 @@ public final class TestNPOIFSStream extends TestCase {
        nout.close();
        
        // Will have dropped to 8
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
        assertEquals(3,                           bat.getValueAt(2));
        assertEquals(4,                           bat.getValueAt(3));
        assertEquals(5,                           bat.getValueAt(4));
@@ -991,9 +991,9 @@ public final class TestNPOIFSStream extends TestCase {
        fs = writeOutAndReadBack(fs);
        bat = fs.getBATBlockAndIndex(0).getBlock();
        
-       // Will have properties, but otherwise the same
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
+       // No change after write
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0)); // Properties
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
        assertEquals(3,                           bat.getValueAt(2));
        assertEquals(4,                           bat.getValueAt(3));
        assertEquals(5,                           bat.getValueAt(4));
@@ -1002,7 +1002,7 @@ public final class TestNPOIFSStream extends TestCase {
        assertEquals(8,                           bat.getValueAt(7));
        assertEquals(9,                           bat.getValueAt(8));
        assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(9)); // End of Normal
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Props
+       assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
        
        normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
@@ -1010,14 +1010,14 @@ public final class TestNPOIFSStream extends TestCase {
        assertEquals(4096, ((DocumentNode)normal).getProperty().getSize());
        
        
-       // Make longer, take 1 block after the properties too
+       // Make longer, take 1 block at the end
        normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
        nout = new NDocumentOutputStream(normal);
        nout.write(main4106);
        nout.close();
 
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,bat.getValueAt(1));
        assertEquals(3,                           bat.getValueAt(2));
        assertEquals(4,                           bat.getValueAt(3));
        assertEquals(5,                           bat.getValueAt(4));
@@ -1025,9 +1025,9 @@ public final class TestNPOIFSStream extends TestCase {
        assertEquals(7,                           bat.getValueAt(6));
        assertEquals(8,                           bat.getValueAt(7));
        assertEquals(9,                           bat.getValueAt(8));
-       assertEquals(11,                          bat.getValueAt(9));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Props
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(11)); // Normal
+       assertEquals(10,                          bat.getValueAt(9));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Normal
+       assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
        
        normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
@@ -1042,8 +1042,8 @@ public final class TestNPOIFSStream extends TestCase {
        nout.write(mini);
        nout.close();
        
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
        assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
        assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(4));
@@ -1052,7 +1052,7 @@ public final class TestNPOIFSStream extends TestCase {
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(7));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(8));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(9));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Props
+       assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(10));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(11));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
        
@@ -1067,8 +1067,8 @@ public final class TestNPOIFSStream extends TestCase {
        nout.close();
        
        // Will keep the mini stream, now empty
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
        assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
        assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
        assertEquals(5,                           bat.getValueAt(4));
@@ -1076,10 +1076,10 @@ public final class TestNPOIFSStream extends TestCase {
        assertEquals(7,                           bat.getValueAt(6));
        assertEquals(8,                           bat.getValueAt(7));
        assertEquals(9,                           bat.getValueAt(8));
-       assertEquals(11,                          bat.getValueAt(9));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Props
-       assertEquals(12,                          bat.getValueAt(11));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(12));
+       assertEquals(10,                          bat.getValueAt(9));
+       assertEquals(11,                          bat.getValueAt(10));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(11));
+       assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(13));
        
        normal = (DocumentEntry)fs.getRoot().getEntry("Normal");
@@ -1091,8 +1091,8 @@ public final class TestNPOIFSStream extends TestCase {
        fs = writeOutAndReadBack(fs);
        bat = fs.getBATBlockAndIndex(0).getBlock();
        
-       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(0));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(1));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(0));
+       assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, bat.getValueAt(1));
        assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(2)); // SBAT
        assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(3)); // Mini Stream
        assertEquals(5,                           bat.getValueAt(4));
@@ -1100,10 +1100,10 @@ public final class TestNPOIFSStream extends TestCase {
        assertEquals(7,                           bat.getValueAt(6));
        assertEquals(8,                           bat.getValueAt(7));
        assertEquals(9,                           bat.getValueAt(8));
-       assertEquals(11,                          bat.getValueAt(9));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(10)); // Props
-       assertEquals(12,                          bat.getValueAt(11));
-       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(12));
+       assertEquals(10,                          bat.getValueAt(9));
+       assertEquals(11,                          bat.getValueAt(10));
+       assertEquals(POIFSConstants.END_OF_CHAIN, bat.getValueAt(11));
+       assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(12));
        assertEquals(POIFSConstants.UNUSED_BLOCK, bat.getValueAt(13));
        
        normal = (DocumentEntry)fs.getRoot().getEntry("Normal");