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


C# StreamWriter.WriteBytes方法代码示例

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


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

示例1: Save

		public static void Save(LoginResponse loginResponse)
		{
			byte[] bytes = Encrypt (loginResponse == null ? "" : JsonConvert.SerializeObject(loginResponse));

#if WINDOWS_PHONE
			StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
			var file = local.CreateFile(filename, CreateCollisionOption.ReplaceExisting);
			using (StreamWriter sw = new StreamWriter(file.OpenStreamForWrite())) {
				sw.WriteBytes(bytes);
			}
#else
			string docPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
			string filePath = Path.Combine(docPath, Constants.UserDataFileName);
			File.WriteAllBytes(filePath, bytes);
#endif
		}
开发者ID:marciopmm,项目名称:CNE,代码行数:16,代码来源:UserData.cs

示例2: SendResponse

        /// <summary>
        /// SendResponse()
        ///     Summary:
        ///         Sends success header and soap message.
        ///     Arguments:
        ///         byte[] soapMessage
        /// </summary>
        /// <param name="soapMessage">A byte array containing a soap message.</param>
        public void SendResponse(byte[] soapMessage)
        {
            StreamWriter streamWriter = new StreamWriter(m_httpResponse.OutputStream);
            // Write Header, if message is null write accepted
            if (soapMessage == null)
                m_httpResponse.StatusCode = 202;
            else
                m_httpResponse.StatusCode = 200;

            // Check to see it the hosted service is sending mtom
            WebHeaderCollection webHeaders = m_httpResponse.Headers;
            if (m_mtomHeader != null)
            {
                string responseLine = HttpKnownHeaderNames.ContentType + ": Multipart/Related;boundary=" +
                    m_mtomHeader.boundary +
                    ";type=\"application/xop+xml\";start=\"" +
                    m_mtomHeader.start +
                    "\";start-info=\"application/soap+xml\"";

                System.Ext.Console.Write(responseLine);
                webHeaders.Add(responseLine);

                responseLine = "Server: Microsoft-MF HTTP 1.0";
                System.Ext.Console.Write(responseLine);
                webHeaders.Add(responseLine);

                responseLine = "MIME-Version: 1.0";
                System.Ext.Console.Write(responseLine);
                webHeaders.Add(responseLine);

                responseLine = "Date: " + DateTime.Now.ToString();
                System.Ext.Console.Write(responseLine);
                webHeaders.Add(responseLine);

            }
            else
            {
                m_httpResponse.ContentType = "application/soap+xml; charset=utf-8";
                System.Ext.Console.Write(HttpKnownHeaderNames.ContentType + ": " + m_httpResponse.ContentType);
            }

            // If chunked encoding is enabled write chunked message else write Content-Length
            if (m_chunked)
            {
                string responseLine = "Transfer-Encoding: chunked";
                webHeaders.Add(responseLine);
                System.Ext.Console.Write(responseLine);

                // Chunk message
                int bufferIndex = 0;
                int chunkSize = 0;
                int defaultChunkSize = 0xff;
                byte[] displayBuffer = new byte[defaultChunkSize];
                while (bufferIndex < soapMessage.Length)
                {

                    // Calculate chunk size and write to stream
                    chunkSize = soapMessage.Length - bufferIndex < defaultChunkSize ? soapMessage.Length - bufferIndex : defaultChunkSize;
                    streamWriter.WriteLine(chunkSize.ToString("{0:X}"));
                    System.Ext.Console.Write(chunkSize.ToString("{0:X}"));

                    // Write chunk
                    streamWriter.WriteBytes(soapMessage, bufferIndex, chunkSize);
                    streamWriter.WriteLine();
                    for (int i = 0; i < chunkSize; ++i)
                        displayBuffer[i] = soapMessage[bufferIndex + i];
                    System.Ext.Console.Write(new String(System.Text.Encoding.UTF8.GetChars(displayBuffer), bufferIndex, chunkSize));

                    // Adjust buffer index
                    bufferIndex = bufferIndex + chunkSize;
                }

                // Write 0 length and blank line
                streamWriter.WriteLine("0");
                streamWriter.WriteLine();
                System.Ext.Console.Write("0");
                System.Ext.Console.Write("");

            }
            else
            {
                if (soapMessage == null)
                {
                    m_httpResponse.ContentLength64 = 0;
                }
                else
                {
                    m_httpResponse.ContentLength64 = soapMessage.Length;
                }

                System.Ext.Console.Write("Content Length: " + m_httpResponse.ContentLength64);

//.........这里部分代码省略.........
开发者ID:prabby,项目名称:miniclr,代码行数:101,代码来源:WsHttpServer.cs

示例3: OnProcessOutputMessage


//.........这里部分代码省略.........
                                {
                                    isChunked = true;
                                }

                                headers.Add(name, (string)prop.Value);
                            }
                            else if (container == null || container == "")
                            {
                                if (name == HttpKnownHeaderNames.ContentType)
                                {
                                    listenerResponse.ContentType = (string)prop.Value;
                                    System.Ext.Console.Write(HttpKnownHeaderNames.ContentType + ": " + listenerResponse.ContentType);
                                }
                            }
                        }
                    }

                    // If chunked encoding is enabled write chunked message else write Content-Length
                    if (isChunked)
                    {
                        // Chunk message
                        int bufferIndex = 0;
                        int chunkSize = 0;
                        int defaultChunkSize = 0xff;
#if DEBUG
                    byte[] displayBuffer = new byte[defaultChunkSize];
#endif
                        while (bufferIndex < message.Length)
                        {

                            // Calculate chunk size and write to stream
                            chunkSize = message.Length - bufferIndex < defaultChunkSize ? message.Length - bufferIndex : defaultChunkSize;
                            streamWriter.WriteLine(chunkSize.ToString("{0:X}"));
                            System.Ext.Console.Write(chunkSize.ToString("{0:X}"));

                            // Write chunk
                            streamWriter.WriteBytes(message, bufferIndex, chunkSize);
                            streamWriter.WriteLine();
#if DEBUG
                            Array.Copy(message, bufferIndex, displayBuffer, 0, chunkSize);
                            System.Ext.Console.Write(displayBuffer, bufferIndex, chunkSize);
#endif

                            // Adjust buffer index
                            bufferIndex = bufferIndex + chunkSize;
                        }

                        // Write 0 length and blank line
                        streamWriter.WriteLine("0");
                        streamWriter.WriteLine();
                        System.Ext.Console.Write("0");
                        System.Ext.Console.Write("");

                    }
                    else
                    {
                        if (message == null)
                        {
                            listenerResponse.ContentLength64 = 0;
                        }
                        else
                        {
                            listenerResponse.ContentLength64 = message.Length;
                        }

                        System.Ext.Console.Write("Content Length: " + listenerResponse.ContentLength64);

                        // If an empty message is returned (i.e. oneway request response) don't send
                        if (message != null && message.Length > 0)
                        {
                            System.Ext.Console.Write(message);

                            // Write soap message
                            streamWriter.WriteBytes(message, 0, message.Length);
                        }
                    }

                    // Flush the stream and return
                    streamWriter.Flush();

                }
                catch
                {
                    return ChainResult.Abort;
                }
                finally
                {
                    if (m_persistConn)
                    {
                        listenerResponse.Detach();
                    }
                    else
                    {
                        listenerContext.Close( ctx.CloseTimeout.Seconds );
                        ctx.ContextObject = null;
                    }
                }
            }
            return ChainResult.Handled;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:101,代码来源:HttpTransportBindingElement.cs


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