本文整理汇总了C#中System.Text.UnicodeEncoding.GetPreamble方法的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding.GetPreamble方法的具体用法?C# UnicodeEncoding.GetPreamble怎么用?C# UnicodeEncoding.GetPreamble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UnicodeEncoding
的用法示例。
在下文中一共展示了UnicodeEncoding.GetPreamble方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest3
public void PosTest3()
{
UnicodeEncoding uE = new UnicodeEncoding(false, true);
Byte[] expectedValue = new Byte[] { 0xff, 0xfe };
Byte[] actualValue;
actualValue = uE.GetPreamble();
Assert.Equal(expectedValue, actualValue);
}
示例2: GetContentBytes
internal static byte[] GetContentBytes(TextEncodingType encodingType, string content)
{
byte[] contentBytes;
switch (encodingType)
{
case TextEncodingType.ISO_8859_1:
var asciiEncoding = new ASCIIEncoding();
contentBytes = asciiEncoding.GetBytes(content);
break;
case TextEncodingType.UTF16:
var utf16Encoding = new UnicodeEncoding(false, true);
var bom = utf16Encoding.GetPreamble();
var dataBytes = utf16Encoding.GetBytes(content);
// Copy BOM and Content together in an array
contentBytes = new byte[bom.Length + dataBytes.Length];
Array.Copy(bom, 0, contentBytes, 0, bom.Length);
Array.Copy(dataBytes, 0, contentBytes, bom.Length, dataBytes.Length);
break;
case TextEncodingType.UTF16_BE:
var utf16BEEncoding = new UnicodeEncoding(true, true);
contentBytes = utf16BEEncoding.GetBytes(content);
break;
case TextEncodingType.UTF8:
var utf8Encoding = new UTF8Encoding();
contentBytes = utf8Encoding.GetBytes(content);
break;
default:
throw new ID3TagException("Unknown Encoding Type found!");
}
return contentBytes;
}
示例3: TestPreamble3
public void TestPreamble3()
{
//little-endian without byte order mark.
UnicodeEncoding UnicodeEnc = new UnicodeEncoding (false, false);
byte[] PreAmble = UnicodeEnc.GetPreamble();
Assert.AreEqual (0, PreAmble.Length, "Uni #1");
}
示例4: TestPreamble2
public void TestPreamble2()
{
//big-endian with byte order mark.
UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true);
byte[] PreAmble = UnicodeEnc.GetPreamble();
Assert.AreEqual (0xFE, PreAmble [0], "Uni #1");
Assert.AreEqual (0xFF, PreAmble [1], "Uni #2");
}
示例5: DoExport
public override void DoExport()
{
this._workDir = this._baseDir.CreateSubdirectory(this._flag);
this._productImagesDir = this._workDir.CreateSubdirectory("products");
string path = Path.Combine(this._workDir.FullName, "products.csv");
using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
{
string productCSV = this.GetProductCSV();
UnicodeEncoding encoding = new UnicodeEncoding();
int byteCount = encoding.GetByteCount(productCSV);
byte[] preamble = encoding.GetPreamble();
byte[] dst = new byte[preamble.Length + byteCount];
Buffer.BlockCopy(preamble, 0, dst, 0, preamble.Length);
encoding.GetBytes(productCSV.ToCharArray(), 0, productCSV.Length, dst, preamble.Length);
stream.Write(dst, 0, dst.Length);
}
using (ZipFile file = new ZipFile())
{
file.CompressionLevel = CompressionLevel.Default;
file.AddFile(path, "");
file.AddDirectory(this._productImagesDir.FullName, this._productImagesDir.Name);
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/x-zip-compressed";
response.ContentEncoding = this._encoding;
response.AddHeader("Content-Disposition", "attachment; filename=" + this._zipFilename);
response.Clear();
file.Save(response.OutputStream);
this._workDir.Delete(true);
response.Flush();
response.Close();
}
}
示例6: TestPreamble2
public void TestPreamble2()
{
//big-endian with byte order mark.
UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true);
byte[] PreAmble = UnicodeEnc.GetPreamble();
Assertion.AssertEquals ("Uni #1", 0xFE, PreAmble [0]);
Assertion.AssertEquals ("Uni #2", 0xFF, PreAmble [1]);
}