本文整理汇总了C#中System.IO.Stream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadByte方法的具体用法?C# Stream.ReadByte怎么用?C# Stream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Stream
的用法示例。
在下文中一共展示了Stream.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Match
public static long[] Match(Stream source, byte[] pattern, int[] next)
{
var result = new List<long>();
int i = 0, k = 0;
int currentData = source.ReadByte();
while (i < source.Length && k < pattern.Length)
{
if (k == -1 || currentData == pattern[k])
{
++i;
++k;
currentData = source.ReadByte();
}
else
{
k = next[k];
}
if (k == pattern.Length)
{
result.Add(i - pattern.Length);
k = 0;
}
}
return result.ToArray();
}
示例2: Decompress
/// <summary>
/// Decompress (if needed) the given stream.
/// </summary>
private static Stream Decompress(Stream stream)
{
if (stream.Length > 2)
{
var id1 = stream.ReadByte();
var id2 = stream.ReadByte();
stream.Position -= 2;
if ((id1 == 0x1F) && (id2 == 0x8B))
{
// GZIP compressed
var memStream = new MemoryStream();
using (var gzipStream = new GZipStream(stream, CompressionMode.Decompress))
{
var buffer = new byte[64 * 1024];
int len;
while ((len = gzipStream.Read(buffer, 0, buffer.Length)) > 0)
{
memStream.Write(buffer, 0, len);
}
}
memStream.Position = 0;
return memStream;
}
}
return stream;
}
示例3: Read
public override ImageData Read(Stream stream, ImageMetaData info)
{
var pixels = new byte[info.Width*info.Height*4];
stream.Position = 0x18;
int dst = 0;
for (uint y = 0; y < info.Height; ++y)
{
while (dst < pixels.Length)
{
int a = stream.ReadByte();
if (-1 == a)
throw new EndOfStreamException();
else if (0 == a)
{
int count = stream.ReadByte();
if (-1 == count)
throw new EndOfStreamException();
else if (0 == count)
break;
dst += count * 4;
}
else
{
stream.Read (pixels, dst, 3);
pixels[dst + 3] = (byte)a;
dst += 4;
}
}
}
return ImageData.Create (info, PixelFormats.Bgra32, null, pixels);
}
示例4: MoveStream
private static Stream MoveStream(Stream stream)
{
// HACK: we need this to get the DeflateStream to read properly
stream.ReadByte();
stream.ReadByte();
return stream;
}
示例5: ReadFromStream
/// <summary>
/// </summary>
/// <param name="stream">
/// </param>
/// <returns>
/// </returns>
public static StatelData ReadFromStream(Stream stream)
{
StatelData statel = new StatelData();
FlatIdentity fi = new FlatIdentity();
fi.ReadFromStream(stream);
statel.StatelIdentity = fi.Id;
// Skip 4, is always 1?
stream.ReadByte();
stream.ReadByte();
stream.ReadByte();
stream.ReadByte();
PFCoordHeading pfc = new PFCoordHeading();
pfc.ReadFromStream(stream);
statel.X = pfc.Coordinate.X;
statel.Y = pfc.Coordinate.Y;
statel.Z = pfc.Coordinate.Z;
statel.HeadingX = pfc.Heading.X;
statel.HeadingY = pfc.Heading.Y;
statel.HeadingZ = pfc.Heading.Z;
statel.HeadingW = pfc.Heading.W;
statel.PlayfieldId = pfc.PlayfieldIdentity;
BinaryReader br = new BinaryReader(stream);
br.ReadInt32();
statel.TemplateId = br.ReadInt32();
int len2 = br.ReadInt32();
byte[] HighLow = br.ReadBytes(len2);
MemoryStream ms = new MemoryStream(HighLow);
BinaryReader br2 = new BinaryReader(ms);
br2.ReadBytes(8);
int C1 = IPAddress.NetworkToHostOrder(br2.ReadInt32());
Debug.Assert(C1 % 0x3f1 == 0, "Wrong 3f1 encountered... stop please");
int evcount = IPAddress.NetworkToHostOrder(br2.ReadInt32());
while (evcount > 0)
{
int dataType = IPAddress.NetworkToHostOrder(br2.ReadInt32());
switch (dataType)
{
case 2:
HLFlatEvent flatEvent = new HLFlatEvent();
flatEvent.ReadFromStream(ms);
statel.Events.Add(flatEvent.ToEvents());
break;
default:
// Console.WriteLine("DataType " + dataType + " found... stop please");
break;
}
evcount--;
}
return statel;
}
示例6: 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.");
}
示例7: Inflate
/// <summary>
/// Inflate the token
/// NOTE: This operation is not continuable and assumes that the entire token is available in the stream
/// </summary>
/// <param name="source">Stream to inflate the token from</param>
/// <returns>TRUE if inflation is complete</returns>
public virtual bool Inflate(Stream source)
{
// Read column number
Number = (byte)source.ReadByte();
// Update offset with the read size
InflationSize += sizeof(byte);
// Read table number
TableNumber = (byte)source.ReadByte();
// Update offset with the read size
InflationSize += sizeof(byte);
// Read status
Status = (TDSColumnStatus)source.ReadByte();
// Update offset with the read size
InflationSize += sizeof(byte);
// Check if status indicates the table name
if ((Status & TDSColumnStatus.DifferentName) != 0)
{
// Read the length of the table name
byte tableNameLength = (byte)source.ReadByte();
// Read table name
Name = TDSUtilities.ReadString(source, (ushort)(tableNameLength * 2));
}
return true;
}
示例8: LogMessageAttributes
public LogMessageAttributes(Stream stream)
{
Classification = (MessageClass)stream.ReadByte();
Level = (MessageLevel)stream.ReadByte();
MessageSuppression = (MessageSuppression)stream.ReadByte();
Flags = (MessageFlags)stream.ReadByte();
}
示例9: ReadNextString
private string ReadNextString(Stream reader, char marker)
{
StringBuilder sbuild = new StringBuilder();
int i = reader.ReadByte();
while (true)
{
if (i == -1 || i == marker)
break;
else if (i == '/')
{
i = reader.ReadByte();
if (i == '/')
{
do { i = reader.ReadByte(); } while (i != '\n' && i != -1);
i = reader.ReadByte();
}
else
sbuild.Append('/');
}
else
{
sbuild.Append((char)i);
i = reader.ReadByte();
}
}
return sbuild.ToString();
}
示例10: IndefiniteLengthInputStream
internal IndefiniteLengthInputStream(
Stream inStream)
: base(inStream)
{
_b1 = inStream.ReadByte();
_b2 = inStream.ReadByte();
_eofReached = (_b2 < 0);
}
示例11: Read
public static EulaVersion Read(Stream s)
{
var eula = new EulaVersion
{
Minor = (byte) s.ReadByte(),
Major = (byte) s.ReadByte()
};
return eula;
}
示例12: FromStream
public static PTableHeader FromStream(Stream stream)
{
var type = stream.ReadByte();
if (type != (int) FileType.PTableFile)
throw new CorruptIndexException("Corrupted PTable.", new InvalidFileException("Wrong type of PTable."));
var version = stream.ReadByte();
if (version == -1)
throw new CorruptIndexException("Couldn't read version of PTable from header.", new InvalidFileException("Invalid PTable file."));
return new PTableHeader((byte)version);
}
示例13: ToInt32
public static int ToInt32(Stream stream, bool littleEndian)
{
return
ToInt32(
new[]
{
(byte) stream.ReadByte(), (byte) stream.ReadByte(), (byte) stream.ReadByte(),
(byte) stream.ReadByte()
}, 0, littleEndian);
}
示例14: LoadBlockData
protected override void LoadBlockData(Map map, Stream stream) {
for (int i = 0; i < map.Volume; i++) {
map.Blocks[i] = (byte)stream.ReadByte();
int msb = stream.ReadByte();
if (msb == 1) {
map.Blocks[i] = ReduxExtraMapping[map.Blocks[i]];
}
}
map.ConvertBlockTypes(MCSharpMapping);
}
示例15: Read
public Id3v2Tag Read(Stream mp3Stream)
{
Id3v2Tag tag;
byte[] b = new byte[3];
mp3Stream.Read(b, 0, b.Length);
mp3Stream.Seek(0, SeekOrigin.Begin);
string ID3 = new string(System.Text.Encoding.ASCII.GetChars(b));
if (ID3 != "ID3") {
throw new CannotReadException("Not an ID3 tag");
}
//Begins tag parsing ---------------------------------------------
mp3Stream.Seek(3, SeekOrigin.Begin);
//----------------------------------------------------------------------------
//Version du tag ID3v2.xx.xx
string versionHigh=mp3Stream.ReadByte() +"";
string versionID3 =versionHigh+ "." + mp3Stream.ReadByte();
//------------------------------------------------------------------------- ---
//D?tection de certains flags (A COMPLETER)
this.ID3Flags = ProcessID3Flags( (byte) mp3Stream.ReadByte() );
//----------------------------------------------------------------------------
// On extrait la taille du tag ID3
int tagSize = ReadSyncsafeInteger(mp3Stream);
//System.err.println("TagSize: "+tagSize);
// ------------------NEWNEWNWENENEWNENWEWN-------------------------------
//Fill a byte buffer, then process according to correct version
b = new byte[tagSize+2];
mp3Stream.Read(b, 0, b.Length);
ByteBuffer bb = new ByteBuffer(b);
if (ID3Flags[0]==true) {
//We have unsynchronization, first re-synchronize
bb = synchronizer.synchronize(bb);
}
if(versionHigh == "2") {
tag = v23.Read(bb, ID3Flags, Id3v2Tag.ID3V22);
}
else if(versionHigh == "3") {
tag = v23.Read(bb, ID3Flags, Id3v2Tag.ID3V23);
}
else if(versionHigh == "4") {
throw new CannotReadException("ID3v2 tag version "+ versionID3 + " not supported !");
}
else {
throw new CannotReadException("ID3v2 tag version "+ versionID3 + " not supported !");
}
return tag;
}