本文整理汇总了C#中System.IO.BinaryReader类的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader类的具体用法?C# BinaryReader怎么用?C# BinaryReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BinaryReader类属于System.IO命名空间,在下文中一共展示了BinaryReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadTXFNChunk
private void ReadTXFNChunk(BinaryReader bin, BlizzHeader chunk)
{
//List of BLP filenames
var blpFilesChunk = bin.ReadBytes((int)chunk.Size);
var str = new StringBuilder();
for (var i = 0; i < blpFilesChunk.Length; i++)
{
if (blpFilesChunk[i] == '\0')
{
if (str.Length > 1)
{
str.Replace("..", ".");
str.Append(".blp"); //Filenames in TEX dont have have BLP extensions
if (!CASC.FileExists(str.ToString()))
{
new WoWFormatLib.Utils.MissingFile(str.ToString());
}
}
str = new StringBuilder();
}
else
{
str.Append((char)blpFilesChunk[i]);
}
}
}
示例2: GetImageBytes
protected byte[] GetImageBytes()
{
Stream fs = FileUpload.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
return bytes;
}
示例3: Read
internal override void Read(BinaryReader reader)
{
Version = reader.ReadUInt16();
VersionNeededToExtract = reader.ReadUInt16();
Flags = (HeaderFlags) reader.ReadUInt16();
CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
LastModifiedTime = reader.ReadUInt16();
LastModifiedDate = reader.ReadUInt16();
Crc = reader.ReadUInt32();
CompressedSize = reader.ReadUInt32();
UncompressedSize = reader.ReadUInt32();
ushort nameLength = reader.ReadUInt16();
ushort extraLength = reader.ReadUInt16();
ushort commentLength = reader.ReadUInt16();
DiskNumberStart = reader.ReadUInt16();
InternalFileAttributes = reader.ReadUInt16();
ExternalFileAttributes = reader.ReadUInt32();
RelativeOffsetOfEntryHeader = reader.ReadUInt32();
byte[] name = reader.ReadBytes(nameLength);
Name = DecodeString(name);
byte[] extra = reader.ReadBytes(extraLength);
byte[] comment = reader.ReadBytes(commentLength);
Comment = DecodeString(comment);
LoadExtra(extra);
}
示例4: ReadTEX
private void ReadTEX(string filename, Stream tex)
{
var bin = new BinaryReader(tex);
BlizzHeader chunk;
long position = 0;
while (position < tex.Length)
{
tex.Position = position;
chunk = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32());
chunk.Flip();
position = tex.Position + chunk.Size;
switch (chunk.ToString())
{
case "TXVR": ReadTXVRChunk(bin);
continue;
case "TXFN": ReadTXFNChunk(bin, chunk);
continue;
case "TXBT":
case "TXMD": continue;
default:
throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename));
}
}
}
示例5: MDBlob
public MDBlob(BinaryReader reader)
{
//read length indicator
_length = MModule.DecodeInt32(reader);
_data = reader.ReadBytes(_length);
}
示例6: BFCodeLabel
internal BFCodeLabel(BinaryReader reader)
{
_name = reader.ReadCString(24);
_offset = reader.ReadUInt32();
int unused = reader.ReadInt32();
_opcodeIndex = (int)_offset;
}
示例7: RadarColorData
static RadarColorData()
{
using (FileStream index = new FileStream(FileManager.GetFilePath("Radarcol.mul"), FileMode.Open, FileAccess.Read, FileShare.Read))
{
BinaryReader bin = new BinaryReader(index);
// Prior to 7.0.7.1, all clients have 0x10000 colors. Newer clients have fewer colors.
int colorCount = (int)index.Length / 2;
for (int i = 0; i < colorCount; i++)
{
uint c = bin.ReadUInt16();
Colors[i] = 0xFF000000 | (
((((c >> 10) & 0x1F) * multiplier)) |
((((c >> 5) & 0x1F) * multiplier) << 8) |
(((c & 0x1F) * multiplier) << 16)
);
}
// fill the remainder of the color table with non-transparent magenta.
for (int i = colorCount; i < Colors.Length; i++)
{
Colors[i] = 0xFFFF00FF;
}
Metrics.ReportDataRead((int)bin.BaseStream.Position);
}
}
示例8: ServerConnection
public ServerConnection(TcpClient client, SslStream stream, BinaryReader binaryReader, BinaryWriter binaryWriter)
{
_client = client;
_stream = stream;
_binaryReader = binaryReader;
_binaryWriter = binaryWriter;
}
示例9: Load
public void Load(BinaryReader br, FileStream fs)
{
Offset = br.ReadInt32();
Offset += 16;
FrameCount = br.ReadInt32();
MipWidth = br.ReadInt32();
MipHeight = br.ReadInt32();
StartX = br.ReadInt32();
StartY = br.ReadInt32();
TileCount = br.ReadUInt16();
TotalCount = br.ReadUInt16();
CellWidth = br.ReadUInt16();
CellHeight = br.ReadUInt16();
Frames = new EanFrame[TotalCount];
long curPos = fs.Position;
fs.Seek((long)Offset, SeekOrigin.Begin);
for (int i = 0; i < TotalCount; i++)
{
Frames[i].X = br.ReadUInt16();
Frames[i].Y = br.ReadUInt16();
Frames[i].Width = br.ReadUInt16();
Frames[i].Height = br.ReadUInt16();
}
fs.Seek((long)curPos, SeekOrigin.Begin);
}
示例10: Deserialize
public static MessageBase Deserialize(byte[] data)
{
using (MemoryStream stream = new MemoryStream(data))
using (BinaryReader reader = new BinaryReader(stream))
{
// Ignore initial key
reader.ReadByte();
byte payloadLength = reader.ReadByte();
byte packageSequence = reader.ReadByte();
byte systemId = reader.ReadByte();
byte componentId = reader.ReadByte();
byte messageId = reader.ReadByte();
// Create instance based on message id
MessageBase message = null;
Type messageType;
if (_messageTypes.TryGetValue(messageId, out messageType))
{
message = (MessageBase)Activator.CreateInstance(messageType);
message._fields = new object[message._fieldTypes.Length];
for (int i = 0; i < message._fieldTypes.Length; ++i)
{
message.ReadField(reader, i);
}
// TODO: Verify CRC
byte LSBCRC = reader.ReadByte();
byte MSBCRC = reader.ReadByte();
}
return message;
}
}
示例11: TightUnmarshal
//
// Un-marshal an object instance from the data input stream
//
public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs)
{
base.TightUnmarshal(wireFormat, o, dataIn, bs);
ConsumerInfo info = (ConsumerInfo)o;
info.ConsumerId = (ConsumerId) TightUnmarshalCachedObject(wireFormat, dataIn, bs);
info.Browser = bs.ReadBoolean();
info.Destination = (ActiveMQDestination) TightUnmarshalCachedObject(wireFormat, dataIn, bs);
info.PrefetchSize = dataIn.ReadInt32();
info.MaximumPendingMessageLimit = dataIn.ReadInt32();
info.DispatchAsync = bs.ReadBoolean();
info.Selector = TightUnmarshalString(dataIn, bs);
info.SubscriptionName = TightUnmarshalString(dataIn, bs);
info.NoLocal = bs.ReadBoolean();
info.Exclusive = bs.ReadBoolean();
info.Retroactive = bs.ReadBoolean();
info.Priority = dataIn.ReadByte();
if (bs.ReadBoolean()) {
short size = dataIn.ReadInt16();
BrokerId[] value = new BrokerId[size];
for( int i=0; i < size; i++ ) {
value[i] = (BrokerId) TightUnmarshalNestedObject(wireFormat,dataIn, bs);
}
info.BrokerPath = value;
}
else {
info.BrokerPath = null;
}
info.AdditionalPredicate = (BooleanExpression) TightUnmarshalNestedObject(wireFormat, dataIn, bs);
info.NetworkSubscription = bs.ReadBoolean();
info.OptimizedAcknowledge = bs.ReadBoolean();
info.NoRangeAcks = bs.ReadBoolean();
}
示例12: DeCrypting
private static string DeCrypting()
{
var res = string.Empty;
var file = new FileStream(Controller.GetPath(), FileMode.Open, FileAccess.Read, FileShare.None, 32, FileOptions.SequentialScan);
var reader = new BinaryReader(file);
var writer = new BinaryWriter(new FileStream(Processor.GetNewName(Controller.GetPath()), FileMode.Create, FileAccess.Write,
FileShare.None, 32, FileOptions.WriteThrough));
try
{
var pos = 0;
while (pos < file.Length)
{
var c = reader.ReadUInt16();
//var pow = Processor.fast_exp(c, Controller.GetKc(), Controller.GetR());
var pow = Processor.Pows(c, Controller.GetKc(), Controller.GetR());
if (pos < 256) res += pow + " ";
writer.Write((byte)(pow));
pos += 2;
}
}
finally
{
writer.Close();
reader.Close();
}
return "Decoding Complete!\n" + res;
}
示例13: RespawnInfo
public RespawnInfo(BinaryReader reader, int Version, int Customversion)
{
MonsterIndex = reader.ReadInt32();
Location = new Point(reader.ReadInt32(), reader.ReadInt32());
Count = reader.ReadUInt16();
Spread = reader.ReadUInt16();
Delay = reader.ReadUInt16();
Direction = reader.ReadByte();
if (Envir.LoadVersion >= 36)
{
RoutePath = reader.ReadString();
}
if (Version > 67)
{
RandomDelay = reader.ReadUInt16();
RespawnIndex = reader.ReadInt32();
SaveRespawnTime = reader.ReadBoolean();
RespawnTicks = reader.ReadUInt16();
}
else
{
RespawnIndex = ++SMain.Envir.RespawnIndex;
}
}
示例14: TestIncompleteRewind
public void TestIncompleteRewind()
{
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);
bw.Write(1);
bw.Write(2);
bw.Write(3);
bw.Write(4);
bw.Write(5);
bw.Write(6);
bw.Write(7);
bw.Flush();
ms.Position = 0;
RewindableStream stream = new RewindableStream(ms);
stream.StartRecording();
BinaryReader br = new BinaryReader(stream);
Assert.AreEqual(br.ReadInt32(), 1);
Assert.AreEqual(br.ReadInt32(), 2);
Assert.AreEqual(br.ReadInt32(), 3);
Assert.AreEqual(br.ReadInt32(), 4);
stream.Rewind(true);
Assert.AreEqual(br.ReadInt32(), 1);
Assert.AreEqual(br.ReadInt32(), 2);
stream.StartRecording();
Assert.AreEqual(br.ReadInt32(), 3);
Assert.AreEqual(br.ReadInt32(), 4);
Assert.AreEqual(br.ReadInt32(), 5);
stream.Rewind(true);
Assert.AreEqual(br.ReadInt32(), 3);
Assert.AreEqual(br.ReadInt32(), 4);
Assert.AreEqual(br.ReadInt32(), 5);
Assert.AreEqual(br.ReadInt32(), 6);
Assert.AreEqual(br.ReadInt32(), 7);
}
示例15: KinectReader
public KinectReader(Stream fileStream, int width, int height)
{
this.Width = width;
this.Height = height;
this.reader = new BinaryReader(fileStream);
this.createIndexes();
}