本文整理匯總了C#中System.IO.BinaryReader.PeekChar方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryReader.PeekChar方法的具體用法?C# BinaryReader.PeekChar怎麽用?C# BinaryReader.PeekChar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.IO.BinaryReader
的用法示例。
在下文中一共展示了BinaryReader.PeekChar方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CServerProcessSources
public CServerProcessSources(MemoryStream buffer, uint ServerIP, ushort ServerPort)
{
byte[] FileHash;
uint IP;
ushort Port;
byte nSources;
bool moreFiles = true;
BinaryReader reader = new BinaryReader(buffer);
do
{
FileHash = reader.ReadBytes(16);
nSources = reader.ReadByte();
Debug.WriteLine("Received " + nSources.ToString() + " for " + CKernel.HashToString(FileHash));
while (nSources > 0)
{
IP = reader.ReadUInt32();
Port = reader.ReadUInt16();
nSources--;
CKernel.ClientsList.AddClientToFile(IP, Port, ServerIP, ServerPort, FileHash);
}
if ((reader.PeekChar() != 0) && (reader.PeekChar() != -1))
{
if ((Protocol.ProtocolType)reader.ReadByte() != Protocol.ProtocolType.eDonkey) moreFiles = false;
if ((reader.PeekChar() == -1) || (reader.ReadByte() != (byte)Protocol.ServerCommandUDP.GlobalFoundSources))
moreFiles = false;
}
else moreFiles = false;
}
while (moreFiles);
reader.Close();
buffer.Close();
reader = null;
buffer = null;
}
示例2: ReadDictionary
private static BDictionary ReadDictionary(BinaryReader binaryReader)
{
Contract.Requires(binaryReader != null);
int i = binaryReader.ReadByte();
if (i != 'd')
{
throw Error();
}
BDictionary dict = new BDictionary();
try
{
for (int c = binaryReader.PeekChar(); ; c = binaryReader.PeekChar())
{
if (c == -1) throw Error();
if (c == 'e')
{
binaryReader.ReadByte();
break;
}
BString k = ReadString(binaryReader);
IBElement v = ReadElement(binaryReader);
dict.Add(k, v);
}
}
catch (BencodingException) { throw; }
catch (Exception e) { throw Error(e); }
return dict;
}
示例3: CServerSearchResults
public CServerSearchResults(MemoryStream buffer, CSearcher search, bool esUDP)
{
BinaryReader reader = new BinaryReader(buffer);
if (!esUDP)
{
uint nResultados = reader.ReadUInt32();
for (uint i = 0; i < nResultados; i++)
{
m_ExtractResult(reader, search);
}
search.OnTCPSearchEnded();
}
else
{
m_ExtractResult(reader, search);
while ((reader.PeekChar() != 0) && (reader.PeekChar() != -1))
{
Debug.WriteLine("MoreUDP results in one packet");
if ((Protocol.ProtocolType)reader.ReadByte() != Protocol.ProtocolType.eDonkey) break;
if ((reader.PeekChar() == -1) || (reader.ReadByte() != (byte)Protocol.ServerCommandUDP.GlobalSearchResult))
break;
m_ExtractResult(reader, search);
}
}
reader.Close();
buffer.Close();
reader = null;
buffer = null;
}
示例4: Main
static void Main(string[] args)
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly();
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream("binPath", FileMode.OpenOrCreate, FileAccess.ReadWrite, isf);
try
{
using (BinaryReader binreader = new BinaryReader(isfs))
{
int BinPeek = binreader.PeekChar();
while (BinPeek > 0)
{
Int64 ID = binreader.ReadInt32();
string Name = binreader.ReadString();
Console.WriteLine("Readed binary = " + ID.ToString() + " " + Name);
BinPeek = binreader.PeekChar();
}
}
}
catch (FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
isfs.Close();
Console.ReadKey();
}
Person p = new Person(2, "Pri", 21, DateTime.Parse("27/11/1990"));
isfs = new IsolatedStorageFileStream("binPath", FileMode.OpenOrCreate, FileAccess.ReadWrite, isf);
try
{
BinaryWriter binwriter = new BinaryWriter(isfs);
binwriter.Write(p.ID);
binwriter.Write(p.Name);
binwriter.Write(p.Age);
binwriter.Write(p.Birth.ToString());
binwriter.Flush();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
isfs.Close();
Console.ReadKey();
}
}
示例5: ReadUntilSeparator
private static byte[] ReadUntilSeparator( BinaryReader reader )
{
var bytes = new List<byte>();
int peek = reader.PeekChar();
while( peek != INT_RecordSeparator && peek != INT_EOF)
{
bytes.Add( reader.ReadByte() );
peek = reader.PeekChar();
}
return bytes.ToArray();
}
示例6: StringList
public StringList(string language)
{
this.m_Language = language;
this.m_Table = new Hashtable();
string filePath = Client.GetFilePath(string.Format("cliloc.{0}", (object) language));
if (filePath == null)
{
this.m_Entries = new StringEntry[0];
}
else
{
ArrayList arrayList = new ArrayList();
using (BinaryReader binaryReader = new BinaryReader((Stream) new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
{
binaryReader.ReadInt32();
int num1 = (int) binaryReader.ReadInt16();
while (binaryReader.PeekChar() != -1)
{
int number = binaryReader.ReadInt32();
int num2 = (int) binaryReader.ReadByte();
int count = (int) binaryReader.ReadInt16();
if (count > StringList.m_Buffer.Length)
StringList.m_Buffer = new byte[count + 1023 & -1024];
binaryReader.Read(StringList.m_Buffer, 0, count);
string @string = Encoding.UTF8.GetString(StringList.m_Buffer, 0, count);
arrayList.Add((object) new StringEntry(number, @string));
this.m_Table[(object) number] = (object) @string;
}
}
this.m_Entries = (StringEntry[]) arrayList.ToArray(typeof (StringEntry));
}
}
示例7: WkbBinaryReader
public WkbBinaryReader(Stream stream)
{
_reader = new BinaryReader(stream);
HasData = _reader.PeekChar() != -1;
if (HasData)
Encoding = (WkbEncoding)_reader.ReadByte();
}
示例8: SWFReader
public SWFReader(string SWFFile)
{
Tags = new List<Tag>();
using (BinaryReader b = new BinaryReader(File.Open(SWFFile, FileMode.Open)))
{
if (b.PeekChar() == 'C') //Zlib Compressed
{
Uncompress(b);
}
}
if (SWFBinary == null)
SWFBinary = new BinaryReader(File.Open(SWFFile, FileMode.Open));
ReadSWFHeader();
bool readEndTag = false;
while (SWFBinary.BaseStream.Position < SWFBinary.BaseStream.Length && !readEndTag)
{
Tag b = ReadTag();
if (b != null)
{
if (b is End)
readEndTag = true;
Tags.Add(b);
}
}
}
示例9: StringList
public StringList(string language)
{
this.m_Language = language;
this.m_Table = new Hashtable();
string filePath = Client.GetFilePath(string.Format("cliloc.{0}", language));
if (filePath == null)
{
this.m_Entries = new StringEntry[0];
return;
}
ArrayList arrayLists = new ArrayList();
using (BinaryReader binaryReader = new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)))
{
binaryReader.ReadInt32();
binaryReader.ReadInt16();
while (binaryReader.PeekChar() != -1)
{
int num = binaryReader.ReadInt32();
binaryReader.ReadByte();
int num1 = binaryReader.ReadInt16();
if (num1 > (int)StringList.m_Buffer.Length)
{
StringList.m_Buffer = new byte[num1 + 1023 & -1024];
}
binaryReader.Read(StringList.m_Buffer, 0, num1);
string str = Encoding.UTF8.GetString(StringList.m_Buffer, 0, num1);
arrayLists.Add(new StringEntry(num, str));
this.m_Table[num] = str;
}
}
this.m_Entries = (StringEntry[])arrayLists.ToArray(typeof(StringEntry));
}
示例10: Decrypt
public void Decrypt(string inputFile, string outputFile, string password)
{
byte[] byteKeys = this.GetKey(password);
byte[] ivBytes = this.GetIV();
var decryptor = _symmetricAlgorithm.CreateDecryptor(byteKeys, ivBytes);
int blockSize = _symmetricAlgorithm.BlockSize / 8;
using (var binaryReader = new BinaryReader(File.OpenRead(inputFile), new ASCIIEncoding()))
{
using (var resultFile = File.Create(outputFile))
{
using (var cryptoStream = new CryptoStream(resultFile, decryptor, CryptoStreamMode.Write))
{
using (var binaryWriter = new BinaryWriter(cryptoStream))
{
while (binaryReader.PeekChar() != -1)
{
binaryWriter.Write(binaryReader.ReadBytes(blockSize));
}
}
}
}
}
}
示例11: LoadDirectoriesFromStream
protected void LoadDirectoriesFromStream( BinaryReader reader )
{
Directories = new List<DirectoryEntry>();
while( reader.PeekChar() != INT_RecordSeparator )
{
var entry = CreateDirectoryObject();
char[] buffer = reader.ReadChars( Leader.SizeFieldTag );
string tag = new string( buffer );
if( tag == "0000" )
entry.Tag = DirectoryDataType.Filename;
else if( tag == "0001" )
entry.Tag = DirectoryDataType.DDFRecordIdentifier;
else
entry.Tag = (DirectoryDataType)Enum.Parse( typeof( DirectoryDataType ), tag );
if( entry.Tag == DirectoryDataType.Unknown )
throw new InvalidDataException( String.Format("Unknown tag {0}", tag) );
buffer = reader.ReadChars( Leader.SizeFieldLength );
entry.Length = int.Parse( new string( buffer ) );
buffer = reader.ReadChars( Leader.SizeFieldPos );
entry.Position = int.Parse( new string( buffer ) );
Directories.Add( entry );
}
reader.Read();
}
示例12: GetRowData
private List<KeyValuePair<DDRDirectoryEntry, byte[]>> GetRowData( BinaryReader reader )
{
var rowData = new List<KeyValuePair<DDRDirectoryEntry, byte[]>>();
foreach( DirectoryEntry entry in Directories.OrderBy( dir => dir.Position ) )
{
int peek = reader.PeekChar();
if( peek == INT_RecordSeparator || peek == INT_EOF )
break;
var fieldDescDir = DescriptiveRecord.Directories.OfType<DDRDirectoryEntry>().FirstOrDefault( ddrEntry => ddrEntry.Fields.First() == entry.Tag.GetDescription() );
byte[] block;
if( fieldDescDir.SubFields != null && fieldDescDir.SubFields.Any( field => field.Type == FieldType.Binary ) )
block = reader.ReadBytes( entry.Length - 1 );
else
block = ReadUntilSeparator( reader );
reader.Read();
if( fieldDescDir.Type == DDRDirectoryEntryType.ArrayFieldList )
{
int dataLength = fieldDescDir.SubFields.Sum( field => field.Length.Value );
for( int i = 0; i < block.Length / dataLength; i++ )
{
byte[] subBlock = new byte[ dataLength ];
Array.Copy( block, i * dataLength, subBlock, 0, dataLength );
rowData.Add( new KeyValuePair<DDRDirectoryEntry, byte[]>( fieldDescDir, subBlock ) );
}
}
else
{
rowData.Add( new KeyValuePair<DDRDirectoryEntry, byte[]>( fieldDescDir, block ) );
}
}
return rowData;
}
示例13: button_choose_file_Click
private void button_choose_file_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text files (*.txt)|*.txt";
if (ofd.ShowDialog() == DialogResult.OK)
{
BinaryReader sR = new BinaryReader(File.Open(ofd.FileName, FileMode.Open), Encoding.ASCII);
int i = 0;
while (sR.PeekChar() != -1)
{
i++;
sR.ReadByte();
}
sR.Close();
BinaryReader sR2 = new BinaryReader(File.Open(ofd.FileName, FileMode.Open), Encoding.ASCII);
fileData = sR2.ReadBytes(i);
sR2.Close();
}
textBox1.Text = ofd.FileName.Split('\\')[ofd.FileName.Split('\\').Length-1];
textBox2.Enabled = true;
}
示例14: ReadTapFile
public static TapFile ReadTapFile(Stream inputStream, string fileName)
{
TapFile resultFile = new TapFile(fileName);
using (BinaryReader fileReader = new BinaryReader(inputStream, Encoding.GetEncoding("ISO-8859-1")))
{
while (fileReader.PeekChar() >= 0)
{
TapDataBlock dataBlock = ReadTapDataBlock(fileReader);
resultFile.DataBlocks.Add(dataBlock);
TapeSection section = new TapeSection(dataBlock);
resultFile.Sections.Add(section);
}
}
TapeSection lastSection = resultFile.Sections[resultFile.Sections.Count-1];
TapeSoundSequence lastSoundSequence = lastSection.SoundSequences[lastSection.SoundSequences.Count - 1];
if(lastSoundSequence.GetType() != typeof(PauseSequence))
{
lastSection.SoundSequences.Add(new PauseSequence("End of tape", 1));
}
foreach (TapeSection section in resultFile.Sections)
{
resultFile.Duration += section.Duration;
}
resultFile.Description = ""; // Tap file do not contain metadata
return resultFile;
}
示例15: Parse
public IEnumerable<IAsn1Element> Parse(Stream asn1Stream)
{
using (var reader = new BinaryReader(asn1Stream))
{
while (reader.PeekChar() > -1)
{
var element = GetAsn1ParsedElement(reader);
switch (element.Tag)
{
case 2:
yield return ParseInteger(element);
break;
case 4:
yield return ParseOctetString(element);
break;
case 48:
yield return ParseSequence(element);
break;
default:
yield return new Asn1UnknownElement(element.Tag, element.Data);
break;
}
}
}
}