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


C# NPOIFSFileSystem.GetMiniStore方法代码示例

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


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

示例1: NPOIFSDocument

        /**
         * 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();
            }
        }
开发者ID:xoposhiy,项目名称:npoi,代码行数:19,代码来源:NPOIFSDocument.cs

示例2: TestWriteMiniStreams

        public void TestWriteMiniStreams()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize512.zvi"));
            NPOIFSMiniStore ministore = fs.GetMiniStore();
            NPOIFSStream stream = new NPOIFSStream(ministore, 178);

            // 178 -> 179 -> 180 -> end
            Assert.AreEqual(179, ministore.GetNextBlock(178));
            Assert.AreEqual(180, ministore.GetNextBlock(179));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(180));


            // Try writing 3 full blocks worth
            byte[] data = new byte[64 * 3];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)i;
            }
            stream = new NPOIFSStream(ministore, 178);
            stream.UpdateContents(data);

            // Check
            Assert.AreEqual(179, ministore.GetNextBlock(178));
            Assert.AreEqual(180, ministore.GetNextBlock(179));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(180));

            stream = new NPOIFSStream(ministore, 178);
            IEnumerator<ByteBuffer> it = stream.GetBlockIterator();
            it.MoveNext();
            ByteBuffer b178 = it.Current;
            it.MoveNext();
            ByteBuffer b179 = it.Current;
            it.MoveNext();
            ByteBuffer b180 = it.Current;

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

            Assert.AreEqual((byte)0x00, b178.Read());
            Assert.AreEqual((byte)0x01, b178.Read());
            Assert.AreEqual((byte)0x40, b179.Read());
            Assert.AreEqual((byte)0x41, b179.Read());
            Assert.AreEqual((byte)0x80, b180.Read());
            Assert.AreEqual((byte)0x81, b180.Read());


            // Try writing just into 3 blocks worth
            data = new byte[64 * 2 + 12];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)(i + 4);
            }
            stream = new NPOIFSStream(ministore, 178);
            stream.UpdateContents(data);

            // Check
            Assert.AreEqual(179, ministore.GetNextBlock(178));
            Assert.AreEqual(180, ministore.GetNextBlock(179));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(180));

            stream = new NPOIFSStream(ministore, 178);
            it = stream.GetBlockIterator();
            it.MoveNext();
            b178 = it.Current;
            it.MoveNext();
            b179 = it.Current;
            it.MoveNext();
            b180 = it.Current;
            Assert.AreEqual(false, it.MoveNext());

            Assert.AreEqual((byte)0x04, b178.Read());
            Assert.AreEqual((byte)0x05, b178.Read());
            Assert.AreEqual((byte)0x44, b179.Read());
            Assert.AreEqual((byte)0x45, b179.Read());
            Assert.AreEqual((byte)0x84, b180.Read());
            Assert.AreEqual((byte)0x85, b180.Read());


            // Try writing 1, should truncate
            data = new byte[12];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = (byte)(i + 9);
            }
            stream = new NPOIFSStream(ministore, 178);
            stream.UpdateContents(data);

            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(178));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(179));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(180));

            stream = new NPOIFSStream(ministore, 178);
            it = stream.GetBlockIterator();
            it.MoveNext();
            b178 = it.Current;
            Assert.AreEqual(false, it.MoveNext());

            Assert.AreEqual((byte)0x09, b178[0]);
            Assert.AreEqual((byte)0x0a, b178[1]);

            // Try writing 5, should extend
//.........这里部分代码省略.........
开发者ID:ctddjyds,项目名称:npoi,代码行数:101,代码来源:TestNPOIFSStream.cs

示例3: TestReadMiniStreams

        public void TestReadMiniStreams()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize512.zvi"));
            NPOIFSMiniStore ministore = fs.GetMiniStore();

            // 178 -> 179 -> 180 -> end
            NPOIFSStream stream = new NPOIFSStream(ministore, 178);
            IEnumerator<ByteBuffer> i = stream.GetBlockIterator();
            Assert.AreEqual(true, i.MoveNext());
          //  Assert.AreEqual(true, i.MoveNext());
          //  Assert.AreEqual(true, i.MoveNext());

           // i.MoveNext();
            ByteBuffer b178 = i.Current;
            Assert.AreEqual(true, i.MoveNext());
           // Assert.AreEqual(true, i.MoveNext());

           // i.MoveNext();
            ByteBuffer b179 = i.Current;
            Assert.AreEqual(true, i.MoveNext());

           // i.MoveNext();
            ByteBuffer b180 = i.Current;
            Assert.AreEqual(false, i.MoveNext());
           // Assert.AreEqual(false, i.MoveNext());
           // Assert.AreEqual(false, i.MoveNext());

            // Check the contents of the 1st block
            Assert.AreEqual((byte)0xfe, b178[0]);
            Assert.AreEqual((byte)0xff, b178[1]);
            Assert.AreEqual((byte)0x00, b178[2]);
            Assert.AreEqual((byte)0x00, b178[3]);
            Assert.AreEqual((byte)0x05, b178[4]);
            Assert.AreEqual((byte)0x01, b178[5]);
            Assert.AreEqual((byte)0x02, b178[6]);
            Assert.AreEqual((byte)0x00, b178[7]);

            // And the 2nd
            Assert.AreEqual((byte)0x6c, b179[0]);
            Assert.AreEqual((byte)0x00, b179[1]);
            Assert.AreEqual((byte)0x00, b179[2]);
            Assert.AreEqual((byte)0x00, b179[3]);
            Assert.AreEqual((byte)0x28, b179[4]);
            Assert.AreEqual((byte)0x00, b179[5]);
            Assert.AreEqual((byte)0x00, b179[6]);
            Assert.AreEqual((byte)0x00, b179[7]);

            // And the 3rd
            Assert.AreEqual((byte)0x30, b180[0]);
            Assert.AreEqual((byte)0x00, b180[1]);
            Assert.AreEqual((byte)0x00, b180[2]);
            Assert.AreEqual((byte)0x00, b180[3]);
            Assert.AreEqual((byte)0x00, b180[4]);
            Assert.AreEqual((byte)0x00, b180[5]);
            Assert.AreEqual((byte)0x00, b180[6]);
            Assert.AreEqual((byte)0x80, b180[7]);
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:57,代码来源:TestNPOIFSStream.cs

示例4: TestCreateBlockIfNeeded

        public void TestCreateBlockIfNeeded()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize512.zvi"));
            NPOIFSMiniStore ministore = fs.GetMiniStore();

            // 178 -> 179 -> 180, 181+ is free
            Assert.AreEqual(179, ministore.GetNextBlock(178));
            Assert.AreEqual(180, ministore.GetNextBlock(179));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(180));
            for (int i = 181; i < 256; i++)
            {
                Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(i));
            }

            // However, the ministore data only covers blocks to 183
            for (int i = 0; i <= 183; i++)
            {
                ministore.GetBlockAt(i);
            }
            try
            {
                ministore.GetBlockAt(184);
                Assert.Fail("No block at 184");
            }
            catch (IndexOutOfRangeException) { }

            // The ministore itself is made up of 23 big blocks
            IEnumerator<ByteBuffer> it = new NPOIFSStream(fs, fs.Root.Property.StartBlock).GetBlockIterator();
            int count = 0;

            while (it.MoveNext())
            {
                count++;
                //it.MoveNext();
            }
            Assert.AreEqual(23, count);

            // Ask it to get block 184 with creating, it will do
            ministore.CreateBlockIfNeeded(184);

            // The ministore should be one big block bigger now
            it = new NPOIFSStream(fs, fs.Root.Property.StartBlock).GetBlockIterator();
            count = 0;
            while (it.MoveNext())
            {
                count++;
                //it.MoveNext();
            }
            Assert.AreEqual(24, count);

            // The mini block block counts now run to 191
            for (int i = 0; i <= 191; i++)
            {
                ministore.GetBlockAt(i);
            }
            try
            {
                ministore.GetBlockAt(192);
                Assert.Fail("No block at 192");
            }
            catch (IndexOutOfRangeException) { }

            // Now try writing through to 192, check that the SBAT and blocks are there
            byte[] data = new byte[15 * 64];
            NPOIFSStream stream = new NPOIFSStream(ministore, 178);
            stream.UpdateContents(data);

            // Check now
            Assert.AreEqual(179, ministore.GetNextBlock(178));
            Assert.AreEqual(180, ministore.GetNextBlock(179));
            Assert.AreEqual(181, ministore.GetNextBlock(180));
            Assert.AreEqual(182, ministore.GetNextBlock(181));
            Assert.AreEqual(183, ministore.GetNextBlock(182));
            Assert.AreEqual(184, ministore.GetNextBlock(183));
            Assert.AreEqual(185, ministore.GetNextBlock(184));
            Assert.AreEqual(186, ministore.GetNextBlock(185));
            Assert.AreEqual(187, ministore.GetNextBlock(186));
            Assert.AreEqual(188, ministore.GetNextBlock(187));
            Assert.AreEqual(189, ministore.GetNextBlock(188));
            Assert.AreEqual(190, ministore.GetNextBlock(189));
            Assert.AreEqual(191, ministore.GetNextBlock(190));
            Assert.AreEqual(192, ministore.GetNextBlock(191));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(192));
            for (int i = 193; i < 256; i++)
            {
                Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(i));
            }
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:88,代码来源:TestNPOIFSMiniStore.cs

示例5: TestGetFreeBlockWithSpare

        public void TestGetFreeBlockWithSpare()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.GetFile("BlockSize512.zvi"));
            NPOIFSMiniStore ministore = fs.GetMiniStore();

            // Our 2nd SBAT block has spares
            Assert.AreEqual(false, ministore.GetBATBlockAndIndex(0).Block.HasFreeSectors);
            Assert.AreEqual(true, ministore.GetBATBlockAndIndex(128).Block.HasFreeSectors);

            // First free one at 181
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(181));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(182));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(183));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(184));

            // Ask, will get 181
            Assert.AreEqual(181, ministore.GetFreeBlock());

            // Ask again, will still get 181 as not written to
            Assert.AreEqual(181, ministore.GetFreeBlock());

            // Allocate it, then ask again
            ministore.SetNextBlock(181, POIFSConstants.END_OF_CHAIN);
            Assert.AreEqual(182, ministore.GetFreeBlock());
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:25,代码来源:TestNPOIFSMiniStore.cs

示例6: TestGetFreeBlockWithNonSpare

        public void TestGetFreeBlockWithNonSpare()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(_inst.OpenResourceAsStream("BlockSize512.zvi"));
            NPOIFSMiniStore ministore = fs.GetMiniStore();

            // We've spare ones from 181 to 255
            for (int i = 181; i < 256; i++)
            {
                Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(i));
            }

            // Check our SBAT free stuff is correct
            Assert.AreEqual(false, ministore.GetBATBlockAndIndex(0).Block.HasFreeSectors);
            Assert.AreEqual(true, ministore.GetBATBlockAndIndex(128).Block.HasFreeSectors);

            // Allocate all the spare ones
            for (int i = 181; i < 256; i++)
            {
                ministore.SetNextBlock(i, POIFSConstants.END_OF_CHAIN);
            }

            // SBAT are now full, but there's only the two
            Assert.AreEqual(false, ministore.GetBATBlockAndIndex(0).Block.HasFreeSectors);
            Assert.AreEqual(false, ministore.GetBATBlockAndIndex(128).Block.HasFreeSectors);
            try
            {
                Assert.AreEqual(false, ministore.GetBATBlockAndIndex(256).Block.HasFreeSectors);
                Assert.Fail("Should only be two SBATs");
            }
            catch (ArgumentOutOfRangeException) { }

            // Now ask for a free one, will need to extend the SBAT chain
            Assert.AreEqual(256, ministore.GetFreeBlock());

            Assert.AreEqual(false, ministore.GetBATBlockAndIndex(0).Block.HasFreeSectors);
            Assert.AreEqual(false, ministore.GetBATBlockAndIndex(128).Block.HasFreeSectors);
            Assert.AreEqual(true, ministore.GetBATBlockAndIndex(256).Block.HasFreeSectors);
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(254)); // 2nd SBAT
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, ministore.GetNextBlock(255)); // 2nd SBAT
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(256)); // 3rd SBAT
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, ministore.GetNextBlock(257)); // 3rd SBAT
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:42,代码来源:TestNPOIFSMiniStore.cs

示例7: NPOIFSDocument

        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());
        }
开发者ID:Reinakumiko,项目名称:npoi,代码行数:27,代码来源:NPOIFSDocument.cs


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