コード例 #1
0
        public void Write(NPOIFSStream stream)
        {
            try
            {
                //Leon ByteArrayOutputStream  -->MemoryStream
                MemoryStream ms = new MemoryStream();
                foreach (Property property in _properties)
                {
                    if (property != null)
                    {
                        property.WriteData(ms);
                    }
                }

                stream.UpdateContents(ms.ToArray());

                // Update the start position if needed
                if (StartBlock != stream.GetStartBlock())
                {
                    StartBlock = stream.GetStartBlock();
                }
            }
            catch (System.IO.IOException ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public void Write(NPOIFSStream stream)
        {
            Stream os = stream.GetOutputStream();

            try
            {
                //Leon ByteArrayOutputStream  -->MemoryStream
                MemoryStream ms = new MemoryStream();
                foreach (Property property in _properties)
                {
                    if (property != null)
                    {
                        property.WriteData(os);
                    }
                }

                os.Close();

                // Update the start position if needed
                if (StartBlock != stream.GetStartBlock())
                {
                    StartBlock = stream.GetStartBlock();
                }
            }
            catch (System.IO.IOException)
            {
                throw;
            }
        }
コード例 #3
0
ファイル: NPropertyTable.cs プロジェクト: ctddjyds/npoi
        public void Write(NPOIFSStream stream)
        {
            try
            {
                //Leon ByteArrayOutputStream  -->MemoryStream
                MemoryStream ms = new MemoryStream();
                foreach(Property property in _properties)
                {
                    if(property != null)
                        property.WriteData(ms);
                }

                stream.UpdateContents(ms.ToArray());

                 // Update the start position if needed
              if(StartBlock != stream.GetStartBlock()) 
              {
                      StartBlock = stream.GetStartBlock();
              }
            }
            catch(System.IO.IOException ex)
            {
                throw ex;
            }
        }
コード例 #4
0
ファイル: TestNPOIFSStream.cs プロジェクト: ctddjyds/npoi
        public void TestReadWriteNewStream()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem();
            NPOIFSStream stream = new NPOIFSStream(fs);

            // Check our filesystem has a BAT and the Properties
            Assert.AreEqual(2, fs.GetFreeBlock());
            BATBlock bat = fs.GetBATBlockAndIndex(0).Block;
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, bat.GetValueAt(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, bat.GetValueAt(1));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, bat.GetValueAt(2));

            // Check the stream as-is
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, stream.GetStartBlock());
            try
            {
                stream.GetBlockIterator();
                Assert.Fail("Shouldn't be able to get an iterator before writing");
            }
            catch (Exception) { }

            // Write in two blocks
            byte[] data = new byte[512 + 20];
            for (int i = 0; i < 512; i++)
            {
                data[i] = (byte)(i % 256);
            }
            for (int i = 512; i < data.Length; i++)
            {
                data[i] = (byte)(i % 256 + 100);
            }
            stream.UpdateContents(data);

            // Check now
            Assert.AreEqual(4, fs.GetFreeBlock());
            bat = fs.GetBATBlockAndIndex(0).Block;
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, bat.GetValueAt(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, bat.GetValueAt(1));
            Assert.AreEqual(3, bat.GetValueAt(2));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, bat.GetValueAt(3));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, bat.GetValueAt(4));


            IEnumerator<ByteBuffer> it = stream.GetBlockIterator();

            Assert.AreEqual(true, it.MoveNext());
            ByteBuffer b = it.Current;

            byte[] read = new byte[512];
            //b.get(read);
           // Array.Copy(b, 0, read, 0, b.Length);
            b.Read(read);
            for (int i = 0; i < read.Length; i++)
            {
                //Assert.AreEqual("Wrong value at " + i, data[i], read[i]);
                Assert.AreEqual(data[i], read[i], "Wrong value at " + i);
            }

            Assert.AreEqual(true, it.MoveNext());
            b = it.Current;

            read = new byte[512];
            //b.get(read);
            //Array.Copy(b, 0, read, 0, b.Length);
            b.Read(read);
            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(data[i + 512], read[i]);
            }
            for (int i = 20; i < read.Length; i++)
            {
                Assert.AreEqual(0, read[i]);
            }

            Assert.AreEqual(false, it.MoveNext());
        }
コード例 #5
0
ファイル: TestNPOIFSStream.cs プロジェクト: shnug/OLE2Storage
        public void TestReadWriteNewStream()
        {
            NPOIFSFileSystem fs     = new NPOIFSFileSystem();
            NPOIFSStream     stream = new NPOIFSStream(fs);

            // Check our filesystem has a BAT and the Properties
            Assert.AreEqual(2, fs.GetFreeBlock());
            BATBlock bat = fs.GetBATBlockAndIndex(0).Block;

            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, bat.GetValueAt(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, bat.GetValueAt(1));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, bat.GetValueAt(2));

            // Check the stream as-is
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, stream.GetStartBlock());
            try
            {
                stream.GetBlockIterator();
                Assert.Fail("Shouldn't be able to get an iterator before writing");
            }
            catch (Exception) { }

            // Write in two blocks
            byte[] data = new byte[512 + 20];
            for (int i = 0; i < 512; i++)
            {
                data[i] = (byte)(i % 256);
            }
            for (int i = 512; i < data.Length; i++)
            {
                data[i] = (byte)(i % 256 + 100);
            }
            stream.UpdateContents(data);

            // Check now
            Assert.AreEqual(4, fs.GetFreeBlock());
            bat = fs.GetBATBlockAndIndex(0).Block;
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, bat.GetValueAt(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, bat.GetValueAt(1));
            Assert.AreEqual(3, bat.GetValueAt(2));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, bat.GetValueAt(3));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, bat.GetValueAt(4));


            IEnumerator <ByteBuffer> it = stream.GetBlockIterator();

            Assert.AreEqual(true, it.MoveNext());
            ByteBuffer b = it.Current;

            byte[] read = new byte[512];
            //b.get(read);
            // Array.Copy(b, 0, read, 0, b.Length);
            b.Read(read);
            for (int i = 0; i < read.Length; i++)
            {
                //Assert.AreEqual("Wrong value at " + i, data[i], read[i]);
                Assert.AreEqual(data[i], read[i], "Wrong value at " + i);
            }

            Assert.AreEqual(true, it.MoveNext());
            b = it.Current;

            read = new byte[512];
            //b.get(read);
            //Array.Copy(b, 0, read, 0, b.Length);
            b.Read(read);
            for (int i = 0; i < 20; i++)
            {
                Assert.AreEqual(data[i + 512], read[i]);
            }
            for (int i = 20; i < read.Length; i++)
            {
                Assert.AreEqual(0, read[i]);
            }

            Assert.AreEqual(false, it.MoveNext());

            fs.Close();
        }