/// <summary>
 /// Initializes a new instance of the <see cref="SmallDocumentBlockList"/> class.
 /// </summary>
 /// <param name="blocks">a list of SmallDocumentBlock instances</param>
 public SmallDocumentBlockList(IList blocks)
 {
     SmallDocumentBlock[] array = new SmallDocumentBlock[blocks.Count];
     blocks.CopyTo(array, 0);
     ListManagedBlock[] tmp = (ListManagedBlock[])array;
     this.SetBlocks(ref tmp);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SmallBlockTableWriter"/> class.
        /// </summary>
        /// <param name="documents">a IList of POIFSDocument instances</param>
        /// <param name="root">the Filesystem's root property</param>
        public SmallBlockTableWriter(POIFSBigBlockSize bigBlockSize, IList documents,
                                     RootProperty root)
        {
            _sbat         = new BlockAllocationTableWriter(bigBlockSize);
            _small_blocks = new ArrayList();
            _root         = root;
            IEnumerator iter = documents.GetEnumerator();

            while (iter.MoveNext())
            {
                POIFSDocument   doc    = ( POIFSDocument )iter.Current;
                BlockWritable[] blocks = doc.SmallBlocks;

                if (blocks.Length != 0)
                {
                    doc.StartBlock = _sbat.AllocateSpace(blocks.Length);
                    for (int j = 0; j < blocks.Length; j++)
                    {
                        _small_blocks.Add(blocks[j]);
                    }
                }
                else
                {
                    doc.StartBlock = POIFSConstants.END_OF_CHAIN;
                }
            }
            _sbat.SimpleCreateBlocks();
            _root.Size       = _small_blocks.Count;
            _big_block_count = SmallDocumentBlock.Fill(bigBlockSize, _small_blocks);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SmallDocumentBlockList"/> class.
 /// </summary>
 /// <param name="blocks">a list of SmallDocumentBlock instances</param>
 public SmallDocumentBlockList(IList blocks)
 {
     SmallDocumentBlock[] array = new SmallDocumentBlock[blocks.Count];
     blocks.CopyTo(array, 0);
     ListManagedBlock[] tmp = (ListManagedBlock[])array;
     this.SetBlocks(ref tmp);
 }
Exemplo n.º 4
0
        /// <summary>
        /// convert a single long array into an array of SmallDocumentBlock
        /// instances
        /// </summary>
        /// <param name="bigBlockSize">the poifs bigBlockSize</param>
        /// <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 SmallDocumentBlock instances, filled from
        /// the array</returns>
        public static SmallDocumentBlock [] Convert(POIFSBigBlockSize bigBlockSize,
                                                    byte [] array,
                                                    int size)
        {
            SmallDocumentBlock[] rval = new SmallDocumentBlock[(size + _block_size - 1) / _block_size];
            int offset = 0;

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

                    Array.Copy(array, offset, rval[k]._data, 0, length);
                    if (length != _block_size)
                    {
                        for (int i = length; i < _block_size; i++)
                        {
                            rval[k]._data[i] = _default_fill;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < rval[k]._data.Length; j++)
                    {
                        rval[k]._data[j] = _default_fill;
                    }
                }
                offset += _block_size;
            }
            return(rval);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Makes the empty small document block.
        /// </summary>
        /// <returns></returns>
        private static SmallDocumentBlock MakeEmptySmallDocumentBlock(POIFSBigBlockSize bigBlockSize)
        {
            SmallDocumentBlock block = new SmallDocumentBlock(bigBlockSize);

            for (int i = 0; i < block._data.Length; i++)
            {
                block._data[i] = _default_fill;
            }
            return(block);
        }
Exemplo n.º 6
0
        /// <summary>
        /// fetch the small document block list from an existing file
        /// </summary>
        /// <param name="bigBlockSize">the poifs bigBlockSize</param>
        /// <param name="blockList">the raw data from which the small block table will be extracted</param>
        /// <param name="root">the root property (which contains the start block and small block table size)</param>
        /// <param name="sbatStart">the start block of the SBAT</param>
        /// <returns>the small document block list</returns>
        public static BlockList GetSmallDocumentBlocks(POIFSBigBlockSize bigBlockSize,
                                                       RawDataBlockList blockList, RootProperty root,
                                                       int sbatStart)
        {
            BlockList list =
                new SmallDocumentBlockList(
                    SmallDocumentBlock.Extract(bigBlockSize, blockList.FetchBlocks(root.StartBlock, -1)));

            new BlockAllocationTableReader(bigBlockSize, blockList.FetchBlocks(sbatStart, -1), list);
            return(list);
        }
Exemplo n.º 7
0
        private static BlockList prepareSmallDocumentBlocks(
            POIFSBigBlockSize bigBlockSize,
            RawDataBlockList blockList, RootProperty root,
            int sbatStart)
        {
            // Fetch the blocks which hold the Small Blocks stream
            ListManagedBlock[]
            smallBlockBlocks =
                blockList.FetchBlocks(root.StartBlock, -1);

            // Turn that into a list
            BlockList list = new SmallDocumentBlockList(
                SmallDocumentBlock.Extract(bigBlockSize, smallBlockBlocks));

            return(list);
        }
        /// <summary>
        /// Factory for creating SmallDocumentBlocks from DocumentBlocks
        /// </summary>
        /// <param name="store">the original DocumentBlocks</param>
        /// <param name="size">the total document size</param>
        /// <returns>an array of new SmallDocumentBlocks instances</returns>
        public static SmallDocumentBlock [] Convert(BlockWritable [] store,
                                                    int size)
        {
            MemoryStream stream = new MemoryStream();

            for (int j = 0; j < store.Length; j++)
            {
                store[j].WriteBlocks(stream);
            }
            byte[] data = stream.ToArray();
            SmallDocumentBlock[] rval =
                new SmallDocumentBlock[ConvertToBlockCount(size)];

            for (int index = 0; index < rval.Length; index++)
            {
                rval[index] = new SmallDocumentBlock(data, index);
            }
            return(rval);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Factory for creating SmallDocumentBlocks from DocumentBlocks
        /// </summary>
        /// <param name="bigBlocksSize"></param>
        /// <param name="store">the original DocumentBlocks</param>
        /// <param name="size">the total document size</param>
        /// <returns>an array of new SmallDocumentBlocks instances</returns>
        public static SmallDocumentBlock [] Convert(POIFSBigBlockSize bigBlocksSize,
                                                    BlockWritable [] store,
                                                    int size)
        {
            using (MemoryStream stream = Util.RecyclableMemory.GetStream())
            {
                for (int j = 0; j < store.Length; j++)
                {
                    store[j].WriteBlocks(stream);
                }
                byte[] data = stream.ToArray();
                SmallDocumentBlock[] rval = new SmallDocumentBlock[ConvertToBlockCount(size)];

                for (int index = 0; index < rval.Length; index++)
                {
                    rval[index] = new SmallDocumentBlock(bigBlocksSize, data, index);
                }
                return(rval);
            }
        }
Exemplo n.º 10
0
        public POIFSDocument(string name, SmallDocumentBlock[] blocks, int length)
        {
            _size = length;
            if(blocks.Length == 0)
                _bigBigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
            else
                _bigBigBlockSize = blocks[0].BigBlockSize;

            _big_store = new BigBlockStore(_bigBigBlockSize, EMPTY_BIG_BLOCK_ARRAY);
            _property = new DocumentProperty(name, _size);
            _small_store = new SmallBlockStore(_bigBigBlockSize, blocks);
            _property.Document = this;
        }
Exemplo n.º 11
0
 private static SmallDocumentBlock[] ConvertRawBlocksToSmallBlocks(ListManagedBlock[] blocks)
 {
     if (blocks is SmallDocumentBlock[])
         return (SmallDocumentBlock[])blocks;
     SmallDocumentBlock[] result = new SmallDocumentBlock[blocks.Length];
     System.Array.Copy(blocks, 0, result, 0, blocks.Length);
     return result;
 }
Exemplo n.º 12
0
 internal SmallBlockStore(POIFSBigBlockSize bigBlockSize, SmallDocumentBlock[] blocks)
 {
     this.bigBlockSize = bigBlockSize;
     smallBlocks = (SmallDocumentBlock[])blocks.Clone();
     this.path = null;
     this.name = null;
     this.size = -1;
     this.writer = null;
 }
Exemplo n.º 13
0
        public static DataInputBlock GetDataInputBlock(SmallDocumentBlock[] blocks, int offset)
        {
            int firstBlockIndex = offset >> BLOCK_SHIFT;

            int firstBlockOffset = offset & BLOCK_MASK;

            return new DataInputBlock(blocks[firstBlockIndex]._data, firstBlockOffset);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Constructor from small blocks
 /// </summary>
 /// <param name="name">the name of the POIFSDocument</param>
 /// <param name="blocks">Tthe small blocks making up the POIFSDocument</param>
 /// <param name="length">the actual length of the POIFSDocument</param>
 public POIFSDocument(string name, SmallDocumentBlock[] blocks, int length)
 {
     this._size = length;
     try
     {
         this._big_store = new BigBlockStore(this, new RawDataBlock[0]);
     }
     catch (IOException)
     {
     }
     this._property = new DocumentProperty(name, this._size);
     this._small_store = new SmallBlockStore(this, blocks);
     this._property.Document = this;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Makes the empty small document block.
 /// </summary>
 /// <returns></returns>
 private static SmallDocumentBlock MakeEmptySmallDocumentBlock()
 {
     SmallDocumentBlock block = new SmallDocumentBlock();
     for (int i = 0; i < block._data.Length; i++)
     {
         block._data[i] = _default_fill;
     }
     return block;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Factory for creating SmallDocumentBlocks from DocumentBlocks
        /// </summary>
        /// <param name="store">the original DocumentBlocks</param>
        /// <param name="size">the total document size</param>
        /// <returns>an array of new SmallDocumentBlocks instances</returns>
        public static SmallDocumentBlock[] Convert(BlockWritable [] store,
                                                    int size)
        {
            MemoryStream stream = new MemoryStream();

            for (int j = 0; j < store.Length; j++)
            {
                store[ j ].WriteBlocks(stream);
            }
            byte[]               data = stream.ToArray();
            SmallDocumentBlock[] rval =
                new SmallDocumentBlock[ ConvertToBlockCount(size) ];

            for (int index = 0; index < rval.Length; index++)
            {
                rval[ index ] = new SmallDocumentBlock(data, index);
            }
            return rval;
        }
Exemplo n.º 17
0
        /// <summary>
        /// convert a single long array into an array of SmallDocumentBlock
        /// 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 SmallDocumentBlock instances, filled from
        /// the array</returns>
        public static SmallDocumentBlock[] Convert(byte [] array,
                                                    int size)
        {
            SmallDocumentBlock[] rval   =
                new SmallDocumentBlock[ (size + _block_size - 1) / _block_size ];
            int                  offset = 0;

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

                    Array.Copy(array, offset, rval[ k ]._data, 0, length);
                    if (length != _block_size)
                    {

                        for (int j = (length > 0) ? (length - 1) : length; j < 0x40; j++)
                        {
                            rval[k]._data[j] = _default_fill;
                        }

                    }
                }
                else
                {
                    for (int j = 0; j < rval[k]._data.Length; j++)
                    {
                        rval[k]._data[j] = _default_fill;
                    }

                }
                offset += _block_size;
            }
            return rval;
        }