本文整理汇总了C#中System.Text.Encoding.GetBytesWithPreamble方法的典型用法代码示例。如果您正苦于以下问题:C# Encoding.GetBytesWithPreamble方法的具体用法?C# Encoding.GetBytesWithPreamble怎么用?C# Encoding.GetBytesWithPreamble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.Encoding
的用法示例。
在下文中一共展示了Encoding.GetBytesWithPreamble方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMemoryStreamBasedEncodedText
private static SourceText CreateMemoryStreamBasedEncodedText(string text, Encoding writeEncoding, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
{
byte[] bytes = writeEncoding.GetBytesWithPreamble(text);
// For testing purposes, create a bigger buffer so that we verify
// that the implementation only uses the part that's covered by the stream and not the entire array.
byte[] buffer = new byte[bytes.Length + 10];
bytes.CopyTo(buffer, 0);
using (var stream = new MemoryStream(buffer, 0, bytes.Length, writable: true, publiclyVisible: true))
{
return EncodedStringText.Create(stream, readEncodingOpt, algorithm);
}
}
示例2: CreateMemoryStreamBasedEncodedText
private static SourceText CreateMemoryStreamBasedEncodedText(string text, Encoding writeEncoding, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
{
byte[] bytes = writeEncoding.GetBytesWithPreamble(text);
return CreateMemoryStreamBasedEncodedText(bytes, readEncodingOpt, algorithm);
}
示例3: GetBytes
protected byte[] GetBytes(Encoding encoding, string source)
{
currentEncoding = encoding;
return encoding.GetBytesWithPreamble(source);
}