示例#1
0
 public NPropertyTable(HeaderBlock headerBlock, NPOIFSFileSystem fileSystem)
     :base(headerBlock, 
             BuildProperties( (new NPOIFSStream(fileSystem, headerBlock.PropertyStart)).GetEnumerator(),headerBlock.BigBlockSize)
     )
 {
     _bigBigBlockSize = headerBlock.BigBlockSize;
 }
示例#2
0
        /// <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()
                );
        }
示例#3
0
        /**
         * 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;

        }
示例#4
0
        public NPOIFSMiniStore(NPOIFSFileSystem filesystem, RootProperty root,
             List<BATBlock> sbats, HeaderBlock header)
        {
            this._filesystem = filesystem;
            this._sbat_blocks = sbats;
            this._header = header;
            this._root = root;

            this._mini_stream = new NPOIFSStream(filesystem, root.StartBlock);
        }
示例#5
0
        private NPOIFSFileSystem(bool newFS)
        {
            _header = new HeaderBlock(bigBlockSize);
            _property_table = new NPropertyTable(_header);
            _mini_store = new NPOIFSMiniStore(this, _property_table.Root, new List<BATBlock>(), _header);
            _xbat_blocks = new List<BATBlock>();
            _bat_blocks = new List<BATBlock>();
            _root = null;

            if (newFS)
            {
                // Data needs to Initially hold just the header block,
                //  a single bat block, and an empty properties section
                _data = new ByteArrayBackedDataSource(new byte[bigBlockSize.GetBigBlockSize() * 3]);
            }
        }
示例#6
0
        /**
         * Create a POIFSFileSystem from an <tt>InputStream</tt>.  Normally the stream is read until
         * EOF.  The stream is always closed.<p/>
         *
         * Some streams are usable After reaching EOF (typically those that return <code>true</code>
         * for <tt>markSupported()</tt>).  In the unlikely case that the caller has such a stream
         * <i>and</i> needs to use it After this constructor completes, a work around is to wrap the
         * stream in order to trap the <tt>close()</tt> call.  A convenience method (
         * <tt>CreateNonClosingInputStream()</tt>) has been provided for this purpose:
         * <pre>
         * InputStream wrappedStream = POIFSFileSystem.CreateNonClosingInputStream(is);
         * HSSFWorkbook wb = new HSSFWorkbook(wrappedStream);
         * is.Reset();
         * doSomethingElse(is);
         * </pre>
         * Note also the special case of <tt>MemoryStream</tt> for which the <tt>close()</tt>
         * method does nothing.
         * <pre>
         * MemoryStream bais = ...
         * HSSFWorkbook wb = new HSSFWorkbook(bais); // calls bais.Close() !
         * bais.Reset(); // no problem
         * doSomethingElse(bais);
         * </pre>
         *
         * @param stream the InputStream from which to read the data
         *
         * @exception IOException on errors Reading, or on invalid data
         */

        public NPOIFSFileSystem(Stream stream)
            : this(false)
        {

            Stream channel = null;
            bool success = false;

            try
            {
                // Turn our InputStream into something NIO based
                channel = stream;

                // Get the header
                ByteBuffer headerBuffer = ByteBuffer.CreateBuffer(POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
                IOUtils.ReadFully(channel, headerBuffer.Buffer);

                // Have the header Processed
                _header = new HeaderBlock(headerBuffer);

                // Sanity check the block count
                BlockAllocationTableReader.SanityCheckBlockCount(_header.BATCount);

                // We need to buffer the whole file into memory when
                //  working with an InputStream.
                // The max possible size is when each BAT block entry is used
                int maxSize = BATBlock.CalculateMaximumSize(_header);
                //ByteBuffer data = ByteBuffer.allocate(maxSize);
                // byte[] data = new byte[maxSize];
                //// Copy in the header
                //for(int i = 0; i < headerBuffer.Length; i++)
                //{
                //    data[i] = headerBuffer[i];
                //}
                // byte[] temp = new byte[channel.Length];
                // Now read the rest of the stream

                ByteBuffer data = ByteBuffer.CreateBuffer(maxSize);
                headerBuffer.Position = 0;
                data.Write(headerBuffer.Buffer);
                data.Position = headerBuffer.Length;

                //IOUtils.ReadFully(channel, data);
                data.Position += IOUtils.ReadFully(channel, data.Buffer, data.Position, (int)channel.Length);
                success = true;

                // Turn it into a DataSource
                _data = new ByteArrayBackedDataSource(data.Buffer, data.Position);
            }
            finally
            {
                // As per the constructor contract, always close the stream
                if (channel != null)
                    channel.Close();
                CloseInputStream(stream, success);
            }

            // Now process the various entries
            ReadCoreContents();
        }
示例#7
0
        private NPOIFSFileSystem(FileStream channel, bool closeChannelOnError)
            : this(false)
        {

            try
            {
                // Get the header
                byte[] headerBuffer = new byte[POIFSConstants.SMALLER_BIG_BLOCK_SIZE];
                IOUtils.ReadFully(channel, headerBuffer);

                // Have the header Processed
                _header = new HeaderBlock(headerBuffer);

                // Now process the various entries
                _data = new FileBackedDataSource(channel);
                ReadCoreContents();
                channel.Close();

            }
            catch (IOException e)
            {
                if (closeChannelOnError)
                {
                    channel.Close();
                }
                throw e;
            }
            catch (Exception e)
            {
                // Comes from Iterators etc.
                // TODO Decide if we can handle these better whilst
                //  still sticking to the iterator contract
                if (closeChannelOnError)
                {
                    channel.Close();
                }
                throw e;
            }
        }
示例#8
0
 public NPropertyTable(HeaderBlock headerBlock) : base(headerBlock)
 {
     _bigBigBlockSize = headerBlock.BigBlockSize;
 }
示例#9
0
 public PropertyTableBase(HeaderBlock header_block, List<Property> properties)
 {
     _header_block = header_block;
     _properties = properties;
     PopulatePropertyTree((DirectoryProperty)_properties[0]);
 }
示例#10
0
 public HeaderBlockWriter(POIFSBigBlockSize bigBlockSize)
 {
     _header_block = new HeaderBlock(bigBlockSize);
 }
示例#11
0
        // there is nothing to dispose
        //public void Dispose()
        //{
        //    Dispose(true);
        //    GC.SuppressFinalize(this);
        //}

        //protected virtual void Dispose(bool disposing)
        //{
        //    if (disposing)
        //    {
        //    }
        //}

        /// <summary>
        /// Initializes a new instance of the <see cref="POIFSFileSystem"/> class.  intended for writing
        /// </summary>
        public POIFSFileSystem()
        {
            HeaderBlock headerBlock = new HeaderBlock(bigBlockSize);
            _property_table = new PropertyTable(headerBlock);
            _documents      = new ArrayList();
            _root           = null;
        }
示例#12
0
        /// <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);
        }
示例#13
0
 /**
  * Default constructor
  */
 public PropertyTable(HeaderBlock headerBlock) : base(headerBlock)
 {
     _bigBigBlockSize = headerBlock.BigBlockSize;
     _blocks = null;
 }
示例#14
0
 public static int CalculateMaximumSize(HeaderBlock header)
 {
     return CalculateMaximumSize(header.BigBlockSize, header.BATCount);
 }
示例#15
0
 public HeaderBlockWriter(HeaderBlock headerBlock)
 {
     _header_block = headerBlock;
 }
示例#16
0
        public static BATBlockAndIndex GetSBATBlockAndIndex(int offset, HeaderBlock header, List<BATBlock> sbats)
        {
            POIFSBigBlockSize bigBlockSize = header.BigBlockSize;

            int whichSBAT = (int)Math.Floor(1.0*offset / bigBlockSize.GetBATEntriesPerBlock());
            int index = offset % bigBlockSize.GetBATEntriesPerBlock();

            return new BATBlockAndIndex(index, sbats[whichSBAT]);
        }
示例#17
0
 public PropertyTableBase(HeaderBlock header_block)
 {
     _header_block = header_block;
     _properties = new List<Property>();
     AddProperty(new RootProperty());
 }