本文整理汇总了C#中System.Stream.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadBytes方法的具体用法?C# Stream.ReadBytes怎么用?C# Stream.ReadBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Stream
的用法示例。
在下文中一共展示了Stream.ReadBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseFrames
TmpTDFrame[] ParseFrames(Stream s)
{
var start = s.Position;
var width = s.ReadUInt16();
var height = s.ReadUInt16();
var size = new Size(width, height);
s.Position += 8;
var imgStart = s.ReadUInt32();
s.Position += 8;
var indexEnd = s.ReadInt32();
var indexStart = s.ReadInt32();
s.Position = indexStart;
var count = indexEnd - indexStart;
var tiles = new TmpTDFrame[count];
var tilesIndex = 0;
foreach (var b in s.ReadBytes(count))
{
if (b != 255)
{
s.Position = imgStart + b * width * height;
tiles[tilesIndex++] = new TmpTDFrame(s.ReadBytes(width * height), size);
}
else
tiles[tilesIndex++] = new TmpTDFrame(null, size);
}
s.Position = start;
return tiles;
}
示例2: ReadBlock
public static void ReadBlock(Stream stream, out BlockType blockType, out byte[] data)
{
blockType = (BlockType)stream.ReadByte();
var sizeBuffer = stream.ReadBytes(2);
var size = (ushort)(sizeBuffer[0] | sizeBuffer[1] << 8);
data = stream.ReadBytes(size - 2);
}
示例3: LoadFromStream
protected override void LoadFromStream(Stream stream)
{
base.LoadFromStream(stream);
if (Version == 1)
{
_CreationTime = stream.ReadBEUInt64();
_ModificationTime = stream.ReadBEUInt64();
TimeScale = stream.ReadBEUInt32();
Duration = stream.ReadBEUInt64();
}
else // if(Version == 0)
{
_CreationTime = stream.ReadBEUInt32();
_ModificationTime = stream.ReadBEUInt32();
TimeScale = stream.ReadBEUInt32();
Duration = stream.ReadBEUInt32();
}
_Rate = stream.ReadBEInt32();
_Volume = stream.ReadBEInt16();
Reserved = stream.ReadBytes(2 + (2 * 4));
for (int i = 0; i < 9; i++) Matrix[i] = stream.ReadBEInt32();
PreDefined = stream.ReadBytes(6 * 4);
NextTrackID = stream.ReadBEUInt32();
}
示例4: WavLoader
public WavLoader(Stream s)
{
while (s.Position < s.Length)
{
if ((s.Position & 1) == 1)
s.ReadByte(); // Alignment
var type = s.ReadASCII(4);
switch (type)
{
case "RIFF":
FileSize = s.ReadInt32();
Format = s.ReadASCII(4);
if (Format != "WAVE")
throw new NotSupportedException("Not a canonical WAVE file.");
break;
case "fmt ":
FmtChunkSize = s.ReadInt32();
AudioFormat = s.ReadInt16();
Type = (WaveType)AudioFormat;
if (Type != WaveType.Pcm && Type != WaveType.ImaAdpcm)
throw new NotSupportedException("Compression type is not supported.");
Channels = s.ReadInt16();
SampleRate = s.ReadInt32();
ByteRate = s.ReadInt32();
BlockAlign = s.ReadInt16();
BitsPerSample = s.ReadInt16();
s.ReadBytes(FmtChunkSize - 16);
break;
case "fact":
{
var chunkSize = s.ReadInt32();
UncompressedSize = s.ReadInt32();
s.ReadBytes(chunkSize - 4);
}
break;
case "data":
DataSize = s.ReadInt32();
RawOutput = s.ReadBytes(DataSize);
break;
default:
// Ignore unknown chunks
{
var chunkSize = s.ReadInt32();
s.ReadBytes(chunkSize);
}
break;
}
}
if (Type == WaveType.ImaAdpcm)
{
RawOutput = DecodeImaAdpcmData();
BitsPerSample = 16;
}
}
示例5: ShpTSReader
public ShpTSReader(Stream stream)
{
stream.ReadUInt16();
var width = stream.ReadUInt16();
var height = stream.ReadUInt16();
var size = new Size(width, height);
var frameCount = stream.ReadUInt16();
for (var i = 0; i < frameCount; i++)
frames.Add(new FrameHeader(stream, size));
for (var i = 0; i < frameCount; i++)
{
var f = frames[i];
if (f.FileOffset == 0)
continue;
stream.Position = f.FileOffset;
// Uncompressed
if (f.Format == 1 || f.Format == 0)
f.Data = stream.ReadBytes(f.Size.Width * f.Size.Height);
// Uncompressed scanlines
else if (f.Format == 2)
{
f.Data = new byte[f.Size.Width * f.Size.Height];
for (var j = 0; j < f.Size.Height; j++)
{
var length = stream.ReadUInt16() - 2;
stream.Read(f.Data, f.Size.Width * j, length);
}
}
// RLE-zero compressed scanlines
else if (f.Format == 3)
{
f.Data = new byte[f.Size.Width * f.Size.Height];
for (var j = 0; j < f.Size.Height; j++)
{
var length = stream.ReadUInt16() - 2;
Format2.DecodeInto(stream.ReadBytes(length), f.Data, j * f.Size.Width);
}
}
}
spriteFrames = Exts.Lazy(() => frames.Cast<ISpriteFrame>());
}
示例6: Decrypt
public static Account Decrypt(Stream inputStream, ConsoleType consoleType)
{
var hmac = new HMACSHA1(consoleType == ConsoleType.Retail ? RetailKey : DevkitKey);
var hash = inputStream.ReadBytes(16);
var rc4Key = hmac.ComputeHash(hash);
Array.Resize(ref rc4Key, 16);
var rest = inputStream.ReadBytes(388);
var body = RC4.Decrypt(rc4Key, rest);
var compareBuffer = hmac.ComputeHash(body);
if (!memcmp(hash, compareBuffer, 16))
throw new InvalidDataException("Keys do not match");
return ModelFactory.GetModel<Account>(body.Skip(8).ToArray());
}
示例7: R8Frame
public R8Frame(Stream s)
{
// Scan forward until we find some data
var type = s.ReadUInt8();
while (type == 0)
type = s.ReadUInt8();
var width = s.ReadInt32();
var height = s.ReadInt32();
var x = s.ReadInt32();
var y = s.ReadInt32();
Size = new Size(width, height);
Offset = new int2(width / 2 - x, height / 2 - y);
/*var imageOffset = */
s.ReadInt32();
var paletteOffset = s.ReadInt32();
var bpp = s.ReadUInt8();
if (bpp != 8)
throw new InvalidDataException("Error: {0} bits per pixel are not supported.".F(bpp));
var frameHeight = s.ReadUInt8();
var frameWidth = s.ReadUInt8();
FrameSize = new Size(frameWidth, frameHeight);
// Skip alignment byte
s.ReadUInt8();
Data = s.ReadBytes(width * height);
// Ignore palette
if (type == 1 && paletteOffset != 0)
s.Seek(520, SeekOrigin.Current);
}
示例8: Decode
public DatabaseObject Decode(Stream source)
{
if (source == null) { throw new ArgumentNullException("source"); }
// Create a binary reader that can be disposed without disposing the underlying stream.
string type;
string lenStr;
using (BinaryReader reader = new BinaryReader(new DisposeProtectedStream(source)))
{
// First token is the type
type = ReadToken(reader);
// Second is the len
lenStr = ReadToken(reader);
}
long len = -1;
if(!Int64.TryParse(lenStr, out len)) {
throw new InvalidDataException(String.Format("Invalid object, length token value is not an integer: {0}", lenStr));
}
// Should now be at the object body, read that in (for now)
byte[] data = source.ReadBytes(len);
return new DatabaseObject(DatabaseObjectTypeHelper.Parse(type), data);
}
示例9: Decode
public static String Decode(Stream stream)
{
int len = Int32EncodingLE.Decode(stream);
if (len == -1) return null;
byte[] buf = stream.ReadBytes(len);
return Decode(buf);
}
示例10: Open
public Stream Open(Stream stream)
{
stream.Seek(DataOffset, SeekOrigin.Begin);
byte[] data;
if (DataCompression == 0)
{
data = stream.ReadBytes(DataSize);
}
else
{
var dataBuffer = stream.ReadBytes(DataCompressedSize);
var inflater = new Inflater(false);
inflater.SetInput(dataBuffer);
data = new Byte[DataSize];
inflater.Inflate(data);
}
return new MemoryStream(data);
}
示例11: LoadFromStream
protected override void LoadFromStream(Stream stream)
{
base.LoadFromStream(stream);
_Predefined = stream.ReadBEUInt32();
HandlerType = new FourCC(stream.ReadBytes(4));
for (int i = 0; i < _Reserved.Length; i++) _Reserved[i] = stream.ReadBEUInt32();
Name = stream.ReadNullTerminatedUTF8String();
}
示例12: FileGroup
public FileGroup(Stream reader, long offset)
{
var nameOffset = reader.ReadUInt32();
/* unknown */ reader.ReadBytes(18);
FirstFile = reader.ReadUInt32();
LastFile = reader.ReadUInt32();
reader.Seek(offset + (long)nameOffset, SeekOrigin.Begin);
Name = reader.ReadASCIIZ();
}
示例13: InstallShieldCABExtractor
public InstallShieldCABExtractor(FileSystem context, string hdrFilename)
{
var fileGroups = new List<FileGroup>();
var fileGroupOffsets = new List<uint>();
hdrFile = context.Open(hdrFilename);
this.context = context;
// Strips archive number AND file extension
Name = Regex.Replace(hdrFilename, @"\d*\.[^\.]*$", "");
var signature = hdrFile.ReadUInt32();
if (signature != 0x28635349)
throw new InvalidDataException("Not an Installshield CAB package");
commonHeader = new CommonHeader(hdrFile);
cabDescriptor = new CabDescriptor(hdrFile, commonHeader);
/* unknown */ hdrFile.ReadBytes(14);
for (var i = 0U; i < MaxFileGroupCount; ++i)
fileGroupOffsets.Add(hdrFile.ReadUInt32());
hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset, SeekOrigin.Begin);
directoryTable = new List<uint>();
for (var i = 0U; i < cabDescriptor.DirectoryCount; ++i)
directoryTable.Add(hdrFile.ReadUInt32());
foreach (var offset in fileGroupOffsets)
{
var nextOffset = offset;
while (nextOffset != 0)
{
hdrFile.Seek((long)nextOffset + 4 + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
var descriptorOffset = hdrFile.ReadUInt32();
nextOffset = hdrFile.ReadUInt32();
hdrFile.Seek(descriptorOffset + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
fileGroups.Add(new FileGroup(hdrFile, commonHeader.CabDescriptorOffset));
}
}
hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2, SeekOrigin.Begin);
foreach (var fileGroup in fileGroups)
{
for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; ++i)
{
AddFileDescriptorToList(i);
var fileDescriptor = fileDescriptors[i];
var fullFilePath = "{0}\\{1}\\{2}".F(fileGroup.Name, DirectoryName(fileDescriptor.DirectoryIndex), fileDescriptor.Filename);
index.Add(fullFilePath, i);
}
}
}
示例14: Read
public static ApplicationData Read(Stream stream)
{
var blockSize = stream.ReadByte();
if (blockSize <= 0)
{
return null;
}
var data = stream.ReadBytes(blockSize);
return new ApplicationData((byte) blockSize, data);
}
示例15: WavLoader
public WavLoader(Stream s)
{
while (s.Position < s.Length)
{
if ((s.Position & 1) == 1)
s.ReadByte(); // Alignment
var type = s.ReadASCII(4);
switch (type)
{
case "RIFF":
FileSize = s.ReadInt32();
Format = s.ReadASCII(4);
if (Format != "WAVE")
throw new NotSupportedException("Not a canonical WAVE file.");
break;
case "fmt ":
FmtChunkSize = s.ReadInt32();
if (FmtChunkSize != 16)
throw new NotSupportedException("{0} fmt chunk size is not a supported encoding scheme.".F(FmtChunkSize));
AudioFormat = s.ReadInt16();
if (AudioFormat != 1)
throw new NotSupportedException("Non-PCM compression is not supported.");
Channels = s.ReadInt16();
SampleRate = s.ReadInt32();
ByteRate = s.ReadInt32();
BlockAlign = s.ReadInt16();
BitsPerSample = s.ReadInt16();
break;
case "data":
DataSize = s.ReadInt32();
RawOutput = s.ReadBytes(DataSize);
break;
default:
// Ignore unknown chunks
var chunkSize = s.ReadInt32();
s.ReadBytes(chunkSize);
break;
}
}
}