本文整理汇总了C#中System.IO.BinaryWriter.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.WriteLine方法的具体用法?C# BinaryWriter.WriteLine怎么用?C# BinaryWriter.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter.WriteLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteLine
public static void WriteLine(this Stream stream, string line)
{
var writer = new BinaryWriter(stream, Encoding.UTF8, true);
writer.WriteLine(line);
}
示例2: CopyHttpStream
private static bool CopyHttpStream(Stream fromStream, Stream toStream, string firstLine = "", string sslTunnelDomain="")
{
bool keepAlive = false;
var encoding = Encoding.UTF8;
string method;
string version;
string url;
using (var fromStreamReader = new BinaryReader(fromStream, encoding, true))
using (var toStreamWriter = new BinaryWriter(toStream, encoding, true))
{
if (String.IsNullOrEmpty(firstLine))
firstLine = fromStream.ReadLine();
if (!String.IsNullOrEmpty(sslTunnelDomain))
{
//modify the path in the http request to include the domain
ParseHttpCommand(firstLine, out method, out url, out version);
//modify the forward address so it has complete URL
firstLine = method + ' ' + "https://" + sslTunnelDomain + url + ' ' + version;
firstLine += "\r\n";
firstLine += "X-Forward-Secure: true";
}
LogMessage(string.Format(firstLine));
toStream.WriteLine(firstLine);
toStream.Flush();
string line;
int contentLength = 0;
bool chunked = false;
//copy the headers
while (!String.IsNullOrEmpty(line = fromStreamReader.ReadLine()))
{
if (line.StartsWith("Content-Length:", true, CultureInfo.CurrentCulture))
contentLength = int.Parse(line.Replace("Content-Length:", ""));
if (line.StartsWith("Transfer-Encoding: chunked", true, CultureInfo.CurrentCulture))
chunked = true;
if (line.StartsWith("Proxy-Connection: Keep-Alive", true, CultureInfo.CurrentCulture))
keepAlive = true;
toStreamWriter.WriteLine(line);
}
toStreamWriter.WriteLine();
if (contentLength > 0)
toStreamWriter.Write(fromStreamReader.ReadBytes(contentLength));
if(chunked)
{
while (!String.IsNullOrEmpty(line = fromStreamReader.ReadLine()))
{
contentLength = int.Parse(line, System.Globalization.NumberStyles.HexNumber);
toStreamWriter.Write(fromStreamReader.ReadBytes(contentLength));
fromStreamReader.ReadLine();
}
}
toStreamWriter.Flush();
}
return keepAlive;
}
示例3: Save
public virtual void Save(string basename)
{
using (var output = new BinaryWriter(File.Create(basename))) {
this.InputTokenizer.Save(output);
}
using (var output = File.CreateText(basename + ".names")) {
foreach (var filename in this.FileNames) {
output.WriteLine (filename);
}
}
using (var output = new BinaryWriter(File.Create(basename + ".seq"))) {
GenericIO<Sequence>.Save (output, this.Seq);
}
using (var output = new BinaryWriter(File.Create(basename + ".voc"))) {
output.Write ((int)this.Voc.Count);
foreach (var w in this.Voc) {
output.Write (w);
}
}
}
示例4: GetSslTunnelStream
private static Stream GetSslTunnelStream(Stream stream, string version = "HTTP/1.1")
{
SslStream sslStream = null;
//Browser wants to create a secure tunnel
//read and ignore headers
while (!String.IsNullOrEmpty(stream.ReadLine())) ;
//tell the client that a tunnel has been established
LogMessage(string.Format("Doing CONNECT"));
var connectStreamWriter = new BinaryWriter(stream);
connectStreamWriter.WriteLine(version + " 200 Connection established");
connectStreamWriter.WriteLine(String.Format("Timestamp: {0}", DateTime.Now.ToString()));
connectStreamWriter.WriteLine("Proxy-agent: buskerproxy");
connectStreamWriter.WriteLine();
connectStreamWriter.Flush();
//open a decrypting stream
sslStream = new SslStream(stream, false);
try
{
sslStream.AuthenticateAsServer(_certificate, false, SslProtocols.Tls | SslProtocols.Ssl3 | SslProtocols.Ssl2, true);
}
catch (Exception ex)
{
stream.Close();
sslStream.Close();
return null;
}
return sslStream;
}