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


C# ChunkedMemoryStream.SetLength方法代码示例

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


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

示例1: Write_64k_bytes_Truncate_17k_Read_64k

        public void Write_64k_bytes_Truncate_17k_Read_64k()
        {
            byte[] bytes = GetBytes(64 * 1024);
            var stream = new ChunkedMemoryStream();
            stream.Write(bytes, 0, bytes.Length);
            stream.SetLength(17 * 1024);
            stream.Position = 0;

            byte[] buffer = new byte[bytes.Length];
            int read = stream.Read(buffer, 0, buffer.Length);
            Assert.AreEqual(17 * 1024, read);
            Assert.AreEqual(bytes.Take(17 * 1024).ToArray(), buffer.Take(17 * 1024).ToArray());
            Assert.AreEqual(0, stream.Read(buffer, 0, buffer.Length));
        }
开发者ID:nataren,项目名称:DReAM,代码行数:14,代码来源:ChunkedMemoryStreamTest.cs

示例2: TestSetLength

        public void TestSetLength()
        {
            using (var stream = new ChunkedMemoryStream(4)) {
            for (var len = 0L; len < 12L; len++) {
              stream.SetLength(len);
              Assert.AreEqual(len, stream.Length);
              Assert.AreEqual(0L, stream.Position);
            }

            stream.Position = stream.Length;

            for (var len = 12L; len <= 0L; len--) {
              stream.SetLength(len);
              Assert.AreEqual(len, stream.Length);
              Assert.AreEqual(len, stream.Position);
            }

            stream.SetLength(22L);
            Assert.AreEqual(22L, stream.Length);

            stream.Position = 22L;

            stream.SetLength(14L);
            Assert.AreEqual(14L, stream.Length);
            Assert.AreEqual(14L, stream.Position);
            Assert.AreEqual(-1, stream.ReadByte());
            Assert.AreEqual(14L, stream.Position);

            stream.SetLength(3L);
            Assert.AreEqual(3L, stream.Length);
            Assert.AreEqual(3L, stream.Position);
            Assert.AreEqual(-1, stream.ReadByte());
            Assert.AreEqual(3L, stream.Position);

            stream.SetLength(13L);
            Assert.AreEqual(13L, stream.Length);
            Assert.AreEqual(3L, stream.Position);
            Assert.AreEqual(0, stream.ReadByte());
            Assert.AreEqual(4L, stream.Position);
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:41,代码来源:ChunkedMemoryStream.cs

示例3: TestSetLengthNegative

 public void TestSetLengthNegative()
 {
     using (var stream = new ChunkedMemoryStream(4)) {
     stream.SetLength(-1);
       }
 }
开发者ID:pengyancai,项目名称:cs-util,代码行数:6,代码来源:ChunkedMemoryStream.cs

示例4: TestAllocateDisposeChunk

        public void TestAllocateDisposeChunk()
        {
            var allocated = new List<TestChunk>();

              using (var stream = new ChunkedMemoryStream(4, delegate(int size) {
            Assert.AreEqual(4, size);
            return new TestChunk(size, allocated);
              })) {
            Assert.AreEqual(1, allocated.Count, "first chunk");

            var writer = new System.IO.BinaryWriter(stream);

            writer.Write(new byte[] {0x00, 0x01, 0x02});
            writer.Flush();

            Assert.AreEqual(3L, stream.Length);
            Assert.AreEqual(1, allocated.Count);

            writer.Write(new byte[] {0x03, 0x04, 0x05});
            writer.Flush();

            Assert.AreEqual(6L, stream.Length);
            Assert.AreEqual(2, allocated.Count, "extended by Write 1");

            writer.Write(new byte[] {0x06, 0x07, 0x08});
            writer.Flush();

            Assert.AreEqual(9L, stream.Length);
            Assert.AreEqual(3, allocated.Count, "extended by Write 2");

            stream.SetLength(stream.Length);
            Assert.AreEqual(9L, stream.Length);
            Assert.AreEqual(3, allocated.Count, "SetLength(stream.Length)");

            Console.WriteLine("set length 12");
            stream.SetLength(12L);
            Assert.AreEqual(12L, stream.Length);
            Assert.AreEqual(4, allocated.Count, "extended by SetLength 1");

            Console.WriteLine("set length 8");
            stream.SetLength(8L);
            Assert.AreEqual(8L, stream.Length);
            Assert.AreEqual(3, allocated.Count, "shorten by SetLength 1");

            Console.WriteLine("set length 7");
            stream.SetLength(7L);
            Assert.AreEqual(7L, stream.Length);
            Assert.AreEqual(2, allocated.Count, "shorten by SetLength 2");

            Console.WriteLine("set length 3");
            stream.SetLength(3L);
            Assert.AreEqual(3L, stream.Length);
            Assert.AreEqual(1, allocated.Count, "shorten by SetLength 3");

            Console.WriteLine("set length 0");
            stream.SetLength(0L);
            Assert.AreEqual(0L, stream.Length);
            Assert.AreEqual(1, allocated.Count, "shorten by SetLength 4");

            Console.WriteLine("set length 12");
            stream.SetLength(12L);
            Assert.AreEqual(12L, stream.Length);
            Assert.AreEqual(4, allocated.Count, "extended by SetLength 2");

            Console.WriteLine("set length 0");
            stream.SetLength(0L);
            Assert.AreEqual(0L, stream.Length);
            Assert.AreEqual(1, allocated.Count, "shorten by SetLength 5");
              }

              Assert.AreEqual(0, allocated.Count, "closed");
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:72,代码来源:ChunkedMemoryStream.cs


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