当前位置: 首页>>代码示例>>C#>>正文


C# UnicodeEncoding.GetPreamble方法代码示例

本文整理汇总了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);
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:9,代码来源:UnicodeEncodingGetPreamble.cs

示例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;
        }
开发者ID:saitodisse,项目名称:id3tag.net,代码行数:33,代码来源:Converter.cs

示例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");
                }
开发者ID:symform,项目名称:mono,代码行数:8,代码来源:UnicodeEncodingTest.cs

示例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");
                }
开发者ID:symform,项目名称:mono,代码行数:9,代码来源:UnicodeEncodingTest.cs

示例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();
     }
 }
开发者ID:davinx,项目名称:himedi,代码行数:32,代码来源:Yfx1_2_to_Taobao4_7.cs

示例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]);
                }
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:UnicodeEncodingTest.cs


注:本文中的System.Text.UnicodeEncoding.GetPreamble方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。