本文整理汇总了C#中System.Byte.ToUTF8String方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.ToUTF8String方法的具体用法?C# Byte.ToUTF8String怎么用?C# Byte.ToUTF8String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte
的用法示例。
在下文中一共展示了Byte.ToUTF8String方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadTEBlockLength
public static Int32 ReadTEBlockLength(this Byte[] TEContent, Int32 Position, Int32 TELength)
{
var TEBlockLength = new Byte[TELength];
Array.Copy(TEContent, Position, TEBlockLength, 0, TELength);
return Convert.ToInt32(TEBlockLength.ToUTF8String(), // Hex-String
16);
}
示例2: Execute
//.........这里部分代码省略.........
MemoryCopy[pos - 3] == 0x0d)
{
Array.Resize(ref HTTPHeaderBytes, pos - 3);
Array.Copy(MemoryCopy, 0, HTTPHeaderBytes, 0, pos - 3);
break;
}
}
//if (HTTPHeaderBytes.Length > 0)
// Debug.WriteLine("[" + DateTime.Now + "] End of (" + TCPClient.Client.LocalEndPoint.ToString() + " -> " + RemoteSocket.ToString() + ") HTTP header at " + HTTPHeaderBytes.Length + " bytes (" + sw.ElapsedMilliseconds + "ms)!");
}
#endregion
Thread.Sleep(1);
}
// Note: Delayed parts of the HTTP body may not be read into the buffer
// => Must be read later!
while (TCPStream.DataAvailable ||
((sw.ElapsedMilliseconds < HTTPStream.ReadTimeout) && HTTPHeaderBytes.Length == 0));
//Debug.WriteLine("[" + DateTime.Now + "] Finally read " + _MemoryStream.Length + " bytes of HTTP client (" + TCPClient.Client.LocalEndPoint.ToString() + " -> " + RemoteSocket.ToString() + ") data (" + sw.ElapsedMilliseconds + "ms)!");
#endregion
#region Copy HTTP header data and create HTTP response
if (HTTPHeaderBytes.Length == 0)
throw new ApplicationException(DateTime.Now + " Could not find the end of the HTTP protocol header!");
Response = HTTPResponse.Parse(HTTPHeaderBytes.ToUTF8String(),
Request);
#endregion
#region Read 'Content-Length' bytes...
// Copy only the number of bytes given within
// the HTTP header element 'Content-Length'!
if (Response.ContentLength.HasValue && Response.ContentLength.Value > 0)
{
_MemoryStream.Seek(HTTPHeaderBytes.Length + 4, SeekOrigin.Begin);
var _Read = _MemoryStream.Read(_Buffer, 0, _Buffer.Length);
var _StillToRead = (Int32)Response.ContentLength.Value - _Read;
Response.HTTPBodyStream.Write(_Buffer, 0, _Read);
var _CurrentBufferSize = 0;
do
{
while (TCPStream.DataAvailable && _StillToRead > 0)
{
_CurrentBufferSize = Math.Min(_Buffer.Length, (Int32)_StillToRead);
_Read = HTTPStream.Read(_Buffer, 0, _CurrentBufferSize);
Response.HTTPBodyStream.Write(_Buffer, 0, _Read);
_StillToRead -= _Read;
}
if (_StillToRead <= 0)
break;
Thread.Sleep(1);
示例3: Execute
//.........这里部分代码省略.........
case 0 : if (_int == 0x0d) state = 1; else state = 0; break;
case 1 : if (_int == 0x0a) state = 2; else state = 0; break;
case 2 : if (_int == 0x0d) state = 3; else state = 0; break;
case 3 : if (_int == 0x0a) _EndOfHTTPHeader = true; else state = 0; break;
default : state = 0; break;
}
}
if (_EndOfHTTPHeader)
break;
}
#endregion
}
if (_EndOfHTTPHeader == false)
throw new ApplicationException("Could not find the end of the HTTP protocol header!");
EndOfHeaderPosition = _MemoryStream.Position - 3;
#endregion
#region Copy HTTP header data
var HeaderBytes = new Byte[EndOfHeaderPosition - 1];
_MemoryStream.Seek(0, SeekOrigin.Begin);
_MemoryStream.Read(HeaderBytes, 0, HeaderBytes.Length);
#endregion
var _HTTPResponse = new HTTPResponse(HeaderBytes.ToUTF8String());
#region Read 'Content-Length' bytes...
// Copy only the number of bytes given within
// the HTTP header element 'Content-Length'!
if (_HTTPResponse.ContentLength.HasValue)
{
_MemoryStream.Seek(4, SeekOrigin.Current);
var _Read = _MemoryStream.Read(_Buffer, 0, _Buffer.Length);
var _StillToRead = (Int32) _HTTPResponse.ContentLength.Value - _Read;
_HTTPResponse.ContentStream.Write(_Buffer, 0, _Read);
var _CurrentBufferSize = 0;
var Retries = 0;
while (Retries < 10)
{
while (TCPStream.DataAvailable)
{
_CurrentBufferSize = Math.Min(_Buffer.Length, (Int32) _StillToRead);
_Read = TCPStream.Read(_Buffer, 0, _CurrentBufferSize);
_HTTPResponse.ContentStream.Write(_Buffer, 0, _Read);
_StillToRead -= _Read;
Retries = 0;
}
if (_StillToRead <= 0)
break;
Thread.Sleep(10);