当前位置: 首页>>代码示例>>C#>>正文


C# NPOIFSFileSystem.WriteFilesystem方法代码示例

本文整理汇总了C#中NPOI.POIFS.FileSystem.NPOIFSFileSystem.WriteFilesystem方法的典型用法代码示例。如果您正苦于以下问题:C# NPOIFSFileSystem.WriteFilesystem方法的具体用法?C# NPOIFSFileSystem.WriteFilesystem怎么用?C# NPOIFSFileSystem.WriteFilesystem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPOI.POIFS.FileSystem.NPOIFSFileSystem的用法示例。


在下文中一共展示了NPOIFSFileSystem.WriteFilesystem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCreateWriteRead

        public void TestCreateWriteRead()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem();

            // Initially has a BAT but not SBAT
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(2));

            // Check that the SBAT is empty
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.Root.Property.StartBlock);

            // Write and read it
            MemoryStream baos = new MemoryStream();
            fs.WriteFilesystem(baos);
            byte[] temp = baos.ToArray();
            fs = new NPOIFSFileSystem(new MemoryStream(temp));
            //fs = new NPOIFSFileSystem(new MemoryStream(baos.ToArray()));

            // Check it's still like that
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(2));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.Root.Property.StartBlock);

            // Now add a normal stream and a mini stream
            // TODO

            // TODO The rest of the test
        }
开发者ID:hanwangkun,项目名称:npoi,代码行数:30,代码来源:TestNPOIFSFileSystem.cs

示例2: TestGetFreeBlockWithNoneSpare


//.........这里部分代码省略.........
                }
            }

            Assert.AreEqual(false, fs.GetBATBlockAndIndex(109 * 128 - 1).Block.HasFreeSectors);
            try
            {
                Assert.AreEqual(false, fs.GetBATBlockAndIndex(109 * 128).Block.HasFreeSectors);
                Assert.Fail("Should only be 109 BATs");
            }
           // catch (IndexOutOfRangeException)
            catch(ArgumentOutOfRangeException)
            {
            }

            free = fs.GetFreeBlock();
            Assert.AreEqual(false, fs.GetBATBlockAndIndex(109 * 128 - 1).Block.HasFreeSectors);
            Assert.AreEqual(true, fs.GetBATBlockAndIndex(110 * 128 - 1).Block.HasFreeSectors);
            try
            {
                Assert.AreEqual(false, fs.GetBATBlockAndIndex(110 * 128).Block.HasFreeSectors);
                Assert.Fail("Should only be 110 BATs");
            }
            //catch (IndexOutOfRangeException)
            catch(ArgumentOutOfRangeException)
            {
            }

            for (int i = 109; i < 109 + 127; i++)
            {
                fs.GetFreeBlock();
                int startOffset = i * 128;
                while (fs.GetBATBlockAndIndex(startOffset).Block.HasFreeSectors)
                {
                    free = fs.GetFreeBlock();
                    fs.SetNextBlock(free, POIFSConstants.END_OF_CHAIN);
                }
            }

            // Should now have 109+127 = 236 BATs
            Assert.AreEqual(false, fs.GetBATBlockAndIndex(236 * 128 - 1).Block.HasFreeSectors);
            try
            {
                Assert.AreEqual(false, fs.GetBATBlockAndIndex(236 * 128).Block.HasFreeSectors);
                Assert.Fail("Should only be 236 BATs");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            // Ask for another, will get our 2nd XBAT
            free = fs.GetFreeBlock();
            Assert.AreEqual(false, fs.GetBATBlockAndIndex(236 * 128 - 1).Block.HasFreeSectors);
            Assert.AreEqual(true, fs.GetBATBlockAndIndex(237 * 128 - 1).Block.HasFreeSectors);
            try
            {
                Assert.AreEqual(false, fs.GetBATBlockAndIndex(237 * 128).Block.HasFreeSectors);
                Assert.Fail("Should only be 237 BATs");
            }
            // catch (IndexOutOfRangeException) { }
            catch (ArgumentOutOfRangeException)
            {
            }

            // Check the counts
            int numBATs = 0;
            int numXBATs = 0;
            for (int i = 0; i < 237 * 128; i++)
            {
                if (fs.GetNextBlock(i) == POIFSConstants.FAT_SECTOR_BLOCK)
                {
                    numBATs++;
                }
                if (fs.GetNextBlock(i) == POIFSConstants.DIFAT_SECTOR_BLOCK)
                {
                    numXBATs++;
                }
            }
            Assert.AreEqual(237, numBATs);
#if !HIDE_UNREACHABLE_CODE
            if (1 == 2)
            {
                // TODO Fix this - actual is 128
                Assert.AreEqual(2, numXBATs);
            }
#endif
            MemoryStream stream = new MemoryStream();
            fs.WriteFilesystem(stream);

            HeaderBlock header = new HeaderBlock(new MemoryStream(stream.ToArray()));
            Assert.AreEqual(237, header.BATCount);
#if !HIDE_UNREACHABLE_CODE
            if (1 == 2) // TODO Fix this - actual is 128
            {                
                Assert.AreEqual(2, header.XBATCount);

                fs = new NPOIFSFileSystem(new MemoryStream(stream.ToArray()));
            }
#endif

        }
开发者ID:hanwangkun,项目名称:npoi,代码行数:101,代码来源:TestNPOIFSFileSystem.cs


注:本文中的NPOI.POIFS.FileSystem.NPOIFSFileSystem.WriteFilesystem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。