当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.PeekChar方法代码示例

本文整理汇总了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;
 }
开发者ID:elnomade,项目名称:hathi,代码行数:34,代码来源:CServerProcessSources.cs

示例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;
        }
开发者ID:JoeRall,项目名称:UTorrentClientApi,代码行数:32,代码来源:BinaryBencoding.cs

示例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;
 }
开发者ID:elnomade,项目名称:hathi,代码行数:29,代码来源:CServerSearchResults.cs

示例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();
            }
        }
开发者ID:Rafael-Miceli,项目名称:ProjectStudiesCert70-536,代码行数:56,代码来源:Program.cs

示例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();
        }
开发者ID:PeteFohl,项目名称:SDTS-Browser,代码行数:13,代码来源:DataRecord.cs

示例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));
       }
 }
开发者ID:HankTheDrunk,项目名称:ultimaonlinemapcreator,代码行数:32,代码来源:StringList.cs

示例7: WkbBinaryReader

 public WkbBinaryReader(Stream stream)
 {
     _reader = new BinaryReader(stream);
     HasData = _reader.PeekChar() != -1;
     if (HasData)
         Encoding = (WkbEncoding)_reader.ReadByte();
 }
开发者ID:spadger,项目名称:Geo,代码行数:7,代码来源:WkbBinaryReader.cs

示例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);
                }
            }
        }
开发者ID:Gratin,项目名称:LegendaryClient,代码行数:27,代码来源:SWFReader.cs

示例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));
 }
开发者ID:HankTheDrunk,项目名称:ultimaonlinemapcreator,代码行数:32,代码来源:StringList.cs

示例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));
                            }
                        }
                    }
                }
            }
        }
开发者ID:RamanBut-Husaim,项目名称:ZIRKSiS,代码行数:25,代码来源:CryptoManager.cs

示例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();
        }
开发者ID:PeteFohl,项目名称:SDTS-Browser,代码行数:25,代码来源:Record.cs

示例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;
        }
开发者ID:PeteFohl,项目名称:SDTS-Browser,代码行数:34,代码来源:DataRecord.cs

示例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;
        }
开发者ID:kolyamba8,项目名称:Cryptography,代码行数:26,代码来源:Form1.cs

示例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;
        }
开发者ID:laurentprudhon,项目名称:ZxSpectrumSimulator,代码行数:30,代码来源:TapFileReader.cs

示例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;
                    }
                }
            }
        }
开发者ID:Xamarui,项目名称:acme.net,代码行数:26,代码来源:Asn1Parser.cs


注:本文中的System.IO.BinaryReader.PeekChar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。