本文整理汇总了C#中System.IO.MemoryStream.ReadAllText方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.ReadAllText方法的具体用法?C# MemoryStream.ReadAllText怎么用?C# MemoryStream.ReadAllText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.ReadAllText方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
public void Write(Action<Stream> output)
{
var stream = new MemoryStream();
output(stream);
stream.Position = 0;
_writer.WriteLine(stream.ReadAllText());
}
示例2: TestReadAllText
public void TestReadAllText()
{
var inputText = "Testing1234";
var bytes = Encoding.UTF8.GetBytes(inputText);
var stream = new MemoryStream(bytes);
var outputText = stream.ReadAllText(Encoding.UTF8);
Assert.AreEqual(inputText, outputText);
}
示例3: can_read_all_text_synchronously
public void can_read_all_text_synchronously()
{
var helloWorld = "Hello world.";
var stream = new MemoryStream();
var writer = new StreamWriter(stream, Encoding.Unicode);
writer.WriteLine(helloWorld);
writer.Flush();
stream.Position = 0;
stream.ReadAllText().Trim()
.ShouldBe(helloWorld);
}
示例4: injectContent
private void injectContent(IDictionary<string, object> environment, MemoryStream recordedStream, OwinHttpResponse response)
{
var html = recordedStream.ReadAllText();
var builder = new StringBuilder(html);
var position = html.IndexOf("</head>", 0, StringComparison.OrdinalIgnoreCase);
if (position >= 0)
{
builder.Insert(position, _options.Content(environment));
}
response.Write(builder.ToString());
response.Flush();
}
示例5: ReadAllText_should_return_the_correct_string
public void ReadAllText_should_return_the_correct_string()
{
const string expectedValue = "hello";
var stream = new MemoryStream();
var writer = new StreamWriter(stream)
{
AutoFlush = true
};
writer.Write(expectedValue);
stream.Position = 0;
stream.ReadAllText().Should().Be(expectedValue);
}
示例6: ToText
/// <summary>
/// Convert document to text
/// </summary>
public static string ToText(this XmlNode xmlNode, Encoding encoding)
{
if (xmlNode == null)
{
throw new ArgumentNullException("xmlNode");
}
using (var ms = new MemoryStream())
{
using (var writer = CreateXmlWriter(xmlNode, ms, encoding))
{
xmlNode.WriteTo(writer);
writer.Flush();
return ms.ReadAllText(encoding);
}
}
}
示例7: Write
public async Task Write(Func<Stream, Task> output)
{
var stream = new MemoryStream();
await output(stream).ConfigureAwait(false);
stream.Position = 0;
_writer.WriteLine(stream.ReadAllText());
}
示例8: GetContent
/// <summary>
/// Gets the content with the specified data format.
/// </summary>
/// <param name="dataFormat">The data format.</param>
/// <returns>The content with the specified data format.</returns>
private string GetContent(string dataFormat)
{
TextRange textRange = new TextRange(this.Document.ContentStart, this.Document.ContentEnd);
using (MemoryStream memoryStream = new MemoryStream())
{
textRange.Save(memoryStream, dataFormat);
memoryStream.Position = 0;
return memoryStream.ReadAllText();
}
}