示例#1
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);
            }
        }
示例#2
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);
        }
示例#3
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;
        }