本文整理汇总了C#中Stream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadByte方法的具体用法?C# Stream.ReadByte怎么用?C# Stream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadByteAfterWhitespace
protected int ReadByteAfterWhitespace(Stream s)
{
int buff = s.ReadByte();
while (buff >= 0 && IsWhitespace(buff))
buff = s.ReadByte();
return buff;
}
示例2: ReadBoolean
public static bool ReadBoolean(Stream stream)
{
if (stream == null) {
throw new ArgumentNullException("stream");
}
int b = stream.ReadByte();
if (b == 0xf4) {
return false;
}
if (b == 0xf5) {
return true;
}
while ((b >> 5) == 6) {
// Skip tags until a tag character is no longer read
if (b == 0xd8) {
stream.ReadByte();
} else if (b == 0xd9) {
stream.Position += 2;
} else if (b == 0xda) {
stream.Position += 4;
} else if (b == 0xdb) {
stream.Position += 8;
} else if (b > 0xdb) {
throw new IOException("Not a boolean");
}
b = stream.ReadByte();
}
if (b == 0xf4) {
return false;
}
if (b == 0xf5) {
return true;
}
throw new IOException("Not a boolean");
}
示例3: Decode
public override ScalarValue Decode(Stream inStream)
{
long value = 0;
uint byt;
try
{
byt = (uint) inStream.ReadByte();
if ((byt & 0x40) > 0)
{
value = - 1;
}
value = (value << 7) | (byt & 0x7f);
while ((byt & StopBit) == 0)
{
byt = (uint) inStream.ReadByte();
value = (value << 7) | (byt & 0x7f);
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
return CreateValue(value);
}
示例4: CanReadFrom
/// <summary>
/// Determines whether this instance can read palette from data the specified stream.
/// </summary>
/// <param name="stream">The stream.</param>
/// <returns><c>true</c> if this instance can read palette data from the specified stream; otherwise, <c>false</c>.</returns>
public override bool CanReadFrom(Stream stream)
{
bool result;
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}
try
{
int version;
// read the version, which occupies two bytes
// first byte is 0, the second 1 so I assume this is added to make 1
//version = this.ReadShort(stream);
version = stream.ReadByte() + stream.ReadByte();
result = (version == 1 || version == 2);
}
catch
{
result = false;
}
return result;
}
开发者ID:FrankGITDeveloper,项目名称:Landsknecht_GreenScreen,代码行数:32,代码来源:AdobePhotoShopColorSwatchSerializer.cs
示例5: DerLengthDecode
public static unsafe long DerLengthDecode(Stream bt)
{
long length = 0;
byte b;
b = (byte) bt.ReadByte();
if ((b & 0x80)==0)
{
length = b;
}
else
{
long lengthBytes = b & 0x7f;
if (lengthBytes == 0)
{
throw new Exception("Indefinite length.");
}
length = 0;
while (lengthBytes-- > 0)
{
if ((length >> (8*(sizeof(long)-1))) > 0)
throw new Exception("Length overflow.");
b = (byte) bt.ReadByte();
length = (length << 8) | b;
}
}
return length;
}
示例6: CompletedResponse
public CompletedResponse(Stream stream, ByteBuffer buffer)
{
int bRead;
buffer.Reset();
for (bRead = stream.ReadByte(); bRead > 0 && bRead != ' '; bRead = stream.ReadByte())
buffer.Add((byte)bRead);
if (bRead == ' ' && buffer.GetPosition() == INSERT.Length && buffer.AreSame(INSERT))
{
long lioid = 0;
for (bRead = stream.ReadByte(); bRead > 0 && bRead != ' '; bRead = stream.ReadByte())
lioid = (lioid << 3) + (lioid << 1) + bRead - 48;
if (bRead == ' ') LastInsertedOID = lioid;
}
while (bRead > 0)
{
buffer.Reset();
for (bRead = stream.ReadByte(); bRead > 0 && bRead != ' '; bRead = stream.ReadByte())
buffer.Add((byte)bRead);
}
if (bRead == -1)
{
throw new IOException();
}
RowsAffected = buffer.TryGetInt();
}
示例7: OpenStream
public static StreamReader OpenStream(Stream fs, Encoding defaultEncoding)
{
if (fs == null)
throw new ArgumentNullException("fs");
if (fs.Length >= 2) {
// the autodetection of StreamReader is not capable of detecting the difference
// between ISO-8859-1 and UTF-8 without BOM.
int firstByte = fs.ReadByte();
int secondByte = fs.ReadByte();
switch ((firstByte << 8) | secondByte) {
case 0x0000: // either UTF-32 Big Endian or a binary file; use StreamReader
case 0xfffe: // Unicode BOM (UTF-16 LE or UTF-32 LE)
case 0xfeff: // UTF-16 BE BOM
case 0xefbb: // start of UTF-8 BOM
// StreamReader autodetection works
fs.Position = 0;
return new StreamReader(fs);
default:
return AutoDetect(fs, (byte)firstByte, (byte)secondByte, defaultEncoding);
}
} else {
if (defaultEncoding != null) {
return new StreamReader(fs, defaultEncoding);
} else {
return new StreamReader(fs);
}
}
}
示例8: MX
public MX(String Name,
Stream Stream)
: base(Name, TypeId, Stream)
{
this._Preference = (Stream.ReadByte() << 8) | (Stream.ReadByte() & Byte.MaxValue);
this._Exchange = DNSTools.ExtractName(Stream);
}
示例9: decodeTag
public override DecodedObject<object> decodeTag(Stream stream)
{
int result = 0;
int bt = stream.ReadByte();
if (bt == -1)
return null;
result = bt;
int len = 1;
int tagValue = bt & 31;
//bool isPrimitive = (bt & 0x20) == 0;
if (tagValue == UniversalTags.LastUniversal)
{
bt = 0x80;
while ((bt & 0x80) != 0 && len < 4)
{
result <<= 8;
bt = stream.ReadByte();
if (bt >= 0)
{
result |= bt;
len++;
}
else
{
result >>= 8;
break;
}
}
}
return new DecodedObject<object>(result, len);
}
示例10: MoveStream
private static Stream MoveStream(Stream stream)
{
// HACK: we need this to get the DeflateStream to read properly
stream.ReadByte();
stream.ReadByte();
return stream;
}
示例11: nextToken
public static byte[] nextToken(Stream input, byte[] delimiter)
{
int nextByte;
//If the stream has already ended, return null
if ((nextByte = input.ReadByte()) == -1)
return null;
MemoryStream tokenBuffer = new MemoryStream();
do
{
tokenBuffer.WriteByte((byte)nextByte);
byte[] currentToken = tokenBuffer.ToArray();
if (endsWith(currentToken, delimiter))
{
int tokenLength = currentToken.Length - delimiter.Length;
byte[] token = new byte[tokenLength];
Array.Copy(currentToken, 0, token, 0, tokenLength);
return token;
}
}
while ((nextByte = input.ReadByte()) != -1);
return tokenBuffer.ToArray();
}
示例12: ReadStringFromPositionAndReset
private string ReadStringFromPositionAndReset( Stream s, uint stringPosition )
{
long pos = s.Position;
s.Position = stringPosition;
StringBuilder sb = new StringBuilder();
byte[] buffer = new byte[2];
int b = s.ReadByte();
while ( b != 0 && b != -1 ) {
if ( b == 0x01 ) {
sb.Append( '\n' );
} else if ( b == 0x02 ) {
if ( s.ReadByte() != 0x00 ) { throw new Exception( "control code 0x02 not followed by a null byte!" ); }
sb.AppendFormat( "<Voice: {0:x4}>", s.ReadUInt16() );
} else if ( b == 0x03 ) {
throw new Exception( "unknown control code 0x03" );
} else if ( b == 0x04 ) {
throw new Exception( "unknown control code 0x04" );
} else if ( ( b > 0x04 && b <= 0x80 ) || ( b >= 0xA0 && b <= 0xDF ) ) {
// is a single byte
buffer[0] = (byte)b;
sb.Append( Util.ShiftJISEncoding.GetString( buffer, 0, 1 ) );
} else {
// is two bytes
buffer[0] = (byte)b;
buffer[1] = (byte)s.ReadByte();
sb.Append( Util.ShiftJISEncoding.GetString( buffer ) );
}
b = s.ReadByte();
}
s.Position = pos;
return sb.ToString();
}
示例13: Read
/// <summary>
/// Reads Secure Packet data from a Stream
/// </summary>
/// <param name="stream">Stream</param>
/// <returns>An IEnumerable of byte[] corresponding packet data</returns>
public static IEnumerable Read(Stream stream)
{
while (stream.CanRead)
{
// Reading start sequence
ReadStartSequence(stream);
// Reading header
// - ID
byte id = (byte)stream.ReadByte();
if (id == currentId)
// We skip the packet if it has already been read
continue;
currentId = id;
// - Checksum & size
byte checksum = (byte)stream.ReadByte();
byte size = (byte)stream.ReadByte();
// Reading data
byte[] data = new byte[size];
for (int i = 0; i < size; i++)
data[i] = (byte)stream.ReadByte();
// Integrity check
byte dataChecksum = CheckSum(data);
if (dataChecksum == checksum)
// Checksum OK
yield return data;
}
}
示例14: Parse
public static RequestLine Parse(Stream stream)
{
int b = stream.ReadByte();
while (b == CR || b == LF)
{
b = stream.ReadByte();
}
var bytes = new LinkedList<byte>();
bytes.AddLast((byte) b);
while (true)
{
b = stream.ReadByte();
if (b == CR || b < 0)
{
stream.ReadByte();
break;
}
bytes.AddLast((byte) b);
}
var text = Encoding.Default.GetString(bytes.ToArray());
var parts = text.Split(' ');
if (parts.Length == 3)
{
return new RequestLine(parts[0], parts[1], parts[2]);
}
throw new InvalidRequestException("Invalid Request Line.");
}
示例15: Find
public static long Find(string token, Stream fileStream)
{
while (fileStream.Length != fileStream.Position)
{
if (Compare(token[0], fileStream.ReadByte()))
{
var location = fileStream.Position - 1;
bool fail = false;
for (var index = 1; index <= token.Length - 1; index++)
{
if (!Compare(token[index], fileStream.ReadByte()))
{
fail = true;
break;
}
}
if (!fail)
{
return location;
}
}
}
return -1L;
}