Example #1
0
        /**
         * Constructor for a new Document
         *
         * @param name the name of the POIFSDocument
         * @param stream the InputStream we read data from
         */
        public NPOIFSDocument(String name, NPOIFSFileSystem filesystem, Stream stream)
        {
            this._filesystem = filesystem;
            // sotre it
            int length = Store(stream);

            // Build the property for it
            this._property = new DocumentProperty(name, length);
            _property.StartBlock = _stream.GetStartBlock();
        }
        /**
         * Create an OutputStream from the specified DocumentEntry.
         * The specified entry will be emptied.
         * 
         * @param document the DocumentEntry to be written
         */
        public NDocumentOutputStream(DocumentEntry document)
        {
            if (!(document is DocumentNode))
            {
                throw new IOException("Cannot open internal document storage, " + document + " not a Document Node");
            }
            _document_size = 0;
            _closed = false;

            _property = (DocumentProperty)((DocumentNode)document).Property;

            _document = new NPOIFSDocument((DocumentNode)document);
            _document.Free();
        }
Example #3
0
        public POIFSDocument(string name, RawDataBlock[] blocks, int length)
        {
            _size = length;
            if (blocks.Length == 0)
                _bigBigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS;
            else
            {
                _bigBigBlockSize = (blocks[0].BigBlockSize == POIFSConstants.SMALLER_BIG_BLOCK_SIZE ?
                    POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS : POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS);
            }

            _big_store = new BigBlockStore(_bigBigBlockSize, ConvertRawBlocksToBigBlocks(blocks));
            _property = new DocumentProperty(name, _size);
            _small_store = new SmallBlockStore(_bigBigBlockSize, EMPTY_SMALL_BLOCK_ARRAY);
            _property.Document = this;
        }
Example #4
0
        /**
         * Constructor for an existing Document 
         */
        public NPOIFSDocument(DocumentProperty property, NPOIFSFileSystem filesystem)
        {
            this._property = property;
            this._filesystem = filesystem;

            if (property.Size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE)
            {
                _stream = new NPOIFSStream(_filesystem.GetMiniStore(), property.StartBlock);
                _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize();
            }
            else
            {
                _stream = new NPOIFSStream(_filesystem, property.StartBlock);
                _block_size = _filesystem.GetBlockStoreBlockSize();
            }
        }
Example #5
0
        /**
         * create a DocumentNode. This method Is not public by design; it
         * Is intended strictly for the internal use of this package
         *
         * @param property the DocumentProperty for this DocumentEntry
         * @param parent the parent of this entry
         */

        public DocumentNode(DocumentProperty property, DirectoryNode parent):base(property, parent)
        {
            _document = property.Document;
        }
        /**
         * Create an OutputStream to create the specified new Entry
         * 
         * @param parent Where to create the Entry
         * @param name Name of the new entry
         */
        public NDocumentOutputStream(DirectoryEntry parent, String name)
        {
            if (!(parent is DirectoryNode))
            {
                throw new IOException("Cannot open internal directory storage, " + parent + " not a Directory Node");
            }
            _document_size = 0;
            _closed = false;

            // Have an empty one Created for now
            DocumentEntry doc = parent.CreateDocument(name, new MemoryStream(new byte[0]));
            _property = (DocumentProperty)((DocumentNode)doc).Property;
            _document = new NPOIFSDocument((DocumentNode)doc);
        }
Example #7
0
        public void TestWriterPropertyTable()
        {
            HeaderBlock headerBlock = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
            PropertyTable table = new PropertyTable(headerBlock);

            DocumentProperty workbook = new DocumentProperty("Workbook", 0x00046777);

            workbook.StartBlock = 0;

            DocumentProperty summary1 = new DocumentProperty("\x0005SummaryInformation", 0x00001000);
            summary1.StartBlock = 0x00000234;

            DocumentProperty summary2 = new DocumentProperty("\x0005DocumentSummaryInformation", 0x00001000);
            summary2.StartBlock = 0x0000023C;
            table.AddProperty(workbook);
            RootProperty root = table.Root;

            root.AddChild(workbook);
            table.AddProperty(summary1);
            root = table.Root;
            root.AddChild(summary1);
            table.AddProperty(summary2);
            root = table.Root;
            root.AddChild(summary2);
            table.PreWrite();

            string[] testblock = {
			"52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"16 00 05 01 FF FF FF FF FF FF FF FF 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 00 00 00",
			"57 00 6F 00 72 00 6B 00 62 00 6F 00 6F 00 6B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"12 00 02 01 FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 77 67 04 00 00 00 00 00",
			"05 00 53 00 75 00 6D 00 6D 00 61 00 72 00 79 00 49 00 6E 00 66 00 6F 00 72 00 6D 00 61 00 74 00",
			"69 00 6F 00 6E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"28 00 02 01 01 00 00 00 03 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 02 00 00 00 10 00 00 00 00 00 00",
			"05 00 44 00 6F 00 63 00 75 00 6D 00 65 00 6E 00 74 00 53 00 75 00 6D 00 6D 00 61 00 72 00 79 00",
			"49 00 6E 00 66 00 6F 00 72 00 6D 00 61 00 74 00 69 00 6F 00 6E 00 00 00 00 00 00 00 00 00 00 00",
			"38 00 02 01 FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3C 02 00 00 00 10 00 00 00 00 00 00",
        };

            ConfirmBlockEncoding(testblock, table);

            table.RemoveProperty(summary1);
            root = table.Root;
            root.DeleteChild(summary1);
            table.PreWrite();

            string[] testblock2 = {
			"52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"16 00 05 01 FF FF FF FF FF FF FF FF 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 00 00 00",
			"57 00 6F 00 72 00 6B 00 62 00 6F 00 6F 00 6B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"12 00 02 01 FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 77 67 04 00 00 00 00 00",
			"05 00 44 00 6F 00 63 00 75 00 6D 00 65 00 6E 00 74 00 53 00 75 00 6D 00 6D 00 61 00 72 00 79 00",
			"49 00 6E 00 66 00 6F 00 72 00 6D 00 61 00 74 00 69 00 6F 00 6E 00 00 00 00 00 00 00 00 00 00 00",
			"38 00 02 01 01 00 00 00 FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3C 02 00 00 00 10 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"02 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
        };
            ConfirmBlockEncoding(testblock2, table);

            table.AddProperty(summary1);
            root = table.Root;
            root.AddChild(summary1);
            table.PreWrite();

            string[] testblock3 = {
			"52 00 6F 00 6F 00 74 00 20 00 45 00 6E 00 74 00 72 00 79 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"16 00 05 01 FF FF FF FF FF FF FF FF 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FE FF FF FF 00 00 00 00 00 00 00 00",
			"57 00 6F 00 72 00 6B 00 62 00 6F 00 6F 00 6B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"12 00 02 01 FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 77 67 04 00 00 00 00 00",
			"05 00 44 00 6F 00 63 00 75 00 6D 00 65 00 6E 00 74 00 53 00 75 00 6D 00 6D 00 61 00 72 00 79 00",
			"49 00 6E 00 66 00 6F 00 72 00 6D 00 61 00 74 00 69 00 6F 00 6E 00 00 00 00 00 00 00 00 00 00 00",
			"38 00 02 01 FF FF FF FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3C 02 00 00 00 10 00 00 00 00 00 00",
			"05 00 53 00 75 00 6D 00 6D 00 61 00 72 00 79 00 49 00 6E 00 66 00 6F 00 72 00 6D 00 61 00 74 00",
			"69 00 6F 00 6E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"28 00 02 01 01 00 00 00 02 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
			"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 02 00 00 00 10 00 00 00 00 00 00",
        };
            ConfirmBlockEncoding(testblock3, table);
        }
Example #8
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;
        }
Example #9
0
 public POIFSDocument(string name, int size, POIFSBigBlockSize bigBlockSize, POIFSDocumentPath path, POIFSWriterListener writer)
     {
     _size = size;
     _bigBigBlockSize = bigBlockSize;
     _property = new DocumentProperty(name, _size);
     _property.Document = this;
     if (_property.ShouldUseSmallBlocks)
     {
         _small_store = new SmallBlockStore(_bigBigBlockSize, path, name, size, writer);
         _big_store = new BigBlockStore(_bigBigBlockSize, EMPTY_BIG_BLOCK_ARRAY);
     }
     else
     {
         _small_store = new SmallBlockStore(_bigBigBlockSize, EMPTY_SMALL_BLOCK_ARRAY);
         _big_store = new BigBlockStore(_bigBigBlockSize, path, name, size, writer);
     }
 }
Example #10
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);
        }

        }
Example #11
0
        public POIFSDocument(string name, POIFSBigBlockSize bigBlockSize, ListManagedBlock[] blocks, int length)
        {
            _size = length;
            _bigBigBlockSize = bigBlockSize;
            _property = new DocumentProperty(name, _size);
            _property.Document = this;

            if (Property.IsSmall(_size))
            {
                _big_store = new BigBlockStore(bigBlockSize, EMPTY_BIG_BLOCK_ARRAY);
                _small_store = new SmallBlockStore(bigBlockSize, ConvertRawBlocksToSmallBlocks(blocks));
            }
            else
            {
                _big_store = new BigBlockStore(bigBlockSize, ConvertRawBlocksToBigBlocks(blocks));
                _small_store = new SmallBlockStore(bigBlockSize, EMPTY_SMALL_BLOCK_ARRAY);
            }
        }
Example #12
0
        public NPOIFSDocument(String name, int size, NPOIFSFileSystem filesystem, POIFSWriterListener Writer)
        {
            this._filesystem = filesystem;

            if (size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE)
            {
                _stream = new NPOIFSStream(filesystem.GetMiniStore());
                _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize();
            }
            else
            {
                _stream = new NPOIFSStream(filesystem);
                _block_size = _filesystem.GetBlockStoreBlockSize();
            }

            Stream innerOs = _stream.GetOutputStream();
            DocumentOutputStream os = new DocumentOutputStream(innerOs, size);
            POIFSDocumentPath path = new POIFSDocumentPath(name.Split(new string[] { "\\\\" }, StringSplitOptions.RemoveEmptyEntries));
            String docName = path.GetComponent(path.Length - 1);
            POIFSWriterEvent event1 = new POIFSWriterEvent(os, path, docName, size);
            Writer.ProcessPOIFSWriterEvent(event1);
            innerOs.Close();

            // And build the property for it
            this._property = new DocumentProperty(name, size);
            _property.StartBlock = (/*setter*/_stream.GetStartBlock());
        }
        private void VerifyProperty(String name, int size)
        {
            DocumentProperty property = new DocumentProperty(name, size);

            if (size >= 4096)
            {
                Assert.IsTrue(!property.ShouldUseSmallBlocks);
            }
            else
            {
                Assert.IsTrue(property.ShouldUseSmallBlocks);
            }
            byte[] Testblock = new byte[128];
            int index = 0;

            for (; index < 0x40; index++)
            {
                Testblock[index] = (byte)0;
            }
            int limit = Math.Min(31, name.Length);

            Testblock[index++] = (byte)(2 * (limit + 1));
            Testblock[index++] = (byte)0;
            Testblock[index++] = (byte)2;
            Testblock[index++] = (byte)1;
            for (; index < 0x50; index++)
            {
                Testblock[index] = (byte)0xFF;
            }
            for (; index < 0x78; index++)
            {
                Testblock[index] = (byte)0;
            }
            int sz = size;

            Testblock[index++] = (byte)sz;
            sz /= 256;
            Testblock[index++] = (byte)sz;
            sz /= 256;
            Testblock[index++] = (byte)sz;
            sz /= 256;
            Testblock[index++] = (byte)sz;
            for (; index < 0x80; index++)
            {
                Testblock[index] = (byte)0x0;
            }
            byte[] name_bytes = Encoding.UTF8.GetBytes(name);

            for (index = 0; index < limit; index++)
            {
                Testblock[index * 2] = name_bytes[index];
            }
            MemoryStream stream = new MemoryStream(512);

            property.WriteData(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(Testblock.Length, output.Length);
            for (int j = 0; j < Testblock.Length; j++)
            {
                Assert.AreEqual(Testblock[j],
                             output[j], "mismatch at offset " + j);
            }
        }
        private void VerifyReadingProperty(int index, byte[] input, int offset, string name)
        {
            DocumentProperty property = new DocumentProperty(index, input, offset);
            MemoryStream stream = new MemoryStream(128);
            byte[] expected = new byte[128];

            Array.Copy(input, offset, expected, 0, 128);
            property.WriteData(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(128, output.Length);
            for (int j = 0; j < 128; j++)
            {
                Assert.AreEqual(expected[j],
                             output[j], "mismatch at offset " + j);
            }
            Assert.AreEqual(index, property.Index);
            Assert.AreEqual(name, property.Name);
        }