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


C# UTF8Encoding.GetPreamble方法代码示例

本文整理汇总了C#中System.Text.UTF8Encoding.GetPreamble方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.GetPreamble方法的具体用法?C# UTF8Encoding.GetPreamble怎么用?C# UTF8Encoding.GetPreamble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.UTF8Encoding的用法示例。


在下文中一共展示了UTF8Encoding.GetPreamble方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PosTest1

        public void PosTest1()
        {
            UTF8Encoding UTF8NoPreamble = new UTF8Encoding();
            Byte[] preamble;

            preamble = UTF8NoPreamble.GetPreamble();
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:UTF8EncodingGetPreamble.cs

示例2: EncodingBOM

        public void EncodingBOM()
        {
            var utf8BOM = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true);

            var bytes = utf8BOM.GetPreamble().Concat(utf8BOM.GetBytes("abc")).ToArray();
            Assert.Equal(utf8BOM, SourceText.From(bytes, bytes.Length, s_unicode).Encoding);
            Assert.Equal(utf8BOM, SourceText.From(bytes, bytes.Length, null).Encoding);

            var stream = new MemoryStream(bytes);
            Assert.Equal(utf8BOM, SourceText.From(stream, s_unicode).Encoding);
            Assert.Equal(utf8BOM, SourceText.From(stream, null).Encoding);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:12,代码来源:SourceTextTests.cs

示例3: GetSQLResource

        private static string GetSQLResource(string SQLName)
        {
            var resourceStream = new MemoryStream();
            var assemblyStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(SQLName);
            if (assemblyStream == null)
                throw new DatabaseConfigurationException("Could not find the resource " + SQLName);
            assemblyStream.CopyTo(resourceStream);
            byte[] resourceBytes = resourceStream.ToArray();
            var encoder = new UTF8Encoding(true, true); //without byte order mark

            //Strip the BOM out of the resource if it's present
            byte[] bom = encoder.GetPreamble();
            bool haveBom = true;
            for (int i = 0; i < bom.Length; i++)
            {
                if (resourceBytes[i] != bom[i])
                    haveBom = false;
            }
            int startOffset = haveBom ? bom.Length : 0;

            return encoder.GetString(resourceBytes, startOffset, resourceBytes.Length - startOffset);
        }
开发者ID:raiker,项目名称:PhotoWeasel,代码行数:22,代码来源:Database.cs

示例4: Main

        static void Main(string[] args)
        {
            var files = Directory.GetFiles(@"C:\files\");
            var result = new List<string>();

            foreach (var file in files)
            {
                 var bytes = File.ReadAllBytes(file);
                
                    var enc = new UTF8Encoding(true);
                    var preamble = enc.GetPreamble();

                if (preamble.Where((p, i) => p != bytes[i]).Any())
                {
                    result.Add(file);
                }

            }

            Console.WriteLine(string.Join(Environment.NewLine, result));
            Console.WriteLine("done");
            Console.ReadLine();
        }
开发者ID:ChelseaStats,项目名称:BomlessFiles,代码行数:23,代码来源:program.cs

示例5: SendWebRequest

 private void SendWebRequest()
 {
     Encoding encoding = new UTF8Encoding(true);
     RequestProperties selectedObject = this.propRequest.SelectedObject as RequestProperties;
     HttpWebRequest request = (HttpWebRequest)WebRequest.CreateDefault(new Uri(selectedObject.Url));
     if ((selectedObject.HttpProxy != null) && (selectedObject.HttpProxy.Length != 0))
     {
         request.Proxy = new WebProxy(selectedObject.HttpProxy);
     }
     request.Method = selectedObject.Method.ToString();
     request.ContentType = selectedObject.ContentType;
     request.Headers["SOAPAction"] = selectedObject.SOAPAction;
     request.SendChunked = selectedObject.SendChunked;
     request.AllowAutoRedirect = selectedObject.AllowAutoRedirect;
     request.AllowWriteStreamBuffering = selectedObject.AllowWriteStreamBuffering;
     request.KeepAlive = selectedObject.KeepAlive;
     request.Pipelined = selectedObject.Pipelined;
     request.PreAuthenticate = selectedObject.PreAuthenticate;
     request.Timeout = selectedObject.Timeout;
     HttpWebClientProtocol proxy = this.GetCurrentMethodProperty().GetProxyProperty().GetProxy();
     if (selectedObject.UseCookieContainer)
     {
         if (proxy.CookieContainer != null)
         {
             request.CookieContainer = proxy.CookieContainer;
         }
         else
         {
             request.CookieContainer = new CookieContainer();
         }
     }
     CredentialCache cache = new CredentialCache();
     bool flag = false;
     if ((selectedObject.BasicAuthUserName != null) && (selectedObject.BasicAuthUserName.Length != 0))
     {
         cache.Add(new Uri(selectedObject.Url), "Basic", new NetworkCredential(selectedObject.BasicAuthUserName, selectedObject.BasicAuthPassword));
         flag = true;
     }
     if (selectedObject.UseDefaultCredential)
     {
         cache.Add(new Uri(selectedObject.Url), "NTLM", (NetworkCredential)CredentialCache.DefaultCredentials);
         flag = true;
     }
     if (flag)
     {
         request.Credentials = cache;
     }
     if (selectedObject.Method == RequestProperties.HttpMethod.POST)
     {
         request.ContentLength = this.richRequest.Text.Length + encoding.GetPreamble().Length;
         StreamWriter writer = new StreamWriter(request.GetRequestStream(), encoding);
         writer.Write(this.richRequest.Text);
         writer.Close();
     }
     try
     {
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         this.DumpResponse(response);
         response.Close();
     }
     catch (WebException exception)
     {
         if (exception.Response != null)
         {
             this.DumpResponse((HttpWebResponse)exception.Response);
         }
         else
         {
             this.richResponse.Text = exception.ToString();
         }
     }
     catch (Exception exception2)
     {
         this.richResponse.Text = exception2.ToString();
     }
 }
开发者ID:hdougie,项目名称:webservicestudio2,代码行数:76,代码来源:NewMainForm.cs

示例6: DownloadTags

        public ActionResult DownloadTags(int id = invalidId, string formatString = "", bool setFormatString = false, bool includeHeader = false)
        {
            if (id == invalidId)
                return NoId();

            if (setFormatString) {
                userQueries.SetAlbumFormatString(formatString);
            } else if (string.IsNullOrEmpty(formatString) && LoginManager.IsLoggedIn) {
                formatString = LoginManager.LoggedUser.AlbumFormatString;
            }

            if (string.IsNullOrEmpty(formatString))
                formatString = TagFormatter.TagFormatStrings[0];

            var album = Service.GetAlbum(id);
            var tagString = Service.GetAlbumTagString(id, formatString, includeHeader);

            var enc = new UTF8Encoding(true);
            var data = enc.GetPreamble().Concat(enc.GetBytes(tagString)).ToArray();

            return File(data, "text/csv", album.Name + ".csv");
        }
开发者ID:realzhaorong,项目名称:vocadb,代码行数:22,代码来源:AlbumController.cs

示例7: SendWebRequest

 private void SendWebRequest()
 {
     Encoding encoding1 = new UTF8Encoding(true);
     RequestProperties properties1 = propRequest.SelectedObject as RequestProperties;
     if (properties1 != null)
     {
         HttpWebRequest request1 = (HttpWebRequest)WebRequest.CreateDefault(new Uri(properties1.Url));
         if ((properties1.HttpProxy != null) && (properties1.HttpProxy.Length != 0))
         {
             request1.Proxy = new WebProxy(properties1.HttpProxy);
         }
         request1.Method = properties1.Method.ToString();
         request1.ContentType = properties1.ContentType;
         request1.Headers["SOAPAction"] = properties1.SOAPAction;
         request1.SendChunked = properties1.SendChunked;
         request1.AllowAutoRedirect = properties1.AllowAutoRedirect;
         request1.AllowWriteStreamBuffering = properties1.AllowWriteStreamBuffering;
         request1.KeepAlive = properties1.KeepAlive;
         request1.Pipelined = properties1.Pipelined;
         request1.PreAuthenticate = properties1.PreAuthenticate;
         request1.Timeout = properties1.Timeout;
         MethodProperty property1 = GetCurrentMethodProperty();
         HttpWebClientProtocol protocol1 = property1.GetProxyProperty().GetProxy();
         if (properties1.UseCookieContainer)
         {
             if (protocol1.CookieContainer != null)
             {
                 request1.CookieContainer = protocol1.CookieContainer;
             }
             else
             {
                 request1.CookieContainer = new CookieContainer();
             }
         }
         CredentialCache cache1 = new CredentialCache();
         bool flag1 = false;
         if ((properties1.BasicAuthUserName != null) && (properties1.BasicAuthUserName.Length != 0))
         {
             cache1.Add(new Uri(properties1.Url), "Basic",
                        new NetworkCredential(properties1.BasicAuthUserName, properties1.BasicAuthPassword));
             flag1 = true;
         }
         if (properties1.UseDefaultCredential)
         {
             cache1.Add(new Uri(properties1.Url), "NTLM", (NetworkCredential)CredentialCache.DefaultCredentials);
             flag1 = true;
         }
         if (flag1)
         {
             request1.Credentials = cache1;
         }
         if (properties1.Method == RequestProperties.HttpMethod.POST)
         {
             request1.ContentLength = richRequest.Text.Length + encoding1.GetPreamble().Length;
             StreamWriter writer1 = new StreamWriter(request1.GetRequestStream(), encoding1);
             writer1.Write(richRequest.Text);
             writer1.Close();
         }
         try
         {
             HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
             DumpResponse(response1);
             response1.Close();
         }
         catch (WebException exception1)
         {
             if (exception1.Response != null)
             {
                 DumpResponse((HttpWebResponse)exception1.Response);
                 return;
             }
             richResponse.Text = exception1.ToString();
         }
         catch (Exception exception2)
         {
             richResponse.Text = exception2.ToString();
         }
     }
 }
开发者ID:irdetocustomercentral,项目名称:WebServiceStudio,代码行数:79,代码来源:MainForm.cs

示例8: DownloadTags

        public FileContentResult DownloadTags(int id)
        {
            var album = Service.GetAlbum(id);
            var tagString = Service.GetAlbumTagString(id, TagFormatter.TagFormatStrings[0]);
            var enc = new UTF8Encoding(true);
            var data = enc.GetPreamble().Concat(enc.GetBytes(tagString)).ToArray();

            return File(data, "text/csv", album.Name + ".csv");
        }
开发者ID:realzhaorong,项目名称:vocadb,代码行数:9,代码来源:AlbumController.cs

示例9: SendWebRequest

 public static string SendWebRequest(string url, string action, string rqt, string method, string requestContentType, int timeout)
 {
     string responseXml = string.Empty;
     Encoding encoding = new UTF8Encoding(true);
     HttpWebRequest request = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
     System.Net.CookieContainer cc = new CookieContainer();
     request.Method = method;
     request.ContentType = requestContentType;
     request.Headers["SOAPAction"] = action;
     request.AllowAutoRedirect = true;
     request.AllowWriteStreamBuffering = true;
     request.SendChunked = false;
     request.KeepAlive = false;
     request.Pipelined = false;
     request.PreAuthenticate = false;
     request.Timeout = timeout;
     request.CookieContainer = new CookieContainer();
     CredentialCache cache = new CredentialCache();
     #region Pending
     //request.Proxy=...
     //bool flag = false;
     //if (basicAuthUserName != null && basicAuthUserName!=null))
     //{
     //    cache.Add(new Uri(selectedObject.Url), "Basic", new NetworkCredential(basicAuthUserName, basicAuthPassword));
     //    flag = true;
     //}
     //if (useDefaultCredential)
     //{
     //    cache.Add(new Uri(selectedObject.Url), "NTLM", (NetworkCredential)CredentialCache.DefaultCredentials);
     //    flag = true;
     //}
     //if (flag)
     //{
     //    request.Credentials = cache;
     //}
     #endregion
     request.ContentLength = rqt.Length + encoding.GetPreamble().Length;
     StreamWriter writer = new StreamWriter(request.GetRequestStream(), encoding);
     writer.Write(rqt);
     writer.Close();
     try
     {
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         responseXml = GetResponse(response);
         response.Close();
     }
     catch (WebException exception)
     {
         if (exception.Response != null)
         {
             responseXml = GetResponse((HttpWebResponse)exception.Response);
         }
         else
         {
             responseXml = exception.ToString();
         }
     }
     catch (Exception exception2)
     {
         responseXml = exception2.ToString();
     }
     return responseXml;
 }
开发者ID:TaylorLi,项目名称:gettogether,代码行数:63,代码来源:RequestHelper.cs


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