本文整理汇总了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
}
示例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
}