コード例 #1
0
ファイル: OPOIFSDocument.cs プロジェクト: zzy092/npoi
        /// <summary>
        /// read data from the internal stores
        /// </summary>
        /// <param name="buffer">the buffer to write to</param>
        /// <param name="offset">the offset into our storage to read from</param>
        public virtual void Read(byte[] buffer, int offset)
        {
            //if (this._property.ShouldUseSmallBlocks)
            //{
            //    SmallDocumentBlock.Read(this._small_store.Blocks, buffer, offset);
            //}
            //else
            //{
            //    DocumentBlock.Read(this._big_store.Blocks, buffer, offset);
            //}
            int len = buffer.Length;

            DataInputBlock currentBlock = GetDataInputBlock(offset);

            int blockAvailable = currentBlock.Available();

            if (blockAvailable > len)
            {
                currentBlock.ReadFully(buffer, 0, len);
                return;
            }
            // else read big amount in chunks
            int remaining     = len;
            int writePos      = 0;
            int currentOffset = offset;

            while (remaining > 0)
            {
                bool blockIsExpiring = remaining >= blockAvailable;
                int  reqSize;
                if (blockIsExpiring)
                {
                    reqSize = blockAvailable;
                }
                else
                {
                    reqSize = remaining;
                }
                currentBlock.ReadFully(buffer, writePos, reqSize);
                remaining     -= reqSize;
                writePos      += reqSize;
                currentOffset += reqSize;
                if (blockIsExpiring)
                {
                    if (currentOffset == _size)
                    {
                        if (remaining > 0)
                        {
                            throw new InvalidOperationException("reached end of document stream unexpectedly");
                        }
                        currentBlock = null;
                        break;
                    }
                    currentBlock   = GetDataInputBlock(currentOffset);
                    blockAvailable = currentBlock.Available();
                }
            }
        }
コード例 #2
0
        public override void ReadFully(byte[] buf, int off, int len)
        {
            CheckAvaliable(len);
            int blockAvailable = _currentBlock.Available();

            if (blockAvailable > len)
            {
                _currentBlock.ReadFully(buf, off, len);
                _current_offset += len;
                return;
            }
            // else read big amount in chunks
            int remaining = len;
            int WritePos  = off;

            while (remaining > 0)
            {
                bool blockIsExpiring = remaining >= blockAvailable;
                int  reqSize;
                if (blockIsExpiring)
                {
                    reqSize = blockAvailable;
                }
                else
                {
                    reqSize = remaining;
                }
                _currentBlock.ReadFully(buf, WritePos, reqSize);
                remaining       -= reqSize;
                WritePos        += reqSize;
                _current_offset += reqSize;
                if (blockIsExpiring)
                {
                    if (_current_offset == _document_size)
                    {
                        if (remaining > 0)
                        {
                            throw new InvalidOperationException(
                                      "reached end of document stream unexpectedly");
                        }
                        _currentBlock = null;
                        break;
                    }
                    _currentBlock  = GetDataInputBlock(_current_offset);
                    blockAvailable = _currentBlock.Available();
                }
            }
        }