本文整理汇总了C#中MimeKit.IO.FilteredStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredStream.CopyTo方法的具体用法?C# FilteredStream.CopyTo怎么用?C# FilteredStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MimeKit.IO.FilteredStream
的用法示例。
在下文中一共展示了FilteredStream.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBase64Decode
public void TestBase64Decode ()
{
using (var original = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.jpg"))
file.CopyTo (original, 4096);
using (var decoded = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.b64")) {
using (var filtered = new FilteredStream (file)) {
filtered.Add (DecoderFilter.Create (ContentEncoding.Base64));
filtered.CopyTo (decoded, 4096);
}
}
var buf0 = original.GetBuffer ();
var buf1 = decoded.GetBuffer ();
int n = (int) original.Length;
Assert.AreEqual (original.Length, decoded.Length, "Decoded length is incorrect.");
for (int i = 0; i < n; i++)
Assert.AreEqual (buf0[i], buf1[i], "The byte at offset {0} does not match.", i);
}
}
}
示例2: TestBase64Decode
public void TestBase64Decode ()
{
using (var original = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.jpg"))
file.CopyTo (original, 4096);
using (var decoded = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.b64")) {
using (var filtered = new FilteredStream (file)) {
filtered.Add (DecoderFilter.Create (ContentEncoding.Base64));
filtered.CopyTo (decoded, 4096);
}
}
var buf0 = original.GetBuffer ();
var buf1 = decoded.GetBuffer ();
int n = (int) original.Length;
Assert.AreEqual (original.Length, decoded.Length, "Decoded length is incorrect.");
for (int i = 0; i < n; i++)
Assert.AreEqual (buf0[i], buf1[i], "The byte at offset {0} does not match.", i);
}
}
var decoder = new Base64Decoder ();
var output = new byte[4096];
Assert.AreEqual (ContentEncoding.Base64, decoder.Encoding);
for (int i = 0; i < base64EncodedPatterns.Length; i++) {
decoder.Reset ();
var buf = Encoding.ASCII.GetBytes (base64EncodedPatterns[i]);
int n = decoder.Decode (buf, 0, buf.Length, output);
var actual = Encoding.ASCII.GetString (output, 0, n);
Assert.AreEqual (base64DecodedPatterns[i], actual, "Failed to decode base64EncodedPatterns[{0}]", i);
}
for (int i = 0; i < base64EncodedLongPatterns.Length; i++) {
decoder.Reset ();
var buf = Encoding.ASCII.GetBytes (base64EncodedLongPatterns[i]);
int n = decoder.Decode (buf, 0, buf.Length, output);
for (int j = 0; j < n; j++)
Assert.AreEqual (output[j], (byte) (j + i), "Failed to decode base64EncodedLongPatterns[{0}]", i);
}
}