Exemple #1
0
        /**
         * Load the block at the given offset.
         */
        public override ByteBuffer GetBlockAt(int offset)
        {
            // Which big block is this?
            int byteOffset     = offset * POIFSConstants.SMALL_BLOCK_SIZE;
            int bigBlockNumber = byteOffset / _filesystem.GetBigBlockSize();
            int bigBlockOffset = byteOffset % _filesystem.GetBigBlockSize();

            // Now locate the data block for it
            NPOIFSStream.StreamBlockByteBufferIterator it = _mini_stream.GetBlockIterator() as NPOIFSStream.StreamBlockByteBufferIterator;

            for (int i = 0; i < bigBlockNumber; i++)
            {
                it.Next();
            }
            ByteBuffer dataBlock = it.Next();

            if (dataBlock == null)
            {
                throw new IndexOutOfRangeException("Big block " + bigBlockNumber + " outside stream");
            }

            // Position ourselves, and take a slice
            dataBlock.Position = dataBlock.Position + bigBlockOffset;
            ByteBuffer miniBuffer = dataBlock.Slice();

            miniBuffer.Limit = POIFSConstants.SMALL_BLOCK_SIZE;
            return(miniBuffer);
        }
 protected static void assertBATCount(NPOIFSFileSystem fs, int expectedBAT, int expectedXBAT)
 {
     int foundBAT = 0;
     int foundXBAT = 0;
     int sz = (int)(fs.Size / fs.GetBigBlockSize());
     for (int i = 0; i < sz; i++)
     {
         if (fs.GetNextBlock(i) == POIFSConstants.FAT_SECTOR_BLOCK)
         {
             foundBAT++;
         }
         if (fs.GetNextBlock(i) == POIFSConstants.DIFAT_SECTOR_BLOCK)
         {
             foundXBAT++;
         }
     }
     Assert.AreEqual(expectedBAT, foundBAT, "Wrong number of BATs");
     Assert.AreEqual(expectedXBAT, foundXBAT, "Wrong number of XBATs with " + expectedBAT + " BATs");
 }