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


C# BinaryReader.Read方法代码示例

本文整理汇总了C#中System.IO.BinaryReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.Read方法的具体用法?C# BinaryReader.Read怎么用?C# BinaryReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryReader的用法示例。


在下文中一共展示了BinaryReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExexEntry

        public ExexEntry(BinaryReader reader)
            : this()
        {
            auraId = reader.ReadUInt16();
            auraSlot = reader.ReadUInt16();

            particleColor = readColor(reader);
            reader.Read(data1, 0, data1.Length);

            outerGlowColor = readColor(reader);
            innerGlowColor = readColor(reader);
            reader.Read(data2, 0, data2.Length);

            smoke1Color = readColor(reader);
            smoke1Invert = reader.ReadByte() != COLOR_NOT_INVERTED;
            reader.Read(data3, 0, data3.Length);

            smoke2Color = readColor(reader);
            smoke2Invert = reader.ReadByte() != COLOR_NOT_INVERTED;
            reader.Read(data4, 0, data4.Length);

            boltsColor = readColor(reader);
            boltsInvert = reader.ReadByte() != COLOR_NOT_INVERTED;
            reader.Read(data5, 0, data5.Length);
        }
开发者ID:kidaa,项目名称:DissDlcToolkit,代码行数:25,代码来源:ExexEntry.cs

示例2: StreamToHexString

		private static string StreamToHexString(Stream stream)
		{
			byte[] buffer = new byte[4096];

			StringBuilder strB = new StringBuilder(4096);

			using (BinaryReader br = new BinaryReader(stream))
			{
				int byteRead = br.Read(buffer, 0, buffer.Length);

				while (byteRead > 0)
				{
					for (int i = 0; i < byteRead; i++)
					{
						if (strB.Length == 0)
							strB.Append("0X");

						strB.AppendFormat("{0:X2}", buffer[i]);
					}

					byteRead = br.Read(buffer, 0, buffer.Length);
				}
			}

			if (strB.Length == 0)
				strB.Append("NULL");

			return strB.ToString();
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:29,代码来源:StreamDescriptionGenerator.cs

示例3: Read

        public void Read(Stream stream)
        {
            BinaryReader reader = new BinaryReader (stream);
                int headerSize = IPAddress.NetworkToHostOrder(reader.ReadInt32());
                int keySize = IPAddress.NetworkToHostOrder(reader.ReadInt32());
                int valueSize = IPAddress.NetworkToHostOrder(reader.ReadInt32());
                int packetVersion = reader.ReadByte();
                if (packetVersion != PACKET_VERSION)
                {
                    //throw new Exception("Packet versions do not match. Expected " + PACKET_VERSION + " but found " + packetVersion);
                }
                readHeader(reader);

                try
                {
                    this.key = new byte[keySize];
                    if (keySize > 0)
                        reader.Read(this.key, 0, keySize);
                    this.value = new byte[valueSize];
                    if (valueSize > 0)
                    {
                        int x = reader.Read(this.value, 0, valueSize);
                        if (x != valueSize) {
                            Console.WriteLine("Esit degil: " + x + "::" + valueSize + "");
                            Thread.Sleep(10000);
                        }
                    }
                }catch (Exception e) {
                    Console.WriteLine("Keysize" + keySize + ": " + valueSize);
                    Console.WriteLine(e.StackTrace);
                }
        }
开发者ID:fuadm,项目名称:csharp-mini-hazelcast-client,代码行数:32,代码来源:Packet.cs

示例4: Close

 public void Close()
 {
     if (writer == null)
         return;
     writer.Close();
     writer = null;
     using (BinaryWriter bw2 = new BinaryWriter(wavR.OpenResourceForWrite()))
     {
         bw2.Write((Int32)1179011410);
         bw2.Write((Int32)44 + length - 8);
         bw2.Write((Int32)1163280727);
         bw2.Write((Int32)544501094);
         bw2.Write((Int32)16);
         bw2.Write((Int16)1);
         bw2.Write((Int16)channels);
         bw2.Write((Int32)sRate);
         bw2.Write((Int32)(sRate * channels * (bits / 8)));
         bw2.Write((Int16)(channels * (bits / 8)));
         bw2.Write((Int16)bits);
         bw2.Write((Int32)1635017060);
         bw2.Write((Int32)length);
         using (BinaryReader br = new BinaryReader(tempR.OpenResourceForRead()))
         {
             byte[] buffer = new byte[1024];
             int count = br.Read(buffer, 0, buffer.Length);
             while (count > 0)
             {
                 bw2.Write(buffer, 0, count);
                 count = br.Read(buffer, 0, buffer.Length);
             }
         }
     }
     tempR.DeleteResource();
 }
开发者ID:n-yoda,项目名称:unity-midi,代码行数:34,代码来源:WaveFileWriter.cs

示例5: GetImageFromUrl

        public static BitmapImage GetImageFromUrl(string url)
        {
            var image = new BitmapImage();
            int BytesToRead = 100;
            var responseStream = Network.GetStream(url);
            if (responseStream == null)
            {
                return null;
            }
            BinaryReader reader = new BinaryReader(responseStream);
            MemoryStream memoryStream = new MemoryStream();

            byte[] bytebuffer = new byte[BytesToRead];
            int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);

            while (bytesRead > 0)
            {
                memoryStream.Write(bytebuffer, 0, bytesRead);
                bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
            }

            image.BeginInit();
            memoryStream.Seek(0, SeekOrigin.Begin);

            image.StreamSource = memoryStream;
            image.EndInit();

            return image;
        }
开发者ID:salterok,项目名称:vkSuite,代码行数:29,代码来源:Helper.cs

示例6: cryptBtn_Click

        private void cryptBtn_Click(object sender, EventArgs e)
        {
            // Copy header
            byte[] header = new byte[54];
            List<Byte> body = new List<byte>();
            byte[] temp = new byte[1];

            using (BinaryReader sourceF = new BinaryReader(File.Open(this.selFileTb.Text, FileMode.Open)))
            {
                sourceF.Read(header, 0, header.Length);
                using (BinaryWriter newF = new BinaryWriter(File.Open(this.newFileTb.Text, FileMode.OpenOrCreate)))
                {
                    newF.Write(header, 0, header.Length);
                    int len = 0;
                    while (sourceF.BaseStream.Position != sourceF.BaseStream.Length)
                    {
                        sourceF.Read(temp, 0, 1);
                        body.Add(temp[0]);
                        len++;
                    }
                    byte[] b = body.ToArray();

                    newF.Write(this.Crypt(b), 0, len);
                }
            }
        }
开发者ID:lordmilutin,项目名称:rc4forBMP,代码行数:26,代码来源:Form1.cs

示例7: LoadElf

        public static void LoadElf(string FileName, SPU spu, bool setProgramCounter)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(FileName));
            // GetElfHeader
            byte[] elfMagic = new byte[4];
            br.Read(elfMagic, 0, 4);
            if (elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F ||
                elfMagic[0] != 0x7F)
            {
                MessageBox.Show("Elf Magic Wrong (" + FileName + ")");
                return;
            }
            br.BaseStream.Seek(0, SeekOrigin.Begin);
            byte[] eHDR = new byte[0x34];
            br.Read(eHDR, 0, eHDR.Length);
            uint phdr_offset = ConversionUtil.byteToUInt(eHDR, 0x1C);
            ushort n_phdrs = ConversionUtil.byteToUShort(eHDR, 0x2C);
            for (ushort i = 0; i < n_phdrs; i++)
            {
                int error = LoadElfPHDR(br, spu, phdr_offset, i);
                if (error == 1)
                    MessageBox.Show("Didn't Load phdr " + i + " of File " + FileName);
                else if (error == 2)
                    MessageBox.Show("Local Storage Overflow!");
            }

            if (setProgramCounter)
                spu.IP = ConversionUtil.byteToUInt(eHDR, 0x18);
            br.Close();
        }
开发者ID:Inviction,项目名称:PS3Tools,代码行数:32,代码来源:FileLoader.cs

示例8: FindFiles

        public static List<DATFile> FindFiles(DAT dat, BinaryReader br)
        {
            List<DATFile> DatFiles = new List<DATFile>();

            uint FileIndex = 0;
            br.BaseStream.Seek(-(dat.TreeSize + 4), SeekOrigin.End);
            while (FileIndex < dat.FilesTotal)
            {
                DATFile file = new DATFile();
                file.br = br;
                file.FileNameSize = br.ReadInt32();
                char[] namebuf = new Char[file.FileNameSize];
                br.Read(namebuf, 0, (int)file.FileNameSize);
                file.Path = new String(namebuf, 0, namebuf.Length);
                file.FileName = Path.GetFileName(file.Path);
                file.Compression = br.ReadByte();
                file.UnpackedSize = br.ReadInt32();
                file.PackedSize = br.ReadInt32();
                if (file.Compression==0x00&&(file.UnpackedSize != file.PackedSize))
                        file.Compression = 1;
                file.Offset = br.ReadInt32();
                long oldoffset = br.BaseStream.Position;
                // Read whole file into a buffer
                br.BaseStream.Position = file.Offset;
                file.Buffer = new Byte[file.PackedSize];
                br.Read(file.Buffer, 0, file.PackedSize);
                br.BaseStream.Position = oldoffset;

                DatFiles.Add(file);
                FileIndex++;
            }
            return DatFiles;
        }
开发者ID:SnakeSolidNL,项目名称:CritterBrowser,代码行数:33,代码来源:DATReader.cs

示例9: GetModuleFromSSHPublicKeyString

        // MEMO:
        // The purpose of using"IPAddress.NetworkToHostOrder()" method is changing endian from big endian to little endian.

        public static IEnumerable<byte[]> GetModuleFromSSHPublicKeyString(string pubKeySSHFormat)
        {
            if (string.IsNullOrEmpty(pubKeySSHFormat)) yield break;

            // Split each rows
            var pubKeyBodies = pubKeySSHFormat
                .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(row => row.Trim().Split(' ', '\t').Last());

            foreach (var pubKeyBody in pubKeyBodies)
            {
                var pubKeyBin = Convert.FromBase64String(pubKeyBody);
                using (var ms = new MemoryStream(pubKeyBin))
                using (var binReader = new BinaryReader(ms))
                {
                    // Get byte size of algorithm name.
                    var sizeOfAlgorithmName = IPAddress.NetworkToHostOrder(binReader.ReadInt32());
                    // Read and drop algorithm name (generally, this is "ssh-rsa" 7 bytes).
                    binReader.Read(new byte[sizeOfAlgorithmName], 0, sizeOfAlgorithmName);

                    // Get byte size of exponent.
                    var sizeOfExponent = IPAddress.NetworkToHostOrder(binReader.ReadInt32());
                    // Read and drop exponent.
                    binReader.Read(new byte[sizeOfExponent], 0, sizeOfExponent);

                    // Get byte size of module.
                    var sizeOfModule = IPAddress.NetworkToHostOrder(binReader.ReadInt32());
                    // Read module and return it.
                    var module = new byte[sizeOfModule];
                    binReader.Read(module, 0, sizeOfModule);
                    yield return module;
                }
            }
        }
开发者ID:KatsuYuzu,项目名称:clickonce-get,代码行数:37,代码来源:CertificateValidater.cs

示例10: GetImageFromUrl

        private static BitmapImage GetImageFromUrl(string url)
        {
            var image = new BitmapImage();
            const int bytesToRead = 100;
            var request =
                WebRequest.Create(
                    new Uri(url, UriKind.Absolute));
            request.Timeout = -1;
            var response = request.GetResponse();
            var responseStream = response.GetResponseStream();
            if (responseStream != null)
            {
                var reader = new BinaryReader(responseStream);
                var memoryStream = new MemoryStream();

                var bytebuffer = new byte[bytesToRead];
                var bytesRead = reader.Read(bytebuffer, 0, bytesToRead);

                while (bytesRead > 0)
                {
                    memoryStream.Write(bytebuffer, 0, bytesRead);
                    bytesRead = reader.Read(bytebuffer, 0, bytesToRead);
                }

                image.BeginInit();
                memoryStream.Seek(0, SeekOrigin.Begin);

                image.StreamSource = memoryStream;
            }
            image.EndInit();
            return image;
        }
开发者ID:etiennepierrot,项目名称:LastFm2Gtalk,代码行数:32,代码来源:MainWindow.xaml.cs

示例11: ObjectEntry

        public ObjectEntry(BinaryReader reader)
            : this()
        {
            id = reader.ReadUInt16();
            data1 = reader.ReadUInt16();
            data2 = reader.ReadUInt16();
            characterId = reader.ReadByte();
            costumeId = reader.ReadByte();
            objectEntryType = reader.ReadByte();
            objectEntrySlot = reader.ReadByte();

            for (int i = 0; i < MODEL_DATA_BYTES; i++)
            {
                modelData[i] = reader.ReadByte();
            }

            for (int i = 0; i < ATTACHMENT_IDS_ARRAY_SIZE; i++)
            {
                attachmentIds[i] = reader.ReadUInt16();
            }
            byte[] buffer = new byte[16];
            reader.Read(buffer, 0, 16);
            modelName = Encoding.ASCII.GetString(buffer).TrimEnd('\0');

            buffer = new byte[16];
            reader.Read(buffer, 0, 16);
            objxName = Encoding.ASCII.GetString(buffer).TrimEnd('\0');
        }
开发者ID:kidaa,项目名称:DissDlcToolkit,代码行数:28,代码来源:ObjectEntry.cs

示例12: icon

        protected BitmapImage icon(string url)
        {
            var image = new BitmapImage();
            int BytesToRead = 100;

            WebRequest request = WebRequest.Create(new Uri(url, UriKind.Absolute));
            request.Timeout = -1;
            WebResponse response = request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            BinaryReader reader = new BinaryReader(responseStream);
            MemoryStream memoryStream = new MemoryStream();

            byte[] bytebuffer = new byte[BytesToRead];
            int bytesRead = reader.Read(bytebuffer, 0, BytesToRead);

            while (bytesRead > 0)
            {
                memoryStream.Write(bytebuffer, 0, bytesRead);
                bytesRead = reader.Read(bytebuffer, 0, BytesToRead);
            }

            image.BeginInit();
            memoryStream.Seek(0, SeekOrigin.Begin);

            image.StreamSource = memoryStream;
            image.EndInit();
            return image;
        }
开发者ID:zhaidy,项目名称:Box,代码行数:28,代码来源:MainWindow.xaml.cs

示例13: ParseInfo

 public void ParseInfo(long pos, string filePath)
 {
     byte[] array = new byte[100000];
     BinaryReader binaryReader = new BinaryReader(File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read));
     try
     {
         binaryReader.BaseStream.Position = pos + VolumePathOffset;
         binaryReader.Read(array, 0, VolumePathLength*2);
         string name = Encoding.Unicode.GetString(array).TrimEnd('\0'); //bytestostring_littleendian(array);
         binaryReader.BaseStream.Position = pos + FolderPathOffset;
         List<string> iFolderPaths = new List<string>();
         for (int i = 0; i < NumFolderPaths; i++)
         {
             byte[] array2 = new byte[100000];
             binaryReader.Read(array2, 0, 2);
             uint len = BitConverter.ToUInt16(array2, 0);
             binaryReader.Read(array2, 0, (int)len*2);
             string szPath = Encoding.Unicode.GetString(array2).TrimEnd('\0');
             if (szPath != "")
                 iFolderPaths.Add(szPath);
             binaryReader.Read(array2, 0, 2);
         }
         FolderPaths = iFolderPaths.ToArray();
     }
     finally
     {
         binaryReader.Close();
     }
 }
开发者ID:jacobsoo,项目名称:PrefetchParser,代码行数:29,代码来源:PrefetchVolInfoClass.cs

示例14: ValidateDisposedExceptions

        private void ValidateDisposedExceptions(BinaryReader binaryReader)
        {
            byte[] byteBuffer = new byte[10];
            char[] charBuffer = new char[10];

            Assert.Throws<ObjectDisposedException>(() => binaryReader.PeekChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(byteBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.Read(charBuffer, 0, 1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBoolean());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadBytes(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChar());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadChars(1));
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDecimal());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadDouble());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadInt64());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSByte());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadSingle());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadString());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt16());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt32());
            Assert.Throws<ObjectDisposedException>(() => binaryReader.ReadUInt64());
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:26,代码来源:BinaryReaderTests.cs

示例15: ListFiles

        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            byte[] buf = new byte[4];
            BinaryReader rd = new BinaryReader(strm);
            int numFiles;
            List<FileEntry> results = new List<FileEntry>();

            rd.Read(buf, 0, 4);
            if (Encoding.ASCII.GetString(buf, 0, 4) != "TGP0")
                return results;

            if (rd.ReadInt32() != 1)  // version check
                return results;

            if (rd.ReadInt32() != 0)  // should be zero
                return results;

            numFiles = rd.ReadInt32();
            buf = new byte[0x60];
            for (int i = 0; i < numFiles; i++)
            {
                FileEntry ent = new FileEntry();

                rd.Read(buf, 0, 0x60);
                ent.Filename = Encoding.ASCII.GetString(buf);
                ent.Filename = ent.Filename.Substring(0, ent.Filename.IndexOf('\0'));
                ent.Offset = rd.ReadInt64();
                ent.UncompressedSize = rd.ReadInt64();

                results.Add(ent);
            }

            return results;
        }
开发者ID:darkstar,项目名称:gus,代码行数:34,代码来源:TGPUnpacker.cs


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