本文整理汇总了C#中System.IO.BinaryReader.ReadChar方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadChar方法的具体用法?C# BinaryReader.ReadChar怎么用?C# BinaryReader.ReadChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.ReadChar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
using (BinaryReader b = new BinaryReader(File.Open("file.top", FileMode.Open)))
{
int pos = 0;
int length = (int)b.BaseStream.Length;
char ch0 = b.ReadChar();
char ch1 = b.ReadChar();
char ch2 = b.ReadChar();
byte verr = b.ReadByte();
/*Int32 tripCount = b.ReadInt32();
for (int i = 0; i < tripCount; i++)
{
Int64 time = b.ReadInt64();
string comment = b.ReadString();
Int16 declination = b.ReadInt16();
}
pos += sizeof(char) * 3;*/
TopFile file = new TopFile(b);
}
byte[] fajl = File.ReadAllBytes("file.top");
/* char ch0 = Convert.ToChar(fajl[0]);
char ch1 = Convert.ToChar(fajl[1]);
char ch2 = Convert.ToChar(fajl[2]);
byte ver = fajl[3];*/
//TopFile file = new TopFile(fajl, 4);
}
示例2: ShareMemory
public static void ShareMemory()
{
using (MemoryMappedFile mmf = MemoryMappedFile.CreateNew(MmfName, 10000))
{
Console.WriteLine("Process A started.");
bool mutexCreated;
var mutex = new Mutex(true, MmfMutex, out mutexCreated);
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
var writer = new BinaryWriter(stream);
writer.Write('a');
}
mutex.ReleaseMutex();
Console.WriteLine("Please start process B. Once it's done press ENTER.");
Console.ReadLine();
mutex.WaitOne();
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
var reader = new BinaryReader(stream);
Console.WriteLine("Process A : {0}", reader.ReadChar());
Console.WriteLine("Process B : {0}", reader.ReadChar());
Console.ReadLine();
}
mutex.ReleaseMutex();
}
}
示例3: GenerateDonorGenomeFromReferenceGenome
public static void GenerateDonorGenomeFromReferenceGenome(string refGenomeFile, string donorGenomeFile)
{
var rng = new Random();
using (var refFile = File.OpenRead(refGenomeFile))
using (var donorFile = File.Open(donorGenomeFile, FileMode.Create))
{
var reader = new BinaryReader(refFile);
var writer = new BinaryWriter(donorFile);
for (long i = 0; i < refFile.Length; i++)
{
var randomNumber = rng.NextDouble();
if (randomNumber < SnpDensity)
{
var readChar = reader.ReadChar();
if (readChar == 'A')
writer.Write('C');
else if (readChar == 'C')
writer.Write('G');
else if (readChar == 'G')
writer.Write('T');
else if (readChar == 'T')
writer.Write('A');
else throw new Exception();
}
else
{
writer.Write(reader.ReadChar());
}
}
}
}
示例4: ReadAllLines
public static string[] ReadAllLines(BinaryReader reader)
{
List<string> strings = new List<string>();
StringBuilder temp = new StringBuilder();
char lastChar = reader.ReadChar();
// an EndOfStreamException here would propogate to the caller
try
{
while (true)
{
char newChar = reader.ReadChar();
if (lastChar == '\r' && newChar == '\n')
{
strings.Add(temp.ToString());
}
temp.Append(lastChar);
lastChar = newChar;
}
}
catch (EndOfStreamException)
{
temp.Append(lastChar);
strings.Add(temp.ToString());
return strings.ToArray();
}
}
示例5: GetEntries
public static SortedDictionary<string, Stream> GetEntries(string archive)
{
SortedDictionary<string, Stream> result = new SortedDictionary<string, Stream>();
BinaryReader br = new BinaryReader(File.OpenRead(archive));
StringBuilder sb = new StringBuilder();
var magic = new String(br.ReadChars(4));
if (magic != "BIG4" && magic != "BIGF")
{
throw new BigLoadException(archive + " is not a valid BIG4 File");
}
UInt32 filesize = br.ReadUInt32();
UInt32 numEntries = ReadUint32LE(br);
UInt32 offset = ReadUint32LE(br);
for (var i = 0;i<numEntries;++i)
{
var entryOffset = ReadUint32LE(br);
var entrySize = ReadUint32LE(br);
char c = br.ReadChar();
while(c!=0)
{
sb.Append(c);
c = br.ReadChar();
}
var bs = new BigStream(br.BaseStream, entryOffset, entrySize, sb.ToString());
result.Add(sb.ToString(), bs);
sb.Clear();
}
return result;
}
示例6: load
// --- Static Methods ---
// Loads in the team
public static Team load(string filename, GameExt game)
{
// Variables
BinaryReader reader= new BinaryReader(File.OpenRead(filename));
Team team= new Team(game, true);
int size;
int passiveSize= 0;
team.money= reader.ReadInt32();
size= reader.ReadInt32();
for(int i= 0; i< size; i++)
{
team.units.add(
new Unit(
reader.ReadString(),
reader.ReadString(),
reader.ReadString(),
game,
game.registry.get<ProfessionRegistry>().get(reader.ReadChar()+""+reader.ReadChar()+""+reader.ReadChar()+""+reader.ReadChar())
)
);
team.units.items[i].statVariance= new BaseStats(reader.ReadUInt64());
team.units.items[i].setExp(reader.ReadInt32());
passiveSize= reader.ReadInt32();
for(int k= 0; k< passiveSize; k++)
{
team.units.items[i].assignPassive(
team.units.items[i].decryptPassive(reader.ReadChar()),
k
);
}
}
return team;
}
示例7: Load
public static BARFile Load(string filename)
{
if (!File.Exists(filename)) return null;
var file = File.OpenRead(filename);
var bar = new BARFile() {
stream = file,
SourceFilename = filename,
};
var reader = new BinaryReader(file);
reader.Read(bar.Id = new byte[8], 0, 8);
int unknown = reader.ReadInt32();
int entryC = reader.ReadInt32();
bar.DirectorySize = reader.ReadInt32();
bar.DirectoryOffset = reader.ReadInt32();
int unknown2 = reader.ReadInt32();
file.Seek(bar.DirectoryOffset, SeekOrigin.Begin);
int[] offsets = new int[entryC];
for (int o = 0; o < offsets.Length; ++o) offsets[o] = reader.ReadInt32();
for (int e = 0; e < entryC; ++e) {
Entry entry = new Entry();
entry.Offset = reader.ReadInt32();
entry.Size = reader.ReadInt32();
entry.Size2 = reader.ReadInt32();
byte b0 = reader.ReadByte(),
b1 = reader.ReadByte(),
b2 = reader.ReadByte(),
b3 = reader.ReadByte();
if (b3 != 0) file.Position += 4;
for (var c = reader.ReadChar(); c != '\0'; c = reader.ReadChar()) {
entry.Name += c;
}
bar.entries.Add(entry);
}
return bar;
}
示例8: Read
public void Read(BinaryReader reader)
{
ID0 = reader.ReadChar();
ID1 = reader.ReadChar();
ID2 = reader.ReadChar();
ID3 = reader.ReadChar();
length = NetworkToHostOrder(reader.ReadUInt32());
}
示例9: DecompressXMLDocument
public static XmlDocument DecompressXMLDocument(Stream ms)
{
BinaryReader br = new BinaryReader(ms);
StringBuilder sb = new StringBuilder();
while (br.PeekChar() != (int)BYTE_TAGS.DEFINE_ELEMENTS_BEGIN)
{
br.ReadChar();
}
//Load elemental translations
br.ReadChar();
bool elem_use_short = br.ReadByte() == (byte)2;
Dictionary<int, string> elementTrans = new Dictionary<int, string>();
int id;
int len;
while (true)
{
if (br.ReadByte() == (int)BYTE_TAGS.DEFINE_ELEMENTS_END)
break;
if (elem_use_short)
id = (int)br.ReadInt16();
else
id = (int)br.ReadByte();
len = br.ReadInt32();
elementTrans.Add(id, System.Text.ASCIIEncoding.ASCII.GetString(br.ReadBytes(len)));
}
//Load attribute translations
br.ReadByte();
bool att_use_short = br.ReadByte() == (byte)2;
Dictionary<int, string> attTrans = new Dictionary<int, string>();
while (true)
{
if (br.ReadByte() == (byte)BYTE_TAGS.DEFINE_ATTRIBUTES_END)
break;
if (att_use_short)
id = (int)br.ReadInt16();
else
id = (int)br.ReadByte();
len = br.ReadInt32();
attTrans.Add(id, System.Text.ASCIIEncoding.ASCII.GetString(br.ReadBytes(len)));
}
//begin loading and translation of the document back to xml
br.ReadByte();
XmlDocument ret = new XmlDocument();
while (br.BaseStream.Position < br.BaseStream.Length - 1)
{
XmlElement tmp = LoadElement(ref br, ret,att_use_short,elem_use_short,elementTrans,attTrans);
if (tmp != null)
ret.AppendChild(tmp);
}
return ret;
}
示例10: getShMemData
public Int32 getShMemData(int offset = 0)
{
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
BinaryReader reader = new BinaryReader(stream);
for (int i = 0; i < offset; i++) reader.ReadChar();
return reader.ReadChar();
}
}
示例11: DxfBinaryReader
public DxfBinaryReader(BinaryReader reader)
{
_reader = reader;
// swallow next two characters
var sub = reader.ReadChar();
Debug.Assert(sub == 0x1A);
var nul = reader.ReadChar();
Debug.Assert(nul == 0x00);
}
示例12: Load
public static DDTImage Load(Stream file)
{
long beg = file.Position;
var reader = new BinaryReader(file);
string header = "";
for (int h = 0; h < 3; ++h) header += reader.ReadChar();
if (header != "RTS") throw new InvalidDataException();
int version = (int)reader.ReadChar() - (int)'0';
if (version == 3) {
var img = new DDTImage();
var serializer = new SerialReader(new BinaryReader(file));
SerializeHeader(ref img.Header, serializer);
int numColors = (img.Palette != null ? img.Palette.Length : 0);
int[] paletteOffs = new int[5];
if (img.Header.Format == ImageHeader.FormatE.Palette) {
// TODO: paletteOffs[img.Header.AlphaBits] = palette offset
serializer.Serialize(ref numColors);
int unknown02 = 0;
int palette15Off = 0;
serializer.Serialize(ref unknown02);
serializer.Serialize(ref paletteOffs[0]); //16
serializer.Serialize(ref palette15Off);
serializer.Serialize(ref paletteOffs[1]); //15b
serializer.Serialize(ref paletteOffs[4]); //12
}
List<Tuple<int, int>> images = new List<Tuple<int, int>>();
for (int l = 0; l < img.Header.MipLevels; ++l) {
int off = reader.ReadInt32();
int len = reader.ReadInt32();
images.Add(new Tuple<int,int>(off, len));
}
if (img.Header.Format == ImageHeader.FormatE.Palette) {
file.Seek(beg + paletteOffs[img.Header.AlphaBits], SeekOrigin.Begin);
byte[] paletteData = new byte[numColors * 2];
file.Read(paletteData, 0, paletteData.Length);
img.Palette = new Pixel[numColors];
switch (img.Header.AlphaBits) {
case 0: Convert565ToRGB(paletteData, 0, img.Palette); break;
case 1: Convert555ToRGB(paletteData, 0, img.Palette); break;
case 4: Convert444ToRGB(paletteData, 0, img.Palette); break;
}
}
file.Seek(beg + images[0].Item1, SeekOrigin.Begin);
byte[] bytes = new byte[images[0].Item2];
reader.Read(bytes, 0, bytes.Length);
img.PixelData = bytes;
return img;
}
return null;
}
示例13: ReadString
public static string ReadString(BinaryReader stream)
{
string r = "";
char c = stream.ReadChar();
while (c != 0xFF)
{
r += c;
c = stream.ReadChar();
}
return r;
}
示例14: ExtractAudio
public byte[] ExtractAudio(Stream stream)
{
stream.Position = 0;
var reader = new BinaryReader(stream);
// Is stream a Flash Video stream
if (reader.ReadChar() != 'F' || reader.ReadChar() != 'L' || reader.ReadChar() != 'V')
throw new IOException("The file is not a FLV file.");
// Is audio stream exists in the video stream
var version = reader.ReadByte();
var exists = reader.ReadByte();
if ((exists != 5) && (exists != 4))
throw new IOException("No Audio Stream");
reader.ReadInt32(); // data offset of header. ignoring
var output = new List<byte>();
while (true)
{
try
{
reader.ReadInt32(); // PreviousTagSize0 skipping
var tagType = reader.ReadByte();
while (tagType != 8)
{
var skip = ReadNext3Bytes(reader) + 11;
reader.BaseStream.Position += skip;
tagType = reader.ReadByte();
}
var DataSize = ReadNext3Bytes(reader);
reader.ReadInt32(); //skip timestamps
ReadNext3Bytes(reader); // skip streamID
reader.ReadByte(); // skip audio header
for (int i = 0; i < DataSize - 1; i++)
output.Add(reader.ReadByte());
}
catch
{
break;
}
}
return output.ToArray();
}
示例15: ReadLine
private string ReadLine(BinaryReader binReader)
{
StringBuilder result = new StringBuilder();
char lastChar = binReader.ReadChar();
while (lastChar != '\n')
{
result.Append(lastChar);
lastChar = binReader.ReadChar();
}
return result.ToString();
}