本文整理汇总了C#中System.IO.BufferedStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.WriteByte方法的具体用法?C# BufferedStream.WriteByte怎么用?C# BufferedStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.WriteByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public void Save(Map mapToSave, string path) {
if (mapToSave == null) throw new ArgumentNullException("mapToSave");
if (path == null) throw new ArgumentNullException("path");
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
// Write metadata/config file
using (StreamWriter sw = File.CreateText(Path.Combine(path, ConfigFileName))) {
sw.WriteLine("; Converted by {0} on {1}", Updater.UserAgent, DateTime.Now.ToCompactString());
sw.WriteLine("Size_X = {0}", mapToSave.Width);
sw.WriteLine("Size_Y = {0}", mapToSave.Length);
sw.WriteLine("Size_Z = {0}", mapToSave.Height);
sw.WriteLine("Spawn_X = {0}", FromPositionCoord(mapToSave.Spawn.X));
sw.WriteLine("Spawn_Y = {0}", FromPositionCoord(mapToSave.Spawn.Y));
sw.WriteLine("Spawn_Z = {0}", FromPositionCoord(mapToSave.Spawn.Z));
sw.WriteLine("Spawn_Rot = {0}", FromPositionAngle(mapToSave.Spawn.R));
sw.WriteLine("Spawn_Look = {0}", FromPositionAngle(mapToSave.Spawn.L));
}
// Write compressed block data
using (FileStream fs = File.Create(Path.Combine(path, DataFileName))) {
using (GZipStream gs = new GZipStream(fs, CompressionMode.Compress)) {
// Buffering necessary to avoid overhead of writing byte-at-a-time
using (BufferedStream bs = new BufferedStream(gs, WriteBufferSize)) {
for (int i = 0; i < mapToSave.Volume; i++) {
bs.WriteByte(mapToSave.Blocks[i]);
bs.WriteByte(0);
bs.WriteByte(0xFF);
bs.WriteByte(0xFF);
}
}
}
}
}
示例2: Compress
public static void Compress(Stream instream, Stream outstream, int blockSize)
{
BufferedStream inStream = new BufferedStream(outstream);
inStream.WriteByte(0x42);
inStream.WriteByte(90);
BufferedStream stream2 = new BufferedStream(instream);
int num = stream2.ReadByte();
BZip2OutputStream stream3 = new BZip2OutputStream(inStream);
while (num != -1)
{
stream3.WriteByte((byte) num);
num = stream2.ReadByte();
}
stream2.Close();
stream3.Close();
}
示例3: Main
static void Main(string[] args)
{
FileStream fs = new FileStream("Hoo.txt",
FileMode.Create, FileAccess.ReadWrite);
BufferedStream bs = new BufferedStream(fs);
Console.WriteLine("Length: {0}\tPosition: {1}", bs.Length, bs.Position);
for (int i = 0; i < 64; i++)
{
bs.WriteByte((byte)i);
}
Console.WriteLine("Length: {0}\tPosition: {1}", bs.Length, bs.Position);
Console.WriteLine("\nContents:");
byte[] ba = new byte[bs.Length];
bs.Position = 0;
bs.Read(ba, 0, (int)bs.Length);
foreach (byte b in ba)
{
Console.Write("{0, -3}", b);
}
string s = "Foo";
for (int i = 0; i < 3; i++)
{
bs.WriteByte((byte)s[i]);
}
Console.WriteLine("Length: {0}\tPosition: {1}", bs.Length, bs.Position);
for (int i = 0; i < (256-67) + 1; i++)
{
bs.WriteByte((byte)i);
}
Console.WriteLine("Length: {0}\tPosition: {1}", bs.Length, bs.Position);
bs.Close();
Console.ReadLine();
}
示例4: Decompress
public static void Decompress(Stream instream, Stream outstream)
{
BufferedStream stream = new BufferedStream(outstream);
BufferedStream zStream = new BufferedStream(instream);
if ((zStream.ReadByte() == 0x42) && (zStream.ReadByte() == 90))
{
BZip2InputStream stream3 = new BZip2InputStream(zStream);
for (int i = stream3.ReadByte(); i != -1; i = stream3.ReadByte())
{
stream.WriteByte((byte) i);
}
stream.Flush();
}
}
示例5: Buffered_Stream_buffers_and_forwards_writes_and_flushes_before_close
public void Buffered_Stream_buffers_and_forwards_writes_and_flushes_before_close()
{
var mock = new Mock<Stream>();
Stream stream = mock.Object;
mock.SetupGet(d => d.CanRead).Returns(true);
mock.SetupGet(d => d.CanWrite).Returns(true);
BufferedStream bs = new BufferedStream(stream);
bs.WriteByte((byte)'a');
bs.Flush();
bs.Close();
mock.Verify(d => d.Write(It.Is<byte[]>(array => array.Length > 0 && array[0] == 'a'), 0, 1));
mock.Verify(d => d.Flush());
mock.Verify(d => d.Close());
}
示例6: runClient
private static void runClient(string message)
{
TcpClient client = new TcpClient("localhost", 8888);
NetworkStream netStream = client.GetStream();
using (CryptoStream cryptoStream = new CryptoStream(netStream, new SHA512Managed(), CryptoStreamMode.Write))
{
using (GZipStream zipStream = new GZipStream(cryptoStream, CompressionMode.Compress))
{
using (BufferedStream buffStream = new BufferedStream(zipStream, 64))
{
foreach (var b in Encoding.Unicode.GetBytes(message))
{
buffStream.WriteByte(b);
}
}
}
}
}
示例7: TcpRequest
private Response TcpRequest(Request request)
{
//System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
//sw.Start();
for (var intAttempts = 0; intAttempts < _mRetries; intAttempts++)
{
for (var intDnsServer = 0; intDnsServer < _mDnsServers.Count; intDnsServer++)
{
//var tcpClient = new TcpClient(AddressFamily.InterNetworkV6) {ReceiveTimeout = _mTimeout*1000};
var tcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//tcpClient.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
try
{
Verbose(";; Connecting to nameserver {0}", _mDnsServers[intDnsServer].Address);
var result = tcpClient.BeginConnect(_mDnsServers[intDnsServer].Address, _mDnsServers[intDnsServer].Port,
null, null);
var success = result.AsyncWaitHandle.WaitOne(_mTimeout*1000, true);
if (!success || !tcpClient.Connected)
{
tcpClient.Close();
Verbose(string.Format(";; Connection to nameserver {0} failed", _mDnsServers[intDnsServer].Address));
continue;
}
var bs = new BufferedStream(new NetworkStream(tcpClient));
var data = request.Data;
bs.WriteByte((byte) ((data.Length >> 8) & 0xff));
bs.WriteByte((byte) (data.Length & 0xff));
bs.Write(data, 0, data.Length);
bs.Flush();
var transferResponse = new Response();
var intSoa = 0;
var intMessageSize = 0;
//Debug.WriteLine("Sending "+ (request.Length+2) + " bytes in "+ sw.ElapsedMilliseconds+" mS");
while (true)
{
var intLength = bs.ReadByte() << 8 | bs.ReadByte();
if (intLength <= 0)
{
tcpClient.Close();
Verbose(string.Format(";; Connection to nameserver {0} failed", (intDnsServer + 1)));
throw new SocketException(); // next try
}
intMessageSize += intLength;
data = new byte[intLength];
bs.Read(data, 0, intLength);
var response = new Response(_mDnsServers[intDnsServer], data);
//Debug.WriteLine("Received "+ (intLength+2)+" bytes in "+sw.ElapsedMilliseconds +" mS");
if (response.Header.RCODE != RCode.NoError)
return response;
if (response.Questions[0].QType != QType.AXFR)
{
AddToCache(response);
return response;
}
// Zone transfer!!
if (transferResponse.Questions.Count == 0)
transferResponse.Questions.AddRange(response.Questions);
transferResponse.Answers.AddRange(response.Answers);
transferResponse.Authorities.AddRange(response.Authorities);
transferResponse.Additionals.AddRange(response.Additionals);
if (response.Answers[0].Type == Type.SOA)
intSoa++;
if (intSoa != 2) continue;
transferResponse.Header.QDCOUNT = (ushort) transferResponse.Questions.Count;
transferResponse.Header.ANCOUNT = (ushort) transferResponse.Answers.Count;
transferResponse.Header.NSCOUNT = (ushort) transferResponse.Authorities.Count;
transferResponse.Header.ARCOUNT = (ushort) transferResponse.Additionals.Count;
transferResponse.MessageSize = intMessageSize;
return transferResponse;
}
} // try
catch (SocketException)
{
continue; // next try
}
finally
{
_mUnique++;
// close the socket
tcpClient.Close();
}
//.........这里部分代码省略.........
示例8: Flush
public void Flush ()
{
BufferedStream stream = new BufferedStream (mem);
stream.WriteByte (1);
stream.WriteByte (2);
byte [] bytes = mem.GetBuffer ();
AssertEquals ("test#01", 0, bytes.Length);
stream.Flush ();
bytes = mem.GetBuffer ();
AssertEquals ("test#02", 256, bytes.Length);
AssertEquals ("test#03", 1, bytes [0]);
AssertEquals ("test#04", 2, bytes [1]);
mem.Close ();
mem = new MemoryStream ();
bytes = new byte [] {0, 1, 2, 3, 4, 5};
stream = new BufferedStream (mem);
stream.Write (bytes, 0, 2);
AssertEquals ("test#05", 2, stream.Length);
bytes = mem.GetBuffer ();
AssertEquals ("test#06", 256, bytes.Length);
AssertEquals ("test#07", 0, bytes [0]);
AssertEquals ("test#08", 1, bytes [1]);
stream.Write (bytes, 0, 2);
bytes = mem.GetBuffer ();
AssertEquals ("test#09", 0, bytes [0]);
AssertEquals ("test#10", 1, bytes [1]);
AssertEquals ("test#11", 0, bytes [2]);
AssertEquals ("test#12", 0, bytes [3]);
stream.Flush ();
bytes = mem.GetBuffer ();
AssertEquals ("test#13", 0, bytes [2]);
AssertEquals ("test#14", 1, bytes [3]);
}
示例9: Open
public void Open()
{
try
{
mySerialPort.Open();
baseStream = new BufferedStream(mySerialPort.BaseStream, 1024);
Encoding enc = new ASCIIEncoding();
writer = new StreamWriter(baseStream, enc);
reader = new BinaryReader(baseStream);
baseStream.WriteByte((byte)0x19); //ctrl-Y --> perform reset of Patriot
baseStream.WriteByte((byte)0x0D);
baseStream.WriteByte((byte)0x0A);
baseStream.Flush();
// Thread.Sleep(12000); //wait for completion
Head h = frames[0];
frames.Remove(h);
h = IssueCommand("F1"); //set binary mode
if (h != null && h.ErrorIndicator != (byte)0)
throw new Exception("Unable to set binary mode: " + h.ExtractErrorMessage());
h = IssueCommand("U1"); //set metric scale (cm)
if (h != null && h.ErrorIndicator != (byte)0)
throw new Exception("Unable to set metric units: " + h.ExtractErrorMessage());
h = IssueCommand("O*,2"); //position data only
reader.ReadBytes(h.ResponseSize); //skip returned
h = IssueCommand("L1,1"); //set button on stylus to work
if (h != null && h.ErrorIndicator != (byte)0)
throw new Exception("Unable to set stylus button mode: " + h.ExtractErrorMessage());
}
catch (Exception e)
{
throw new Exception("Patriot.Open: " + e.Message);
}
}
示例10: Flush
public void Flush ()
{
BufferedStream stream = new BufferedStream (mem);
stream.WriteByte (1);
stream.WriteByte (2);
byte [] bytes = mem.GetBuffer ();
Assert.AreEqual (0, bytes.Length, "test#01");
stream.Flush ();
bytes = mem.GetBuffer ();
Assert.AreEqual (256, bytes.Length, "test#02");
Assert.AreEqual (1, bytes [0], "test#03");
Assert.AreEqual (2, bytes [1], "test#04");
mem.Close ();
mem = new MemoryStream ();
bytes = new byte [] {0, 1, 2, 3, 4, 5};
stream = new BufferedStream (mem);
stream.Write (bytes, 0, 2);
Assert.AreEqual (2, stream.Length, "test#05");
bytes = mem.GetBuffer ();
Assert.AreEqual (256, bytes.Length, "test#06");
Assert.AreEqual (0, bytes [0], "test#07");
Assert.AreEqual (1, bytes [1], "test#08");
stream.Write (bytes, 0, 2);
bytes = mem.GetBuffer ();
Assert.AreEqual (0, bytes [0], "test#09");
Assert.AreEqual (1, bytes [1], "test#10");
Assert.AreEqual (0, bytes [2], "test#11");
Assert.AreEqual (0, bytes [3], "test#12");
stream.Flush ();
bytes = mem.GetBuffer ();
Assert.AreEqual (0, bytes [2], "test#13");
Assert.AreEqual (1, bytes [3], "test#14");
}
示例11: Close7
public void Close7 ()
{
BufferedStream stream = new BufferedStream (mem);
mem.Close ();
stream.WriteByte (1);
}
示例12: WriteEntry
public void WriteEntry(TarEntry entry, bool recurse)
{
string path = null;
string file = entry.File;
if ((file == null) || (file.Length == 0))
{
entry = TarEntry.CreateTarEntry(entry.Name);
}
else
{
string name = entry.Name;
entry = TarEntry.CreateEntryFromFile(file);
entry.Name = name;
}
if (this.verbose)
{
this.OnProgressMessageEvent(entry.Name);
}
if ((this.asciiTranslate && !entry.IsDirectory) && !this.IsBinary(file))
{
path = Path.GetTempFileName();
StreamReader reader = File.OpenText(file);
Stream stream = new BufferedStream(File.Create(path));
while (true)
{
string s = reader.ReadLine();
if (s == null)
{
break;
}
byte[] bytes = Encoding.ASCII.GetBytes(s);
stream.Write(bytes, 0, bytes.Length);
stream.WriteByte(10);
}
reader.Close();
stream.Flush();
stream.Close();
entry.Size = new FileInfo(path).Length;
file = path;
}
string str5 = null;
if ((this.rootPath != null) && entry.Name.StartsWith(this.rootPath))
{
str5 = entry.Name.Substring(this.rootPath.Length + 1);
}
if (this.pathPrefix != null)
{
str5 = (str5 == null) ? (this.pathPrefix + "/" + entry.Name) : (this.pathPrefix + "/" + str5);
}
if (str5 != null)
{
entry.Name = str5;
}
this.tarOut.PutNextEntry(entry);
if (entry.IsDirectory)
{
if (recurse)
{
TarEntry[] directoryEntries = entry.GetDirectoryEntries();
for (int i = 0; i < directoryEntries.Length; i++)
{
this.WriteEntry(directoryEntries[i], recurse);
}
}
}
else
{
Stream stream2 = File.OpenRead(file);
int num2 = 0;
byte[] buffer = new byte[0x8000];
while (true)
{
int count = stream2.Read(buffer, 0, buffer.Length);
if (count <= 0)
{
break;
}
this.tarOut.Write(buffer, 0, count);
num2 += count;
}
Console.WriteLine("written " + num2 + " bytes");
stream2.Close();
if ((path != null) && (path.Length > 0))
{
File.Delete(path);
}
this.tarOut.CloseEntry();
}
}
示例13: WriteByte_CantWrite
public void WriteByte_CantWrite ()
{
ReadOnlyStream ro = new ReadOnlyStream ();
BufferedStream stream = new BufferedStream (ro);
stream.WriteByte (0);
}
示例14: WriteToTemp
public void WriteToTemp(byte[] bytes, String filename, bool createNew = false)
{
if(createNew && System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
using (FileStream fs = new FileStream(filename, FileMode.Append, FileAccess.Write ))
{
using (BufferedStream bs = new BufferedStream(fs))
{
foreach (byte b in bytes)
{
bs.WriteByte(b);
}
}
}
}
示例15: HandleRequest
//throws ServletException, IOException
private int HandleRequest(HttpRequest request,
HttpResponse response,
HmuxChannel hmuxChannel,
BufferedStream rs,
BufferedStream ws,
byte[] buf, int length, bool isComplete,
bool allowBusy)
{
String traceId = hmuxChannel.GetTraceId();
StringBuilder cb = new StringBuilder();
bool isDebugFiner = true;
String uri = Uri.EscapeUriString(request.RawUrl);
Trace.TraceInformation("Hmux[{0}] >>U:uri {1}->{2}", traceId, request.RawUrl, uri);
WriteRequestString(ws, HmuxChannel.HMUX_URI, uri, traceId);
Trace.TraceInformation("Hmux[{0}] >>m:method {1}", traceId, request.HttpMethod);
WriteRequestString(ws, HmuxChannel.HMUX_METHOD, request.HttpMethod, traceId);
Trace.TraceInformation("Hmux[{0}] >>u:server type {1}", traceId, "IIS");
WriteRequestString(ws, HmuxChannel.CSE_SERVER_TYPE, "IIS", traceId);
NameValueCollection serverVariables = request.ServerVariables;
String serverPort = serverVariables.Get("SERVER_PORT");
String serverName = serverVariables.Get("SERVER_NAME") + ':' + serverPort;
Trace.TraceInformation("Hmux[{0}] >>v:server name {1}", traceId, serverName);
WriteRequestString(ws, HmuxChannel.HMUX_SERVER_NAME, serverName, traceId);
Trace.TraceInformation("Hmux[{0}] >>g:server port {1}", traceId, serverPort);
WriteRequestString(ws, HmuxChannel.CSE_SERVER_PORT, serverPort, traceId);
String remoteAddr = serverVariables.Get("REMOTE_ADDR");
Trace.TraceInformation("Hmux[{0}] >>i:remote address {1}", traceId, remoteAddr);
WriteRequestString(ws, HmuxChannel.CSE_REMOTE_ADDR, remoteAddr, traceId);
String remoteHost = serverVariables.Get("REMOTE_HOST");
if (remoteHost == null)
remoteHost = remoteAddr;
Trace.TraceInformation("Hmux[{0}] >>h:remote host {1}", traceId, remoteHost);
WriteRequestString(ws, HmuxChannel.CSE_REMOTE_HOST, remoteHost, traceId);
String protocol = serverVariables.Get("HTTP_VERSION");
Trace.TraceInformation("Hmux[{0}] >>c:protocol {1}", traceId, protocol);
WriteRequestString(ws, HmuxChannel.CSE_PROTOCOL, protocol, traceId);
HttpClientCertificate clientCertificate = request.ClientCertificate;
if (request.IsSecureConnection) {
Trace.TraceInformation("Hmux[{0}] >>r:secure", traceId);
WriteRequestString(ws, HmuxChannel.CSE_IS_SECURE, "", traceId);
WriteRequestHeader(ws, "HTTPS", "on", traceId);
WriteRequestHeader(ws, "SSL_SECRETKEYSIZE", clientCertificate.KeySize.ToString(), traceId);
}
if (clientCertificate.IsPresent) {
Trace.TraceInformation("Hmux[{0}] >>r:certificate ({1})", traceId, clientCertificate.Certificate.Length);
ws.WriteByte(HmuxChannel.CSE_CLIENT_CERT);
WriteHmuxLength(ws, clientCertificate.Certificate.Length);
ws.Write(clientCertificate.Certificate, 0, clientCertificate.Certificate.Length);
}
NameValueCollection headers = request.Headers;
foreach (String key in headers.AllKeys) {
if ("Connection".Equals(key, StringComparison.OrdinalIgnoreCase))
continue;
String[] values = headers.GetValues(key);
foreach (String value in values) {
WriteRequestHeader(ws, key, value, traceId);
}
}
Stream requestStream = request.InputStream;
Stream responseStream = null;
bool hasHeader = true;
bool hasStatus = false;
if (length > 0) {
Trace.TraceInformation("Hmux[{0}] >>D: data ({1})", traceId, length);
WriteRequestData(ws, HmuxChannel.HMUX_DATA, buf, length, traceId);
}
int len;
int code;
while (!isComplete && (len = requestStream.Read(buf, 0, buf.Length)) > 0) {
Trace.TraceInformation("Hmux[{0}] >>D: data ({1})", traceId, length);
WriteRequestData(ws, HmuxChannel.HMUX_DATA, buf, len, traceId);
Trace.TraceInformation("Hmux[{0}] >>Y: (yield)", traceId);
ws.WriteByte(HmuxChannel.HMUX_YIELD);
ws.Flush();
//.........这里部分代码省略.........