public void TestWrite1()
        {
            MemoryStream stream = new MemoryStream();
            DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);

            for (int j = 0; j < 25; j++)
            {
                dstream.Write(j);
            }
            try
            {
                dstream.Write(0);
                Assert.Fail("Should have caught IOException");
            }
            catch (IOException)
            {
            }
            byte[] output = stream.ToArray();

            Assert.AreEqual(25, output.Length);
            for (int j = 0; j < 25; j++)
            {
                Assert.AreEqual((byte)j, output[j]);
            }
            stream.Close();
        }
Esempio n. 2
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());
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="POIFSWriterEvent"/> class.
 /// </summary>
 /// <param name="stream">the POIFSDocumentWriter, freshly opened</param>
 /// <param name="path">the path of the document</param>
 /// <param name="documentName">the name of the document</param>
 /// <param name="limit">the limit, in bytes, that can be written to the stream</param>
 public POIFSWriterEventArgs(DocumentOutputStream stream, POIFSDocumentPath path, string documentName, int limit)
 {
     this.stream = stream;
     this.path = path;
     this.documentName = documentName;
     this.limit = limit;
 }
Esempio n. 4
0
 internal virtual void WriteBlocks(Stream stream)
 {
     if (this.Valid)
     {
         if (this.writer != null)
         {
             DocumentOutputStream stream2 = new DocumentOutputStream(stream, this.size);
             //OnBeforeWriting(new POIFSWriterEventArgs(stream2, this.path, this.name, this.size));
             writer.ProcessPOIFSWriterEvent(new POIFSWriterEvent(stream2, path, name, size));
             stream2.WriteFiller(this.CountBlocks * POIFSConstants.BIG_BLOCK_SIZE, DocumentBlock.FillByte);
         }
         else
         {
             for (int i = 0; i < this.bigBlocks.Length; i++)
             {
                 this.bigBlocks[i].WriteBlocks(stream);
             }
         }
     }
 }
        public void TestWriteFiller()
        {
            MemoryStream stream = new MemoryStream();
            DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);

            for (int j = 0; j < 25; j++)
            {
                dstream.Write(j);
            }
            try
            {
                dstream.Write(0);
                Assert.Fail("Should have caught IOException");
            }
            catch (IOException )
            {
            }
            dstream.WriteFiller(100, (byte)0xff);
            byte[] output = stream.ToArray();

            Assert.AreEqual(100, output.Length);
            for (int j = 0; j < 25; j++)
            {
                Assert.AreEqual((byte)j, output[j]);
            }
            for (int j = 25; j < 100; j++)
            {
                Assert.AreEqual((byte)0xff, output[j], j.ToString());
            }
            stream.Close();
        }
        public void TestWrite3()
        {
            MemoryStream stream = new MemoryStream();
            DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);
            byte[] array = new byte[50];

            for (int j = 0; j < 50; j++)
            {
                array[j] = (byte)j;
            }
            dstream.Write(array, 1, 25);
            try
            {
                dstream.Write(array, 0, 1);
                Assert.Fail("Should have caught IOException");
            }
            catch (IOException )
            {
            }
            byte[] output = stream.ToArray();

            Assert.AreEqual(25, output.Length);
            for (int j = 0; j < 25; j++)
            {
                Assert.AreEqual((byte)(j + 1), output[j]);
            }
            stream.Close();
        }
        public void TestWrite2()
        {
            MemoryStream stream = new MemoryStream();
            DocumentOutputStream dstream = new DocumentOutputStream(stream, 25);

            for (int j = 0; j < 6; j++)
            {
                byte[] array = new byte[4];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = (byte)j;
                }
                dstream.Write(array);
            }
            try
            {
                byte[] array = new byte[4];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = (byte)7;
                }

                dstream.Write(array);
                Assert.Fail("Should have caught IOException");
            }
            catch (IOException )
            {
            }
            byte[] output = stream.ToArray();

            Assert.AreEqual(24, output.Length);
            for (int j = 0; j < 6; j++)
            {
                for (int k = 0; k < 4; k++)
                {
                    Assert.AreEqual((byte)j,
                                 output[(j * 4) + k], ((j * 4) + k).ToString());
                }
            }
            stream.Close();
        }
Esempio n. 8
0
 internal virtual void WriteBlocks(Stream stream)
 {
     if (this.Valid)
     {
         if (this.writer != null)
             {
                 DocumentOutputStream stream2 = new DocumentOutputStream(stream, this.size);
                 //OnBeforeWriting(new POIFSWriterEventArgs(stream2, this.path, this.name, this.size));
             writer.ProcessPOIFSWriterEvent(new POIFSWriterEvent(stream2, path, name, size));
             stream2.WriteFiller(this.CountBlocks * POIFSConstants.BIG_BLOCK_SIZE, DocumentBlock.FillByte);
         }
         else
         {
             for (int i = 0; i < this.bigBlocks.Length; i++)
             {
                 this.bigBlocks[i].WriteBlocks(stream);
             }
         }
     }
 }
Esempio n. 9
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());
        }