本文整理汇总了C#中System.IO.BufferedStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.ReadByte方法的具体用法?C# BufferedStream.ReadByte怎么用?C# BufferedStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runServer
private static void runServer()
{
//ctrl+pötty auto using
TcpListener listener = new TcpListener(IPAddress.Any,8888);
new Thread(() =>
{
listener.Start();
TcpClient client = listener.AcceptTcpClient();
NetworkStream netStream = client.GetStream();
using (CryptoStream cryptoStream = new CryptoStream(netStream, new SHA512Managed(), CryptoStreamMode.Read))
{
using (GZipStream zipStream = new GZipStream(cryptoStream, CompressionMode.Decompress))
{
using (BufferedStream buffStream = new BufferedStream(zipStream, 64))
{
using (FileStream fileStream = new FileStream("message.txt", FileMode.Create))
{
int data = buffStream.ReadByte();
while (data != -1)
{
fileStream.WriteByte((byte)data);
data = buffStream.ReadByte();
}
}
}
}
}
}).Start();
Thread.Sleep(1000);
}
示例2: 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();
}
}
示例3: 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();
}
示例4: AreIdentical
public static bool AreIdentical(String imagePathA, String imagePathB)
{
if (imagePathA == null) return false;
if (imagePathB == null) return false;
if (File.Exists(imagePathA) == false) return false;
if (File.Exists(imagePathB) == false) return false;
FileInfo fileInfoA = new FileInfo(imagePathA);
FileInfo fileInfoB = new FileInfo(imagePathB);
if (fileInfoA.Length != fileInfoB.Length) return false;
using (FileStream fileStreamA = new FileStream(imagePathA, FileMode.Open))
using (FileStream fileStreamB = new FileStream(imagePathB, FileMode.Open))
using (BufferedStream streamA = new BufferedStream(fileStreamA))
using (BufferedStream streamB = new BufferedStream(fileStreamB))
{
while (true)
{
int byteA = streamA.ReadByte();
int byteB = streamB.ReadByte();
if (byteA != byteB) return false;
if (byteA == -1) break;
}
}
return true;
}
示例5: Compare
public static bool Compare(Stream one, Stream other)
{
BufferedStream oneBuffered = new BufferedStream(one, BufferSize);
BufferedStream otherBuffered = new BufferedStream(other, BufferSize);
// Compare length first, if seekable
if (oneBuffered.CanSeek && otherBuffered.CanSeek)
{
if (oneBuffered.Length != otherBuffered.Length)
return false;
}
while (true)
{
int oneByte = oneBuffered.ReadByte();
int otherByte = otherBuffered.ReadByte();
// Both streams ended at the same time
if (oneByte == -1 && otherByte == -1)
return true;
// Read bytes are not equal
// ore one stream ended before the other
if (oneByte != otherByte)
return false;
}
}
示例6: Build
public void Build(string filename) {
positions = new List<long>();
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
using (BufferedStream bs = new BufferedStream(fs)) {
bool detectFirstLine = true;
int b = 0;
while ((b = bs.ReadByte()) != -1) {
if (b == '\n') {
positions.Add(bs.Position);
detectFirstLine = false;
}
if (detectFirstLine) {
if (bs.Position == 1 && b != 0xEF) {
positions.Add(0);
detectFirstLine = false;
}
if (bs.Position == 2 && b != 0xBB) {
positions.Add(0);
detectFirstLine = false;
}
if (bs.Position == 3 && b != 0xBF) {
positions.Add(0);
detectFirstLine = false;
}
if (bs.Position == 4 && detectFirstLine) {
positions.Add(3);
detectFirstLine = false;
}
}
}
}
}
}
示例7: Main
static void Main()
{
var listener = new HttpListener
{
Prefixes = { "http://+:8080/" }
};
listener.Start();
var buffer = new byte[512 * 1024];
for (int i = 0; i < buffer.Length; i++)
{
buffer[i] = (byte)'a';
}
while (true)
{
try
{
var ctx = listener.GetContext();
var sp = Stopwatch.StartNew();
switch (ctx.Request.HttpMethod)
{
case "GET":
break;
default: // PUT/ POST
// this just consume all sent data to memory
using (var buffered = new BufferedStream(ctx.Request.InputStream))
{
while (buffered.ReadByte() != -1)
{
}
}
break;
}
// one write call
//ctx.Response.OutputStream.Write(buffer, 0, buffer.Length);
// 16 write calls
int size = buffer.Length/16;
var wrote = 0;
for (int i = 0; i < 16; i++)
{
ctx.Response.OutputStream.Write(buffer, wrote, size);
wrote += size;
}
ctx.Response.Close();
Console.WriteLine(DateTime.Now + ": " + sp.ElapsedMilliseconds);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
示例8: Main
public static void Main(string[] args)
{
string filename =
//"compl.bit";
//"01-Lovecraft_s Death.mp3";
//"01-enochian_crescent-tatan.mp3";
//"bad-info-crc.mp3";
//"test-id3v1.mp3";
//"test-id3v2.mp3";
"test-lame.mp3";
Stream mp3Stream =
new BufferedStream(
new FileStream(
filename,
FileMode.Open,
FileAccess.Read));
Mp3Validator validator = new Mp3Validator();
validator.OnValidationFailure += ValidationFailureEventHandler;
validator.Validate(mp3Stream);
Console.WriteLine("Done");
mp3Stream.Seek(0, SeekOrigin.Begin);
Mp3StreamReader reader = new Mp3StreamReader(mp3Stream);
foreach (IMp3StreamRegion region in reader)
{
}
Console.WriteLine("Done");
mp3Stream.Seek(0, SeekOrigin.Begin);
while (-1 != mp3Stream.ReadByte())
{
}
Console.WriteLine("Done");
Console.ReadKey();
}
示例9: ReadBytes
/// <summary>
/// Reads the specified number of bytes from the buffered input stream,
/// starting at offset.
/// </summary>
/// <param name="bis">
/// A <see cref="BufferedStream"/>
/// </param>
/// <param name="length">
/// A <see cref="System.Int32"/>
/// </param>
/// <returns>
/// A <see cref="System.Byte"/>
/// </returns>
private byte[] ReadBytes(BufferedStream bis, int length)
{
byte[] binaryTag = new byte[length];
for (int i = 0; i < length; i++)
{
binaryTag[i] = (byte)bis.ReadByte();
}
return binaryTag;
}
示例10: MyBufferStream
private static void MyBufferStream()
{
MemoryStream ms = new MemoryStream();
BufferedStream bs = new BufferedStream(ms, 4096);
byte [] b=new byte[10];
for (int i = 0; i < 10; i++)
{
bs.WriteByte((byte)i);
}
bs.Position = 0;
bs.Read(b, 0, 9);
for (int i = 0; i < 10; i++)
{
Console.WriteLine("读的值是:{0}", b[i]);
}
Console.WriteLine("值是:{0}", bs.ReadByte());
}
示例11: SendAndReceiveAttempt
public byte[] SendAndReceiveAttempt(byte[] data)
{
TcpClient tcpClient = null;
try
{
if (LocalEndPoint != null)
tcpClient = new TcpClient(LocalEndPoint);
else
tcpClient = new TcpClient();
IAsyncResult result = tcpClient.BeginConnect(RemoteEndPoint.Address, RemoteEndPoint.Port, null, null);
bool success = result.AsyncWaitHandle.WaitOne(Timeout, true);
if (!success || !tcpClient.Connected)
{
tcpClient.Close();
throw new Exception("Could not connect with server." + (RemoteEndPoint == null ? "" : " Server=" + RemoteEndPoint.Address + ":" + RemoteEndPoint.Port));
}
var bs = new BufferedStream(tcpClient.GetStream());
bs.WriteByte((byte) ((data.Length >> 8) & 0xff));
bs.WriteByte((byte) (data.Length & 0xff));
bs.Write(data, 0, data.Length);
bs.Flush();
while (true)
{
int intLength = bs.ReadByte() << 8 | bs.ReadByte();
if (intLength <= 0)
{
tcpClient.Close();
throw new Exception("Connection to nameserver failed." + (RemoteEndPoint == null ? "" : " Server=" + RemoteEndPoint.Address + ":" + RemoteEndPoint.Port));
}
data = new byte[intLength];
bs.Read(data, 0, intLength);
return data;
}
}
finally
{
if (tcpClient != null)
{
tcpClient.Close();
}
}
}
示例12: ReadASCIIListingData
private ArrayList ReadASCIIListingData(string dirname)
{
this.log.Debug("Reading ASCII listing data");
BufferedStream stream = new BufferedStream(this.GetInputStream());
MemoryStream stream2 = new MemoryStream(this.TransferBufferSize * 2);
long byteCount = 0L;
long num2 = 0L;
try
{
int num3;
while (((num3 = stream.ReadByte()) != -1) && !this.cancelTransfer)
{
if ((((num3 >= 0x20) || (num3 == 10)) || (num3 == 13)) && (num3 <= 0x7f))
{
byteCount += 1L;
num2 += 1L;
stream2.WriteByte((byte) num3);
if ((this.transferNotifyListings && (this.BytesTransferred != null)) && (!this.cancelTransfer && (num2 >= this.monitorInterval)))
{
this.BytesTransferred(this, new BytesTransferredEventArgs(dirname, byteCount, 0L));
num2 = 0L;
}
}
}
if (this.transferNotifyListings && (this.BytesTransferred != null))
{
this.BytesTransferred(this, new BytesTransferredEventArgs(dirname, byteCount, 0L));
}
}
finally
{
this.CloseDataSocket(stream);
}
stream2.Seek(0L, SeekOrigin.Begin);
StreamReader input = new StreamReader(stream2, Encoding.ASCII);
ArrayList list = new ArrayList(10);
string str = null;
while ((str = this.ReadLine(input)) != null)
{
list.Add(str);
this.log.Debug("-->" + str);
}
input.Close();
stream2.Close();
return list;
}
示例13: 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();
}
//.........这里部分代码省略.........
示例14: CRC
/// <summary>
/// Get the crc32 value for a Stream, setting the position to to the beginPosition and calculation to the length.
/// The position is set back to the original position when complete.
/// </summary>
/// <param name="st">The stream to perform the crc32 calculation on.</param>
/// <param name="beginPosition">The begin position of the stream to start the calculation.</param>
/// <param name="length">The length you wish to run the calculation on.</param>
/// <returns>The crc32 value.</returns>
public long CRC(Stream st, long beginPosition, long length)
{
ulong ulCRC = poly;
long originalPos = st.Position;
long endPos = beginPosition + length;
byte by;
if (endPos > st.Length)
{
throw new Exception("Out of bounds. beginposition + length is greater than the length of the Stream");
}
try
{
st.Position = beginPosition;
BufferedStream bs = new BufferedStream(st);
for(long i = beginPosition; i < endPos; i++)
{
by = Convert.ToByte(bs.ReadByte());
ulCRC = (ulCRC >> 8) ^ crcLookup[(ulCRC & 0xFF) ^ by];
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
//For now do nothing
}
st.Position = originalPos;
return Convert.ToInt64( ulCRC ^ poly);
}
示例15: ProcessBackendResponses_Ver_3
protected virtual void ProcessBackendResponses_Ver_3( NpgsqlConnector context )
{
NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "ProcessBackendResponses");
BufferedStream stream = new BufferedStream(context.Stream);
NpgsqlMediator mediator = context.Mediator;
// Often used buffers
Byte[] inputBuffer = new Byte[ 4 ];
String Str;
Boolean readyForQuery = false;
while (!readyForQuery)
{
// Check the first Byte of response.
Int32 message = stream.ReadByte();
switch ( message )
{
case NpgsqlMessageTypes_Ver_3.ErrorResponse :
{
NpgsqlError error = new NpgsqlError(context.BackendProtocolVersion);
error.ReadFromStream(stream, context.Encoding);
mediator.Errors.Add(error);
NpgsqlEventLog.LogMsg(resman, "Log_ErrorResponse", LogLevel.Debug, error.Message);
}
// Return imediately if it is in the startup state or connected state as
// there is no more messages to consume.
// Possible error in the NpgsqlStartupState:
// Invalid password.
// Possible error in the NpgsqlConnectedState:
// No pg_hba.conf configured.
if (! mediator.RequireReadyForQuery)
{
return;
}
break;
case NpgsqlMessageTypes_Ver_3.AuthenticationRequest :
NpgsqlEventLog.LogMsg(resman, "Log_ProtocolMessage", LogLevel.Debug, "AuthenticationRequest");
// Eat length
PGUtil.ReadInt32(stream, inputBuffer);
{
Int32 authType = PGUtil.ReadInt32(stream, inputBuffer);
if ( authType == NpgsqlMessageTypes_Ver_3.AuthenticationOk )
{
NpgsqlEventLog.LogMsg(resman, "Log_AuthenticationOK", LogLevel.Debug);
break;
}
if ( authType == NpgsqlMessageTypes_Ver_3.AuthenticationClearTextPassword )
{
NpgsqlEventLog.LogMsg(resman, "Log_AuthenticationClearTextRequest", LogLevel.Debug);
// Send the PasswordPacket.
ChangeState( context, NpgsqlStartupState.Instance );
context.Authenticate(context.Password);
break;
}
if ( authType == NpgsqlMessageTypes_Ver_3.AuthenticationMD5Password )
{
NpgsqlEventLog.LogMsg(resman, "Log_AuthenticationMD5Request", LogLevel.Debug);
// Now do the "MD5-Thing"
// for this the Password has to be:
// 1. md5-hashed with the username as salt
// 2. md5-hashed again with the salt we get from the backend
MD5 md5 = MD5.Create();
// 1.
byte[] passwd = context.Encoding.GetBytes(context.Password);
byte[] saltUserName = context.Encoding.GetBytes(context.UserName);
byte[] crypt_buf = new byte[passwd.Length + saltUserName.Length];
passwd.CopyTo(crypt_buf, 0);
saltUserName.CopyTo(crypt_buf, passwd.Length);
StringBuilder sb = new StringBuilder ();
byte[] hashResult = md5.ComputeHash(crypt_buf);
//.........这里部分代码省略.........