本文整理汇总了C#中System.IO.BinaryReader.ReadChar方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryReader.ReadChar方法的具体用法?C# System.IO.BinaryReader.ReadChar怎么用?C# System.IO.BinaryReader.ReadChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了System.IO.BinaryReader.ReadChar方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: split
public static void split(string input_path, string dir_path, int nb)
{
System.IO.FileStream inf = new System.IO.FileStream(input_path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader reader = new System.IO.BinaryReader(inf);
System.IO.BinaryWriter[] writers = new System.IO.BinaryWriter[nb];
for (int x = 0; x < nb; x++)
{
writers[x] = new System.IO.BinaryWriter(new System.IO.FileStream(dir_path + "/part_" + (x + 1) + ".ACDC",
System.IO.FileMode.Create,
System.IO.FileAccess.Write));
}
int i = 0;
while (reader.PeekChar() != -1)
{
writers[i % nb].Write(reader.ReadChar());
i++;
}
for (int j=0; j<nb; j++)
{
writers[j].Close();
}
}
示例2: OpenFile
private void OpenFile(string filename)
{
#if !DEBUG
try
{
#endif
_filename = filename;
fileIn = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read));
string startFileSig = "";
for (int i = 0; i < 4; i++) // 4 bytes
{
startFileSig += fileIn.ReadChar();
}
if (startFileSig != "#PES")
{
// This is not a file that we can read
readyStatus = statusEnum.ParseError;
lastError = "Missing #PES at beginning of file";
fileIn.Close();
return;
}
// PES version
string versionString = "";
for (int i = 0; i < 4; i++) // 4 bytes
{
versionString += fileIn.ReadChar();
}
pesVersion = Convert.ToUInt16(versionString);
int pecstart = fileIn.ReadInt32();
fileIn.BaseStream.Position = pecstart + 48;
int numColors = fileIn.ReadByte() +1;
List<byte> colorList = new List<byte>();
for (int x = 0; x < numColors; x++)
{
colorList.Add(fileIn.ReadByte());
}
fileIn.BaseStream.Position = pecstart + 532;
bool thisPartIsDone = false;
stitchBlock curBlock;
int prevX = 0;
int prevY = 0;
int maxX = 0;
int minX = 0;
int maxY = 0;
int minY = 0;
int colorNum = -1;
int colorIndex = 0;
List<Point> tempStitches = new List<Point>();
while (!thisPartIsDone)
{
byte val1;
byte val2;
val1 = fileIn.ReadByte();
val2 = fileIn.ReadByte();
if (val1 == 255 && val2 == 0)
{
//end of stitches
thisPartIsDone = true;
//add the last block
curBlock = new stitchBlock();
curBlock.stitches = new Point[tempStitches.Count];
tempStitches.CopyTo(curBlock.stitches);
curBlock.stitchesTotal = tempStitches.Count;
colorNum++;
colorIndex = colorList[colorNum];
curBlock.colorIndex = colorIndex;
curBlock.color = getColorFromIndex(colorIndex);
blocks.Add(curBlock);
}
else if (val1 == 254 && val2 == 176)
{
//color switch, start a new block
curBlock = new stitchBlock();
curBlock.stitches = new Point[tempStitches.Count];
tempStitches.CopyTo(curBlock.stitches);
curBlock.stitchesTotal = tempStitches.Count;
colorNum++;
colorIndex = colorList[colorNum];
curBlock.colorIndex = colorIndex;
curBlock.color = getColorFromIndex(colorIndex);
blocks.Add(curBlock);
tempStitches = new List<Point>();
//read useless(?) byte
fileIn.ReadByte();
}
else
{
int deltaX = 0;
int deltaY = 0;
if ((val1 & 0x80) == 0x80)
{
//.........这里部分代码省略.........
示例3: LeCadastroDoArquivo
public void LeCadastroDoArquivo()
{
System.IO.BinaryReader leitor = null;
Aluno a;
int n;
this.lista = new System.Collections.Generic.List<Aluno>();
try
{
leitor = new System.IO.BinaryReader(new System.IO.FileStream("alunos.dat", System.IO.FileMode.Open));
n = leitor.ReadInt32();
for (int i = 0; i < n; i++)
{
a = new Aluno();
a.nome = leitor.ReadString();
a.idade = leitor.ReadInt32();
a.sexo = leitor.ReadChar();
this.lista.Add(a);
}
}
catch (System.IO.FileNotFoundException)
{
Console.WriteLine("AVISO! Arquivo alunos.dat não foi encontrado. Cadastro começará vazio.");
Console.ReadKey();
}
catch (System.Exception exc)
{
Console.WriteLine("ERRO! " + exc.Message);
Console.ReadKey();
}
finally
{
if (leitor != null)
leitor.Close();
}
}
示例4: Process
private void Process(string path)
{
if (!System.IO.File.Exists(path))
{
//MessageBox.Show("种子文件异常!", "提示",MessageBoxButton.OK,MessageBoxImage.Error);
}
TotalValues = 0L;
_path = path;
_torrent = new System.IO.BinaryReader(new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read),
System.Text.Encoding.UTF8);
if (_torrent.ReadChar() != 'd')
{
//MessageBox.Show("种子文件异常!", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
//行了
}
_root = ProcessDict();
ShaHash = GetShaHash();
_files = GetFiles();
_torrent.Close();
}
示例5: OpenFile
private void OpenFile(string filename)
{
#if !DEBUG
try
{
#endif
_filename = filename;
fileIn = new System.IO.BinaryReader(System.IO.File.Open(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read));
string startFileSig = "";
for (int i = 0; i < 4; i++) // 4 bytes
{
startFileSig += fileIn.ReadChar();
}
if (startFileSig != "#PES")
{
// This is not a file that we can read
readyStatus = statusEnum.ParseError;
lastError = "Missing #PES at beginning of file";
fileIn.Close();
return;
}
// PES version
string versionString = "";
for (int i = 0; i < 4; i++) // 4 bytes
{
versionString += fileIn.ReadChar();
}
pesVersion = Convert.ToUInt16(versionString);
int pecstart = fileIn.ReadInt32();
// Read number of colors in this design
fileIn.BaseStream.Position = pecstart + 48;
int numColors = fileIn.ReadByte() +1;
List<byte> colorList = new List<byte>();
for (int x = 0; x < numColors; x++)
{
colorList.Add(fileIn.ReadByte());
}
// Read stitch data
fileIn.BaseStream.Position = pecstart + 532;
bool thisPartIsDone = false;
StitchBlock curBlock;
int prevX = 0;
int prevY = 0;
int maxX = 0;
int minX = 0;
int maxY = 0;
int minY = 0;
int colorNum = -1;
int colorIndex = 0;
List<Stitch> tempStitches = new List<Stitch>();
while (!thisPartIsDone)
{
byte val1;
byte val2;
val1 = fileIn.ReadByte();
val2 = fileIn.ReadByte();
if (val1 == 0xff && val2 == 0x00)
{
//end of stitches
thisPartIsDone = true;
//add the last block
curBlock = new StitchBlock();
curBlock.stitches = new Stitch[tempStitches.Count];
tempStitches.CopyTo(curBlock.stitches);
curBlock.stitchesTotal = tempStitches.Count;
colorNum++;
colorIndex = colorList[colorNum];
curBlock.colorIndex = colorIndex;
curBlock.color = getColorFromIndex(colorIndex);
blocks.Add(curBlock);
}
else if (val1 == 0xfe && val2 == 0xb0)
{
//color switch, start a new block
curBlock = new StitchBlock();
curBlock.stitches = new Stitch[tempStitches.Count];
tempStitches.CopyTo(curBlock.stitches);
curBlock.stitchesTotal = tempStitches.Count;
colorNum++;
colorIndex = colorList[colorNum];
curBlock.colorIndex = colorIndex;
curBlock.color = getColorFromIndex(colorIndex);
//read useless(?) byte
// The value of this 'useless' byte seems to alternate
// between 2 and 1 for every other block. The only
// exception I've noted is the last block which appears
// to always be 0.
curBlock.unknownStartByte = fileIn.ReadByte();
blocks.Add(curBlock);
tempStitches = new List<Stitch>();
}
else
//.........这里部分代码省略.........
示例6: readGameData
private void readGameData()
{
textBox2.Text = path;
if (roq != null)
roq.stop();
roq = null;
if (vdx != null)
vdx.stop();
vdx = null;
switch (game)
{
case GameID.T7G:
lblGame.Text = "The 7th Guest";
System.IO.DirectoryInfo DI = new System.IO.DirectoryInfo(path);
System.IO.FileInfo[] files = DI.GetFiles("*.rl");
this.gjdChooser.Items.Clear();
foreach (System.IO.FileInfo rl in files)
{
this.gjdChooser.Items.Add(rl.Name);
}
break;
case GameID.T11H:
lblGame.Text = "The 11th Hour";
//ROQ roq = new ROQ(new System.IO.BinaryReader(new System.IO.FileStream(path + "\\media\\final_hr.rol", System.IO.FileMode.Open)));
this.gjdChooser.Items.Clear();
System.IO.BinaryReader idx = new System.IO.BinaryReader(new System.IO.FileStream(path + "\\groovie\\gjd.gjd", System.IO.FileMode.Open));
string name = "";
while (idx.BaseStream.Position < idx.BaseStream.Length)
{
if (idx.PeekChar() == 0x0A)
{
idx.ReadChar();
if (name.Length > 0)
this.gjdChooser.Items.Add(name.Substring(0, name.IndexOf(" ")));
name = "";
}
else
name += "" + idx.ReadChar();
}
idx.Close();
V2_RL = new List<GJD.RLData>[this.gjdChooser.Items.Count];
for (int i = 0; i < V2_RL.Length; i++)
V2_RL[i] = new List<GJD.RLData>();
this.gjdChooser.Items.Add("Icons");
idx = new System.IO.BinaryReader(new System.IO.FileStream(path + "\\groovie\\dir.rl", System.IO.FileMode.Open));
uint ctr = 0;
while (idx.BaseStream.Position < idx.BaseStream.Length)
{
// Get RL content
GJD.RLData rl = new GJD.RLData();
idx.ReadUInt32();
rl.offset = idx.ReadUInt32();
rl.length = idx.ReadUInt32();
rl.number = ctr;
ctr++;
ushort target = idx.ReadUInt16();
byte[] filename;
filename = idx.ReadBytes(12);
rl.filename = System.Text.Encoding.ASCII.GetString(filename).Trim();
idx.ReadBytes(6);
V2_RL[target].Add(rl);
}
break;
default:
lblGame.Text = "None";
break;
}
}
示例7: LoadData
public override void LoadData(System.IO.FileStream __fsFileStream)
{
System.IO.BinaryReader _brdrReader = new System.IO.BinaryReader(__fsFileStream);
// only read necessary params from file header
__fsFileStream.Seek(42, System.IO.SeekOrigin.Begin);
int _iXDimension = (int)_brdrReader.ReadInt16();
__fsFileStream.Seek(108, System.IO.SeekOrigin.Begin);
DataType _dtDataType = (DataType)_brdrReader.ReadInt16();
__fsFileStream.Seek(656, System.IO.SeekOrigin.Begin);
int _iYDimension = (int)_brdrReader.ReadInt16();
__fsFileStream.Seek(1446, System.IO.SeekOrigin.Begin);
UInt32 numframes = (UInt32)_brdrReader.ReadInt32();
// Start reading the XCalibStruct.
SpeCalib XCalib = new SpeCalib(0, 0);
__fsFileStream.Seek(3000, System.IO.SeekOrigin.Begin);
XCalib.Offset = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3008, System.IO.SeekOrigin.Begin);
XCalib.Factor = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3016, System.IO.SeekOrigin.Begin);
XCalib.current_unit = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3098, System.IO.SeekOrigin.Begin);
XCalib.CalibValid = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3101, System.IO.SeekOrigin.Begin);
XCalib.PolynomOrder = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3263, System.IO.SeekOrigin.Begin);
XCalib.PolynomCoeff[0] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[1] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[2] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[3] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[4] = _brdrReader.ReadDouble();
XCalib.PolynomCoeff[5] = _brdrReader.ReadDouble();
__fsFileStream.Seek(3311, System.IO.SeekOrigin.Begin);
XCalib.LaserPosition = (double)_brdrReader.ReadDouble();
// Start reading the YCalibStruct.
SpeCalib YCalib = new SpeCalib(0, 0);
__fsFileStream.Seek(3489, System.IO.SeekOrigin.Begin); // move ptr to x_calib start
YCalib.Offset = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3497, System.IO.SeekOrigin.Begin);
YCalib.Factor = (double)_brdrReader.ReadDouble();
__fsFileStream.Seek(3505, System.IO.SeekOrigin.Begin);
YCalib.current_unit = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3587, System.IO.SeekOrigin.Begin);
YCalib.CalibValid = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3590, System.IO.SeekOrigin.Begin);
YCalib.PolynomOrder = (char)_brdrReader.ReadChar();
__fsFileStream.Seek(3752, System.IO.SeekOrigin.Begin);
YCalib.PolynomCoeff[0] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[1] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[2] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[3] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[4] = _brdrReader.ReadDouble();
YCalib.PolynomCoeff[5] = _brdrReader.ReadDouble();
__fsFileStream.Seek(3800, System.IO.SeekOrigin.Begin);
YCalib.LaserPosition = (double)_brdrReader.ReadDouble();
int _iDimension;
SpeCalib _calCurrCalib;
if (_iYDimension == 1)
{
_iDimension = _iXDimension;
_calCurrCalib = XCalib;
}
else if (_iXDimension == 1)
{
_iDimension = _iYDimension;
_calCurrCalib = YCalib;
}
else
{
throw new UnexpectedFormatException("xylib does not support 2-D images");
}
__fsFileStream.Seek(4100, System.IO.SeekOrigin.Begin); // move ptr to frames-start
for (int frm = 0; frm < (int)numframes; frm++)
{
Block _blkBlock = new Block();
Column _colXCol = this.GetCalibColumn(_calCurrCalib, _iDimension);
_blkBlock.AddColumn(_colXCol, "", true);
ListColumn _colYCol = new ListColumn();
for (int i = 0; i < _iDimension; ++i)
{
double _dYVal = 0;
switch (_dtDataType)
{
case DataType.SPE_DATA_FLOAT:
_dYVal = (double)_brdrReader.ReadSingle();
break;
case DataType.SPE_DATA_LONG:
_dYVal = (double)_brdrReader.ReadInt32();
break;
//.........这里部分代码省略.........
示例8: ReadDelimitedDataFrom
public static bool ReadDelimitedDataFrom(this System.Text.Encoding encoding, System.IO.Stream stream, char[] delimits, ulong count, out string result, out ulong read, out System.Exception any, bool includeDelimits = true)
{
read = 0;
any = null;
if (delimits == null) delimits = EmptyChar;
if (stream == null || false == stream.CanRead || count == 0)
{
result = null;
return false;
}
//Use default..
if (encoding == null) encoding = System.Text.Encoding.Default;
System.Text.StringBuilder builder = null;
bool sawDelimit = false;
//Make the builder
builder = new System.Text.StringBuilder();
long at = stream.Position;
//Use the BinaryReader on the stream to ensure ReadChar reads in the correct size
//This prevents manual conversion from byte to char and uses the encoding's code page.
using (var br = new System.IO.BinaryReader(stream, encoding, true))
{
//Read a while permitted, check for EOS
while (read < count && stream.CanRead)
{
try
{
//Get the char in the encoding beging used
char cached = br.ReadChar();
read = (ulong)(stream.Position - at);
//If the Byte was a delemit
if (System.Array.IndexOf<char>(delimits, cached) >= 0)
{
//Indicate the delimit was seen
sawDelimit = true;
//if the delemit should be included, include it.
if (includeDelimits) builder.Append(cached);
//Do not read further
goto Done;
}
//Create a string and append
builder.Append(cached);
}
catch (System.Exception ex)
{
any = ex;
read = (ulong)(stream.Position - at);
break;
}
}
}
Done:
if (builder == null)
{
result = null;
return sawDelimit;
}
result = builder.Length == 0 ? string.Empty : builder.ToString();
return sawDelimit;
}
示例9: TryLoadCachedGroup
private bool TryLoadCachedGroup(byte[] data, DateTime lastWriteTime)
{
var timer = System.Diagnostics.Stopwatch.StartNew();
var reader = new BinaryReader(new MemoryStream(data), Encoding.UTF8);
DateTime cacheTime = new DateTime(reader.ReadInt64(), DateTimeKind.Utc);
if (cacheTime != lastWriteTime)
return false;
Dictionary<int, object> objects = new Dictionary<int, object>();
objects.Add(0, null);
// first pass constructs objects
long objectTableOffset = reader.BaseStream.Position;
int objectCount = reader.ReadInt32();
for (int i = 0; i < objectCount; i++)
{
int key = reader.ReadInt32();
object obj = CreateGroupObject(reader, key, objects);
objects.Add(key, obj);
}
reader.BaseStream.Seek(objectTableOffset + 4, SeekOrigin.Begin);
for (int i = 0; i < objectCount; i++)
{
int key = reader.ReadInt32();
LoadGroupObject(reader, key, objects);
}
List<TemplateGroup> importsToClearOnUnload = new List<TemplateGroup>();
Dictionary<string, CompiledTemplate> templates = new Dictionary<string, CompiledTemplate>();
Dictionary<string, IDictionary<string, object>> dictionaries = new Dictionary<string, IDictionary<string, object>>();
// imported groups
int importCount = reader.ReadInt32();
for (int i = 0; i < importCount; i++)
importsToClearOnUnload.Add((TemplateGroup)objects[reader.ReadInt32()]);
// delimiters
char delimiterStartChar = reader.ReadChar();
char delimiterStopChar = reader.ReadChar();
// templates & aliases
int templateCount = reader.ReadInt32();
for (int i = 0; i < templateCount; i++)
{
string key = reader.ReadString();
CompiledTemplate value = (CompiledTemplate)objects[reader.ReadInt32()];
templates[key] = value;
}
// dictionaries
int dictionaryCount = reader.ReadInt32();
for (int i = 0; i < dictionaryCount; i++)
{
string name = reader.ReadString();
IDictionary<string, object> dictionary = new Dictionary<string, object>();
dictionaries[name] = dictionary;
int valueCount = reader.ReadInt32();
for (int j = 0; j < valueCount; j++)
{
string key = reader.ReadString();
object value = objects[reader.ReadInt32()];
dictionary[key] = value;
}
}
this._importsToClearOnUnload.AddRange(importsToClearOnUnload);
this.delimiterStartChar = delimiterStartChar;
this.delimiterStopChar = delimiterStopChar;
foreach (var pair in templates)
this.templates[pair.Key] = pair.Value;
foreach (var pair in dictionaries)
this.dictionaries[pair.Key] = pair.Value;
System.Diagnostics.Debug.WriteLine(string.Format("Successfully loaded the cached group {0} in {1}ms.", Name, timer.ElapsedMilliseconds));
return true;
}
示例10: Deserialize
public static Row Deserialize(byte[] bytes)
{
using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
byte[] columnSet = BR.ReadBytes (32);
int FieldCount = BR.ReadInt32 ();
object[] fields = new object[FieldCount];
ColumnSet cs = css [columnSet];
if (cs.Columns.Length != fields.Length)
throw new Exception ();
for (int n = 0; n != fields.Length; n++) {
bool Null = BR.ReadBoolean ();
if (Null) {
fields [n] = null;
continue;
}
switch (cs.Columns [n].TFQN) {
case "System.Byte[]":
fields [n] = BR.ReadBytes (BR.ReadInt32 ());
break;
case "System.Byte":
fields [n] = BR.ReadByte ();
break;
case "System.SByte":
fields [n] = BR.ReadSByte ();
break;
case "System.Int16":
fields [n] = BR.ReadInt16 ();
break;
case "System.UInt16":
fields [n] = BR.ReadUInt16 ();
break;
case "System.Int32":
fields [n] = BR.ReadInt32 ();
break;
case "System.UInt32":
fields [n] = BR.ReadUInt32 ();
break;
case "System.Int64":
fields [n] = BR.ReadInt64 ();
break;
case "System.UInt64":
fields [n] = BR.ReadUInt64 ();
break;
case "System.Single":
fields [n] = BR.ReadSingle ();
break;
case "System.Double":
fields [n] = BR.ReadDouble ();
break;
case "System.String":
fields [n] = BR.ReadString ();
break;
case "System.Char":
fields [n] = BR.ReadChar ();
break;
case "System.Boolean":
fields [n] = BR.ReadBoolean ();
break;
case "System.DateTime":
fields [n] = new DateTime (BR.ReadInt64 ());
break;
case "System.Guid":
fields [n] = new Guid (BR.ReadBytes (16));
break;
}
}
return new Row (cs, fields);
}
}
}