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


C# ChunkedMemoryStream.Write方法代码示例

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


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

示例1: TestCreateTextDataFromStream

        public void TestCreateTextDataFromStream()
        {
            var stream = new ChunkedMemoryStream();
              var str = Encoding.ASCII.GetBytes("string");

              stream.Write(str, 0, str.Length);
              stream.Position = 0L;

              var text = ImapData.CreateTextData(stream);

              Assert.AreEqual(ImapDataFormat.Text, text.Format);
              Assert.AreEqual(6, text.GetTextLength());
              Assert.AreEqual(Encoding.ASCII.GetBytes("string"), text.GetTextAsByteArray());
              Assert.AreEqual(new ByteString(str), text.GetTextAsByteString());
              Assert.AreEqual("string", text.GetTextAsString());

              Assert.AreSame(stream, text.GetTextAsStream());

              FileAssert.AreEqual(new MemoryStream(str, false), text.GetTextAsStream());

              var buffer = new byte[3];

              text.CopyText(buffer, 0, buffer.Length);

              Assert.AreEqual(str.Slice(0, 3), buffer);
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:26,代码来源:ImapData.cs

示例2: Write_100_bytes

 public void Write_100_bytes()
 {
     byte[] bytes = GetBytes(100);
     var stream = new ChunkedMemoryStream();
     stream.Write(bytes, 0, bytes.Length);
     Assert.AreEqual(100, stream.Length);
 }
开发者ID:nataren,项目名称:DReAM,代码行数:7,代码来源:ChunkedMemoryStreamTest.cs

示例3: Write_100_bytes_100_times

 public void Write_100_bytes_100_times()
 {
     byte[] bytes = GetBytes(100);
     var stream = new ChunkedMemoryStream();
     for(int i = 0; i < 100; ++i) {
         stream.Write(bytes, 0, bytes.Length);
     }
 }
开发者ID:nataren,项目名称:DReAM,代码行数:8,代码来源:ChunkedMemoryStreamTest.cs

示例4: ResourceContentBE

 public ResourceContentBE(string value, MimeType mimeType)
     : this(true) {
     if(value == null) {
         throw new ArgumentNullException("value");
     }
     if(mimeType == null) {
         throw new ArgumentNullException("mimeType");
     }
     _mimeType = mimeType;
     _stream = new ChunkedMemoryStream();
     _stream.Write(mimeType.CharSet, value);
     _size = (uint)_stream.Length;
 }
开发者ID:heran,项目名称:DekiWiki,代码行数:13,代码来源:ResourceContentBE.cs

示例5: Write_100_bytes_100_times_Read_10000_bytes

        public void Write_100_bytes_100_times_Read_10000_bytes()
        {
            byte[] bytes = GetBytes(100);
            byte[][] arrays = new byte[100][];
            var stream = new ChunkedMemoryStream();
            for(int i = 0; i < 100; ++i) {
                stream.Write(bytes, 0, bytes.Length);
                arrays[i] = bytes;
            }
            stream.Position = 0;

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

示例6: Write_100_bytes_100_times_Read_100_bytes_100_times

        public void Write_100_bytes_100_times_Read_100_bytes_100_times()
        {
            byte[] bytes = GetBytes(100);
            var stream = new ChunkedMemoryStream();
            for(int i = 0; i < 100; ++i) {
                stream.Write(bytes, 0, bytes.Length);
            }
            stream.Position = 0;

            byte[] buffer = new byte[bytes.Length];
            for(int i = 0; i < 100; ++i) {
                int read = stream.Read(buffer, 0, buffer.Length);
                Assert.AreEqual(buffer.Length, read);
                Assert.AreEqual(bytes, buffer);
            }
            Assert.AreEqual(0, stream.Read(buffer, 0, buffer.Length));
        }
开发者ID:nataren,项目名称:DReAM,代码行数:17,代码来源:ChunkedMemoryStreamTest.cs

示例7: Write_fixed_buffer_with_offset_and_overflow

 public void Write_fixed_buffer_with_offset_and_overflow()
 {
     var bytes = GetBytes(100);
     var stream = new ChunkedMemoryStream(bytes, 10, 9);
     var writtenBytes = GetBytes(10).Reverse().ToArray();
     stream.Write(writtenBytes, 0, writtenBytes.Length);
 }
开发者ID:nataren,项目名称:DReAM,代码行数:7,代码来源:ChunkedMemoryStreamTest.cs

示例8: Write_fixed_buffer_with_offset

        public void Write_fixed_buffer_with_offset()
        {
            var bytes = GetBytes(100);
            var stream = new ChunkedMemoryStream(bytes, 10, 10);
            var writtenBytes = GetBytes(10).Reverse().ToArray();
            stream.Write(writtenBytes, 0, writtenBytes.Length);

            stream.Position = 0;
            var readBytes = new byte[10];
            stream.Read(readBytes, 0, readBytes.Length);
            Assert.AreEqual(writtenBytes, readBytes);
        }
开发者ID:nataren,项目名称:DReAM,代码行数:12,代码来源:ChunkedMemoryStreamTest.cs

示例9: 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

示例10: Write_64k_bytes_Read_64k_bytes

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

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

示例11: Write_64k_bytes

 public void Write_64k_bytes()
 {
     byte[] bytes = GetBytes(64 * 1024);
     var stream = new ChunkedMemoryStream();
     stream.Write(bytes, 0, bytes.Length);
 }
开发者ID:nataren,项目名称:DReAM,代码行数:6,代码来源:ChunkedMemoryStreamTest.cs

示例12: TestWrite

        public void TestWrite()
        {
            using (var stream = new ChunkedMemoryStream(8)) {
            Assert.AreEqual(0L, stream.Position);
            Assert.AreEqual(0L, stream.Length);

            stream.Write(new byte[] {0x00}, 0, 1);
            Assert.AreEqual(1L, stream.Position);
            Assert.AreEqual(1L, stream.Length);

            stream.Write(new byte[] {0x01, 0x02, 0x03}, 0, 3);
            Assert.AreEqual(4L, stream.Position);
            Assert.AreEqual(4L, stream.Length);

            stream.Write(new byte[] {0x04, 0x05, 0x06, 0x07}, 0, 4);
            Assert.AreEqual(8L, stream.Position);
            Assert.AreEqual(8L, stream.Length);

            stream.Write(new byte[] {0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e}, 0, 7);
            Assert.AreEqual(15L, stream.Position);
            Assert.AreEqual(15L, stream.Length);

            stream.Write(new byte[] {0x0f, 0x10}, 0, 2);
            Assert.AreEqual(17L, stream.Position);
            Assert.AreEqual(17L, stream.Length);

            stream.Write(new byte[] {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, 0, 15);
            Assert.AreEqual(32L, stream.Position);
            Assert.AreEqual(32L, stream.Length);

            Assert.AreEqual(new byte[] {
              0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
              0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
            }, stream.ToArray());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:36,代码来源:ChunkedMemoryStream.cs

示例13: TestSeekInternalStateNotChanged2

        public void TestSeekInternalStateNotChanged2()
        {
            using (var stream = new ChunkedMemoryStream()) {
            Assert.AreEqual(0L, stream.Position);
            Assert.AreEqual(0L, stream.Length);

            stream.Position = 0L;

            Assert.AreEqual(0L, stream.Position);
            Assert.AreEqual(0L, stream.Length);

            stream.Write(new byte[] {0x00, 0x01, 0x02, 0x03}, 0, 4);

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

示例14: DeserializeStream

		public static Stream DeserializeStream(BufferedTextReader sr, int nextToken)
		{
			if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found " + (char)nextToken);
			nextToken = sr.Read();
			if (nextToken == '"') return new MemoryStream();
			//TODO: lazy init stream (more lightweight!?)
			var res = new ChunkedMemoryStream();
			var base64 = sr.LargeTempBuffer;
			int i = 1;
			base64[0] = (char)nextToken;
			int len;
			while ((len = sr.ReadUntil(base64, i, '"')) > 0)
			{
				i += len;
				if (i == base64.Length)
				{
					var bytes = Convert.FromBase64CharArray(base64, 0, base64.Length);
					res.Write(bytes, 0, bytes.Length);
					i = 0;
				}
			}
			nextToken = sr.Read();
			if (i > 0)
			{
				var bytes = Convert.FromBase64CharArray(base64, 0, i);
				res.Write(bytes, 0, bytes.Length);
			}
			if (nextToken != '"') throw new SerializationException("Expecting '\"' at position " + JsonSerialization.PositionInStream(sr) + ". Found end of stream.");
			return res;
		}
开发者ID:dstimac,项目名称:revenj,代码行数:30,代码来源:BinaryConverter.cs


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