本文整理汇总了C#中System.IO.MemoryStream.SetStreamPosition方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.SetStreamPosition方法的具体用法?C# MemoryStream.SetStreamPosition怎么用?C# MemoryStream.SetStreamPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.SetStreamPosition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
}
示例2: ToStream
/// <summary>
/// 문자열을 기본 인코딩 방식으로 스트림 (<see cref="System.IO.MemoryStream"/>)의 인스턴스로 변환한다.
/// </summary>
/// <param name="s">대상문자열</param>
/// <returns>기본인코딩 방식으로 Stream을 만든다.</returns>
public static Stream ToStream(this string s) {
if(s.IsNull())
return new MemoryStream();
var stream = new MemoryStream(s.Length * 2);
var writer = new StreamWriter(stream);
writer.Write(s);
writer.Flush();
stream.SetStreamPosition();
return stream;
}
示例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);
}
}
示例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());
});
}
示例5: Stream_SetStreamPosition_Test2
public void Stream_SetStreamPosition_Test2()
{
using (var ms = new MemoryStream(GetTestBuffer()))
{
var position = new StreamPosition(32, null);
Assert.AreEqual(true, ms.SetStreamPosition(position));
Assert.AreEqual(32, ms.Position);
}
}
示例6: Stream_SetStreamPosition_Test1
public void Stream_SetStreamPosition_Test1()
{
using (var ms = new MemoryStream(GetTestBuffer()))
{
var position = new StreamPosition(128, null);
Assert.AreEqual(false, ms.SetStreamPosition(position));
Assert.AreEqual(0, ms.Position);
}
}