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


C# MemoryStream.ToText方法代码示例

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


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

示例1: WriteToStreamUsingBackgroundThread_WriteToClosedTransferStream

        public void WriteToStreamUsingBackgroundThread_WriteToClosedTransferStream() {
            var buffer = Encoding.UTF8.GetBytes(Message);

            using(var targetStream = new MemoryStream()) {
                var transferStream = new TransferStream(targetStream);

                // 실제 targetStream에 쓰는 작업이 아니라 쓰기를 예약한 것입니다.
                //
                for(int i = 0; i < TestCount; i++) {
                    // 쓰기 요청은 했지만 실제로 targetStream에 쓰여지는 작업는 비동기적으로 수행되므로 아직 쓰여지지 않았다.
                    Assert.AreNotEqual(buffer.Length * TestCount, (int)targetStream.Length);

                    transferStream.Write(buffer, 0, buffer.Length);
                }

                // 이 때에 모든 쓰기가 완료될 것이고, 대상 Stream에 완전히 복사가 됩니다.
                transferStream.Close();

                // 여기서 예외가 발생해야 한다??? 아니다. close 가 되면 쓰기를 취소하고 그냥 반환한다.
                //
                transferStream.Write(buffer, 0, buffer.Length);

                Assert.AreEqual(buffer.Length * TestCount, (int)targetStream.Length);

                targetStream.ToText(Encoding.UTF8).Contains(Message).Should().Be.True();
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:27,代码来源:TransferStreamTestCase.cs

示例2: Open_stream_with_content

 public void Open_stream_with_content()
 {
     var memoryStream = new MemoryStream();
     var writer = new StreamWriter(memoryStream) { AutoFlush = true };
     writer.Write("foo");
     memoryStream.Position = 0;
     memoryStream.ToText().ShouldBe("foo");
 }
开发者ID:sukchr,项目名称:brevity,代码行数:8,代码来源:ToText.cs

示例3: SerializeTest

        public void SerializeTest() {
            var user = Users[0];

            using(var ms = new MemoryStream()) {
                XmlTool.Serialize(user, ms);

                ms.SetStreamPosition();

                var str = ms.ToText();
                Assert.IsNotEmpty(str);

                Assert.IsTrue(str.Contains(user.Id.ToString()));
                Console.WriteLine("Serialized Usre=" + str);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:15,代码来源:XmlToolFixture.cs

示例4: Adaptor_Compress_Decompress_By_Stream_InParallel

        public void Adaptor_Compress_Decompress_By_Stream_InParallel() {
            var plainStream = PlainText.ToStream();

            Parallel.ForEach(_compressors,
                             compressor => {
                                 var adapter = new CompressAdapter(compressor);

                                 var compressed = adapter.Compress(plainStream);
                                 var recoveryStream = new MemoryStream(compressed.Length * 2);
                                 adapter.Decompress(compressed, recoveryStream);

                                 // 데이터가 써졌으므로, 다시 원 위치로 설정해줘야 합니다.
                                 recoveryStream.SetStreamPosition();

                                 Assert.IsTrue(recoveryStream.Length > 0);
                                 Assert.AreEqual(PlainText, recoveryStream.ToText());
                             });
        }
开发者ID:debop,项目名称:NFramework,代码行数:18,代码来源:CompressAdaptorTestCase.cs

示例5: DeserializeXml

        public void DeserializeXml() {
            var user = Users[0];

            using(var ms = new MemoryStream()) {
                XmlTool.Serialize(user, ms);

                ms.SetStreamPosition();

                var xml = ms.ToText();
                // string xml = StringTool.ToString(ms);

                ms.SetStreamPosition();
                var user2 = XmlTool.Deserialize<User>(ms);

                Assert.AreEqual(user.Id, user2.Id);
                Assert.AreEqual(user.Name, user2.Name);
                Assert.AreEqual(user.Description, user2.Description);

                Assert.IsTrue(user.Equals(user2));
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:21,代码来源:XmlToolFixture.cs

示例6: ToString

        /// <summary>
        /// 문서 내용을 Xml Text로 변환한다.
        /// </summary>
        /// <param name="enc">Encoding 방식</param>
        /// <returns>Xml Text</returns>
        public string ToString(System.Text.Encoding enc) {
            using(var ms = new MemoryStream()) {
                XmlTool.Serialize(this, ms);
                ms.Position = 0;

                return ms.ToText(XmlTool.XmlEncoding);
                // return StringTool.ToString((Stream)((Object)ms), XmlConst.XmlEncoding);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:14,代码来源:XdsDocumentBase.cs

示例7: AppendTextTest

        public void AppendTextTest() {
            Assert.IsFalse(gridFS.Exists("HelloWorld.txt"));
            using(var writer = gridFS.AppendText("HelloWorld.txt")) {
                Assert.IsFalse(writer.BaseStream.CanRead);
                Assert.IsTrue(writer.BaseStream.CanSeek);
                Assert.IsTrue(writer.BaseStream.CanWrite);
                writer.Write("동해물과");
            }

            Assert.IsTrue(gridFS.Exists("HelloWorld.txt"));
            using(var writer = gridFS.AppendText("HelloWorld.txt")) {
                writer.Write(" 백두산이");
            }
            var memoryStream = new MemoryStream();
            gridFS.Download(memoryStream, "HelloWorld.txt");
            var bytes = memoryStream.ToArray();

            // 2-byte 문자열임을 나타내는 헤더값
            StringTool.IsMultiByteString(bytes).Should().Be.True();

            //Assert.AreEqual(0xEF, bytes[0]); // the BOM
            //Assert.AreEqual(0xBB, bytes[1]);
            //Assert.AreEqual(0xBF, bytes[2]);

            // Header 값을 빼고, 한다.
            // var text = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3);
            var text = memoryStream.ToText(Encoding.UTF8);

            Assert.AreEqual("동해물과 백두산이", text);
        }
开发者ID:debop,项目名称:NFramework,代码行数:30,代码来源:MongoGridFSFixture.cs

示例8: DownloadTest

        public void DownloadTest() {
            gridFS.Delete(Query.Null);

            var fileInfo = UploadHelloWord();

            using(var downloadStream = new MemoryStream()) {
                gridFS.Download(downloadStream, fileInfo);
                var downloadedBytes = downloadStream.ToArray();
                var downloadedContents = downloadStream.ToText(Encoding.UTF8);
                Assert.AreEqual(Content, downloadedContents);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:12,代码来源:MongoGridFSFixture.cs

示例9: Open_empty_stream

 public void Open_empty_stream()
 {
     var memoryStream = new MemoryStream();
     memoryStream.ToText().ShouldBe(string.Empty);
 }
开发者ID:sukchr,项目名称:brevity,代码行数:5,代码来源:ToText.cs


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