コード例 #1
0
 private static DocumentBlock[] ConvertRawBlocksToBigBlocks(ListManagedBlock[] blocks)
 {
     DocumentBlock[] result = new DocumentBlock[blocks.Length];
     for (int i = 0; i < result.Length; i++)
         result[i] = new DocumentBlock((RawDataBlock)blocks[i]);
     return result;
 }
コード例 #2
0
        /// <summary>
        /// convert a single long array into an array of DocumentBlock
        /// instances
        /// </summary>
        /// <param name="array">the byte array to be converted</param>
        /// <param name="size">the intended size of the array (which may be smaller)</param>
        /// <returns>an array of DocumentBlock instances, filled from the
        /// input array</returns>
        public static DocumentBlock[] Convert(POIFSBigBlockSize bigBlockSize,
                                              byte[] array,
                                              int size)
        {
            DocumentBlock[] rval =
                new DocumentBlock[(size + POIFSConstants.BIG_BLOCK_SIZE - 1) / POIFSConstants.BIG_BLOCK_SIZE];
            int offset = 0;

            for (int k = 0; k < rval.Length; k++)
            {
                rval[k] = new DocumentBlock(bigBlockSize);
                if (offset < array.Length)
                {
                    int length = Math.Min(POIFSConstants.BIG_BLOCK_SIZE,
                                          array.Length - offset);

                    Array.Copy(array, offset, rval[k]._data, 0, length);
                    if (length != POIFSConstants.BIG_BLOCK_SIZE)
                    {
                        for (int j = (length > 0) ? (length - 1) : length; j < POIFSConstants.BIG_BLOCK_SIZE; j++)
                        {
                            rval[k]._data[j] = _default_value;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < rval[k]._data.Length; j++)
                    {
                        rval[k]._data[j] = _default_value;
                    }
                }
                offset += POIFSConstants.BIG_BLOCK_SIZE;
            }
            return(rval);
        }
コード例 #3
0
 internal BigBlockStore(POIFSBigBlockSize bigBlockSize, DocumentBlock[] blocks)
 {
     this.bigBlockSize = bigBlockSize;
     bigBlocks = (DocumentBlock[])blocks.Clone();
     path = null;
     name = null;
     size = -1;
     writer = null;
 }
コード例 #4
0
        public POIFSDocument(string name, POIFSBigBlockSize bigBlockSize, Stream stream)
        {
            List<DocumentBlock> blocks = new List<DocumentBlock>();

            _size = 0;
            _bigBigBlockSize = bigBlockSize;
            while (true)
            {
                DocumentBlock block = new DocumentBlock(stream, bigBlockSize);
                int blockSize = block.Size;

                if (blockSize > 0)
                {
                    blocks.Add(block);
                    _size += blockSize;
                }
                if (block.PartiallyRead)
                    break;
            }

            DocumentBlock[] bigBlocks = blocks.ToArray();
            _big_store = new BigBlockStore(bigBlockSize, bigBlocks);
            _property = new DocumentProperty(name, _size);
            _property.Document = this;

            if (_property.ShouldUseSmallBlocks)
            {
                _small_store = new SmallBlockStore(bigBlockSize, SmallDocumentBlock.Convert(bigBlockSize, bigBlocks, _size));
                _big_store = new BigBlockStore(bigBlockSize, new DocumentBlock[0]);
            }
            else
            {
                _small_store = new SmallBlockStore(bigBlockSize, EMPTY_SMALL_BLOCK_ARRAY);
        }

        }
コード例 #5
0
        public static DataInputBlock GetDataInputBlock(DocumentBlock[] blocks, int offset)
        {
            if (blocks == null || blocks.Length == 0)
                return null;

            POIFSBigBlockSize bigBlockSize = blocks[0].bigBlockSize;
            int BLOCK_SHIFT = bigBlockSize.GetHeaderValue();
            int BLOCK_SIZE = bigBlockSize.GetBigBlockSize();
            int BLOCK_MASK = BLOCK_SIZE - 1;

            int firstBlockIndex = offset >> BLOCK_SHIFT;
            int firstBlockOffset = offset & BLOCK_MASK;
            return new DataInputBlock(blocks[firstBlockIndex]._data, firstBlockOffset);
        }
コード例 #6
0
        /// <summary>
        /// Read data from an array of DocumentBlocks
        /// </summary>
        /// <param name="blocks">the blocks to Read from</param>
        /// <param name="buffer">the buffer to Write the data into</param>
        /// <param name="offset">the offset into the array of blocks to Read from</param>
        public static void Read(DocumentBlock[] blocks,
                                byte[] buffer, int offset)
        {
            int firstBlockIndex = offset / POIFSConstants.BIG_BLOCK_SIZE;
            int firstBlockOffSet = offset % POIFSConstants.BIG_BLOCK_SIZE;
            int lastBlockIndex = (offset + buffer.Length - 1)
                                   / POIFSConstants.BIG_BLOCK_SIZE;

            if (firstBlockIndex == lastBlockIndex)
            {
                Array.Copy(blocks[firstBlockIndex]._data,
                                 firstBlockOffSet, buffer, 0, buffer.Length);
            }
            else
            {
                int buffer_offset = 0;

                Array.Copy(blocks[firstBlockIndex]._data,
                                 firstBlockOffSet, buffer, buffer_offset,
                                 POIFSConstants.BIG_BLOCK_SIZE
                                 - firstBlockOffSet);
                buffer_offset += POIFSConstants.BIG_BLOCK_SIZE - firstBlockOffSet;
                for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++)
                {
                    Array.Copy(blocks[j]._data, 0, buffer, buffer_offset,
                                     POIFSConstants.BIG_BLOCK_SIZE);
                    buffer_offset += POIFSConstants.BIG_BLOCK_SIZE;
                }
                Array.Copy(blocks[lastBlockIndex]._data, 0, buffer,
                                 buffer_offset, buffer.Length - buffer_offset);
            }
        }
コード例 #7
0
        /// <summary>
        /// convert a single long array into an array of DocumentBlock
        /// instances
        /// </summary>
        /// <param name="array">the byte array to be converted</param>
        /// <param name="size">the intended size of the array (which may be smaller)</param>
        /// <returns>an array of DocumentBlock instances, filled from the
        /// input array</returns>
        public static DocumentBlock[] Convert(POIFSBigBlockSize bigBlockSize,
                                                byte[] array,
                                               int size)
        {
            DocumentBlock[] rval =
                new DocumentBlock[(size + POIFSConstants.BIG_BLOCK_SIZE - 1) / POIFSConstants.BIG_BLOCK_SIZE];
            int offset = 0;

            for (int k = 0; k < rval.Length; k++)
            {
                rval[k] = new DocumentBlock(bigBlockSize);
                if (offset < array.Length)
                {
                    int length = Math.Min(POIFSConstants.BIG_BLOCK_SIZE,
                                          array.Length - offset);

                    Array.Copy(array, offset, rval[k]._data, 0, length);
                    if (length != POIFSConstants.BIG_BLOCK_SIZE)
                    {
                        for (int j = (length > 0) ? (length - 1) : length; j < POIFSConstants.BIG_BLOCK_SIZE; j++)
                        {
                            rval[k]._data[j] = _default_value;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < rval[k]._data.Length; j++)
                    {
                        rval[k]._data[j] = _default_value;
                    }
                }
                offset += POIFSConstants.BIG_BLOCK_SIZE;
            }
            return rval;
        }