コード例 #1
0
ファイル: NPOIFSMiniStore.cs プロジェクト: 562127386/HBHC
        /**
         * Load the block, extending the underlying stream if needed
         */
        public override ByteBuffer CreateBlockIfNeeded(int offset)
        {
            // Try to Get it without extending the stream
            try
            {
                return(GetBlockAt(offset));
            }
            catch (IndexOutOfRangeException)
            {
                // Need to extend the stream
                // TODO Replace this with proper append support
                // For now, do the extending by hand...

                // Ask for another block
                int newBigBlock = _filesystem.GetFreeBlock();
                _filesystem.CreateBlockIfNeeded(newBigBlock);

                // Tack it onto the end of our chain
                ChainLoopDetector loopDetector = _filesystem.GetChainLoopDetector();
                int block = _mini_stream.GetStartBlock();
                while (true)
                {
                    loopDetector.Claim(block);
                    int next = _filesystem.GetNextBlock(block);
                    if (next == POIFSConstants.END_OF_CHAIN)
                    {
                        break;
                    }
                    block = next;
                }
                _filesystem.SetNextBlock(block, newBigBlock);
                _filesystem.SetNextBlock(newBigBlock, POIFSConstants.END_OF_CHAIN);

                // Now try again to Get it
                return(CreateBlockIfNeeded(offset));
            }
        }