Examples of HeaderBlock


Examples of org.apache.poi.poifs.storage.HeaderBlock

      // We now have 109 BATs, but no XBATs
      assertBATCount(fs, 109, 0);
     
     
      // Ask for it to be written out, and check the header
      HeaderBlock header = writeOutAndReadHeader(fs);
      assertEquals(109, header.getBATCount());
      assertEquals(0, header.getXBATCount());
     
     
      // Ask for another, will get our first XBAT
      free = fs.getFreeBlock();
      assertEquals(false, fs.getBATBlockAndIndex(109*128-1).getBlock().hasFreeSectors());
      assertEquals(true, fs.getBATBlockAndIndex(110*128-1).getBlock().hasFreeSectors());
      try {
         assertEquals(false, fs.getBATBlockAndIndex(110*128).getBlock().hasFreeSectors());
         fail("Should only be 110 BATs");
      } catch(IndexOutOfBoundsException e) {}
      assertBATCount(fs, 110, 1);
     
      header = writeOutAndReadHeader(fs);
      assertEquals(110, header.getBATCount());
      assertEquals(1, header.getXBATCount());

     
      // Fill the XBAT, which means filling 127 BATs
      for(int i=109; i<109+127; i++) {
         fs.getFreeBlock();
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

      assertEquals(23, fs.getRoot().getProperty().getStartBlock());
     
     
      // Write and read back
      fs = writeOutAndReadBack(fs);
      HeaderBlock header = writeOutAndReadHeader(fs);
     
      // 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.getSBATCount());
      assertEquals(22, header.getSBATStart());
      assertEquals(23, 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
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

   @Test
   public void addBeforeWrite() throws Exception {
       NPOIFSFileSystem fs = new NPOIFSFileSystem();
       DocumentEntry miniDoc;
       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));
       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(POIFSConstants.END_OF_CHAIN, hdr.getSBATStart());
       assertEquals(POIFSConstants.END_OF_CHAIN, hdr.getXBATIndex());
       assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*4, fs.size());
      
      
       // Get a clean filesystem to start with
       fs = new NPOIFSFileSystem();
      
       // Put our test files in a non-standard place
       DirectoryEntry parentDir = fs.createDirectory("Parent Directory");
       DirectoryEntry testDir = parentDir.createDirectory("Test Directory");
      
      
       // Add to the mini stream
       byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
       testDir.createDocument("Mini", new ByteArrayInputStream(mini));
      
       // Add to the main stream
       byte[] main4096 = new byte[4096];
       main4096[0] = -10;
       main4096[4095] = -11;
       testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));

      
       // 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(2)); // Mini Fat
       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini Stream
       assertEquals(5,                           fs.getNextBlock(4)); // Main Stream
       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(11,                          fs.getNextBlock(10));
       assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(11));
       assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(12));
       assertEquals(POIFSConstants.SMALLER_BIG_BLOCK_SIZE*13, fs.size());
      
      
       // Check that we can read the right data pre-write
       miniDoc = (DocumentEntry)testDir.getEntry("Mini");
       assertContentsMatches(mini, miniDoc);

       normDoc = (DocumentEntry)testDir.getEntry("Normal4096");
       assertContentsMatches(main4096, normDoc);
      
      
       // Write, read, check
       hdr = writeOutAndReadHeader(fs);
       fs = writeOutAndReadBack(fs);
      
       // 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(2, hdr.getSBATStart());
       assertEquals(12, 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));
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

    private POIFSBigBlockSize bigBlockSize =
       POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;

    private NPOIFSFileSystem(boolean newFS)
    {
        _header         = new HeaderBlock(bigBlockSize);
        _property_table = new NPropertyTable(_header);
        _mini_store     = new NPOIFSMiniStore(this, _property_table.getRoot(), new ArrayList<BATBlock>(), _header);
        _xbat_blocks    = new ArrayList<BATBlock>();
        _bat_blocks     = new ArrayList<BATBlock>();
        _root           = null;
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

          // Get the header
          ByteBuffer headerBuffer = ByteBuffer.allocate(POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
          IOUtils.readFully(channel, headerBuffer);
         
          // Have the header processed
          _header = new HeaderBlock(headerBuffer);
         
          // Now process the various entries
          _data = new FileBackedDataSource(channel);
          readCoreContents();
       } catch(IOException e) {
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

           // Get the header
           ByteBuffer headerBuffer = ByteBuffer.allocate(POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
           IOUtils.readFully(channel, headerBuffer);
          
           // Have the header processed
           _header = new HeaderBlock(headerBuffer);
          
           // Sanity check the block count
           BlockAllocationTableReader.sanityCheckBlockCount(_header.getBATCount());
  
           // We need to buffer the whole file into memory when
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

    private POIFSBigBlockSize bigBlockSize =
       POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;

    private NPOIFSFileSystem(boolean newFS)
    {
        _header         = new HeaderBlock(bigBlockSize);
        _property_table = new NPropertyTable(_header);
        _mini_store     = new NPOIFSMiniStore(this, _property_table.getRoot(), new ArrayList<BATBlock>(), _header);
        _xbat_blocks    = new ArrayList<BATBlock>();
        _bat_blocks     = new ArrayList<BATBlock>();
        _root           = null;
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

          // Get the header
          ByteBuffer headerBuffer = ByteBuffer.allocate(POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
          IOUtils.readFully(channel, headerBuffer);
         
          // Have the header processed
          _header = new HeaderBlock(headerBuffer);
         
          // Now process the various entries
          _data = new FileBackedDataSource(channel);
          readCoreContents();
       } catch(IOException e) {
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

           // Get the header
           ByteBuffer headerBuffer = ByteBuffer.allocate(POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
           IOUtils.readFully(channel, headerBuffer);
          
           // Have the header processed
           _header = new HeaderBlock(headerBuffer);
          
           // Sanity check the block count
           BlockAllocationTableReader.sanityCheckBlockCount(_header.getBATCount());
  
           // We need to buffer the whole file into memory when
View Full Code Here

Examples of org.apache.poi.poifs.storage.HeaderBlock

      // Write it out
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      fs.writeFilesystem(baos);
     
      // Check the header is correct
      HeaderBlock header = new HeaderBlock(new ByteArrayInputStream(baos.toByteArray()));
      if(1==2) {
      // TODO Fix this
      assertEquals(237, header.getBATCount());
      assertEquals(2, header.getXBATCount());
     
      // Now check the filesystem sees it correct too
      fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
      // TODO
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.