/// <summary> /// Read from an InputStream and Process the documents we Get /// </summary> /// <param name="stream">the InputStream from which to Read the data</param> /// <returns>POIFSDocument list</returns> public List<DocumentDescriptor> Read(Stream stream) { registryClosed = true; // Read the header block from the stream HeaderBlock header_block = new HeaderBlock(stream); // Read the rest of the stream into blocks RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block.BigBlockSize); // Set up the block allocation table (necessary for the // data_blocks to be manageable new BlockAllocationTableReader(header_block.BigBlockSize, header_block.BATCount, header_block.BATArray, header_block.XBATCount, header_block.XBATIndex, data_blocks); // Get property table from the document PropertyTable properties = new PropertyTable(header_block, data_blocks); // Process documents return ProcessProperties(SmallBlockTableReader.GetSmallDocumentBlocks (header_block.BigBlockSize, data_blocks, properties.Root, header_block.SBATStart), data_blocks, properties.Root.Children, new POIFSDocumentPath() ); }
/** * reading constructor (used when we've read in a file and we want * to extract the property table from it). Populates the * properties thoroughly * * @param startBlock the first block of the property table * @param blockList the list of blocks * * @exception IOException if anything goes wrong (which should be * a result of the input being NFG) */ public PropertyTable(HeaderBlock headerBlock, RawDataBlockList blockList) : base(headerBlock, PropertyFactory.ConvertToProperties( blockList.FetchBlocks(headerBlock.PropertyStart, -1) ) ) { _bigBigBlockSize = headerBlock.BigBlockSize; _blocks = null; }
/// <summary> /// fetch the small document block list from an existing file /// </summary> /// <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; }
/// <summary> /// Create a POIFSFileSystem from an Stream. Normally the stream is Read until /// EOF. The stream is always Closed. In the unlikely case that the caller has such a stream and /// needs to use it after this constructor completes, a work around is to wrap the /// stream in order to trap the Close() call. /// </summary> /// <param name="stream">the Streamfrom which to Read the data</param> public POIFSFileSystem(Stream stream) : this() { bool success = false; HeaderBlock header_block_reader; RawDataBlockList data_blocks; try { // Read the header block from the stream header_block_reader = new HeaderBlock(stream); bigBlockSize = header_block_reader.BigBlockSize; // Read the rest of the stream into blocks data_blocks = new RawDataBlockList(stream, bigBlockSize); success = true; } finally { CloseInputStream(stream, success); } // Set up the block allocation table (necessary for the // data_blocks to be manageable new BlockAllocationTableReader(header_block_reader.BigBlockSize, header_block_reader.BATCount, header_block_reader.BATArray, header_block_reader.XBATCount, header_block_reader.XBATIndex, data_blocks); // Get property table from the document PropertyTable properties = new PropertyTable(header_block_reader, data_blocks); // init documents ProcessProperties(SmallBlockTableReader.GetSmallDocumentBlocks(bigBlockSize, data_blocks, properties.Root, header_block_reader.SBATStart), data_blocks, properties.Root.Children, null, header_block_reader.PropertyStart); // For whatever reason CLSID of root is always 0. Root.StorageClsid = (properties.Root.StorageClsid); }