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


C# BinaryReader.Dispose方法代码示例

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


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

示例1: BinaryReader_DisposeTests

 public void BinaryReader_DisposeTests()
 {
     // Disposing multiple times should not throw an exception
     using (Stream memStream = CreateStream())
     using (BinaryReader binaryReader = new BinaryReader(memStream))
     {
         binaryReader.Dispose();
         binaryReader.Dispose();
         binaryReader.Dispose();
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:11,代码来源:BinaryReaderTests.cs

示例2: EncodeFile

        public static void EncodeFile(string sourceFilePath, string destinationFilePath)
        {
            FileStream fs_src = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read);
            BinaryReader br_src = new BinaryReader(fs_src);
            FileStream fs_dst = new FileStream(destinationFilePath, FileMode.Open, FileAccess.Write);
            BinaryWriter bw_dst = new BinaryWriter(fs_dst);
            string temp;
            ASCIIEncoding asci = new ASCIIEncoding();
            while (fs_src.Length > fs_src.Position)
            {
                temp = string.Empty;
                temp += (char)br_src.ReadByte();
                if (fs_src.Position + 1 < fs_src.Length)
                    temp += (char)br_src.ReadByte();
                if (fs_src.Position + 1 < fs_src.Length)
                    temp += (char)br_src.ReadByte();
                bw_dst.Write(Convert.ToBase64String(asci.GetBytes(temp)));

            }
            bw_dst.Close();
            bw_dst.Dispose();
            br_src.Close();
            br_src.Dispose();
            fs_src.Close();
            fs_src.Dispose();
            fs_dst.Close();
            fs_dst.Dispose();
            temp = null;
        }
开发者ID:jiashida,项目名称:super-trojan-horse,代码行数:29,代码来源:base64.cs

示例3: HeaderOnly

        private string fileString; //接收header的字符串

        #endregion Fields

        #region Constructors

        //HeaderOnly的构造函数
        public HeaderOnly(string name)
            : base(name)
        {
            fileString = "";
            FileStream fs;                                              //文件流
            fs = new FileStream(name, FileMode.Open, FileAccess.Read); //从文件名读取一个文件流
            string FileString = "";
            fs.Seek(0, SeekOrigin.Begin);              //设置文件开始读取的位置
            BinaryReader reader = new BinaryReader(fs);     //初始化二进制文件读写器,读取文件流
            byte[] b = new byte[20];                   //接收文件内容的byte数组

            //异常处理
            try
            {
                for (int i = 0; i < b.Length; i++)
                {
                    b[i] = reader.ReadByte();                   //将文件内容读入数组
                }
            }
            catch (Exception)
            {
                throw;
            }

            fs.Close();                             //关闭文件流,释放资源
            reader.Dispose();                       //释放二进制读取器的资源

            for (int i = 0; i < b.Length; i++)
            {
                FileString += b[i].ToString("X2");        //将字节数组内容转为字符串(16进制)
            }

            fileString = FileString;
            Console.WriteLine(fileString);
        }
开发者ID:william0227,项目名称:filetype,代码行数:42,代码来源:Program.cs

示例4: CheckAddress

        public bool CheckAddress(long offset, params byte[] bytes)
        {
            try
            {
                using (var br = new BinaryReader(File.Open(binary, FileMode.Open, FileAccess.Read)))
                {
                    br.BaseStream.Seek(offset, SeekOrigin.Begin);

                    for (int i = 0; i < bytes.Length; i++)
                    {
                        if (br.ReadByte() == bytes[i])
                        {
                            Console.WriteLine("Binary already patched!");

                            br.Dispose();

                            return false;
                        }
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}", ex.Message);
            }

            if (File.Exists(binary))
                File.Delete(binary);

            return false;
        }
开发者ID:aceindy,项目名称:ArctiumTools,代码行数:33,代码来源:Patcher.cs

示例5: MakeDigitalSignature

        /// <summary>
        /// Metoda za digitalno potpisivanje dokumenta
        /// </summary>
        /// <param name="file"></param>
        public void MakeDigitalSignature(string file)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            StreamReader streamReader = new StreamReader("privatni_kljuc.txt");
            string publicOnlyKeyXml = streamReader.ReadToEnd();
            rsa.FromXmlString(publicOnlyKeyXml);

            streamReader.Close();
            streamReader.Dispose();

            FileStream dat = new FileStream(file, FileMode.Open, FileAccess.Read);

            BinaryReader binReader = new BinaryReader(dat);
            byte[] data = binReader.ReadBytes((int)dat.Length);
            byte[] sign = rsa.SignData(data, "SHA1");

            binReader.Close();
            binReader.Dispose();
            dat.Close();
            dat.Dispose();

            string datName = file + ".dp";

            TextWriter tw = new StreamWriter(datName);
            tw.WriteLine(Convert.ToBase64String(sign));
            tw.Close();
            tw.Dispose();
        }
开发者ID:ivpusic,项目名称:cryptography_algorithms,代码行数:32,代码来源:DigSignatureHelper.cs

示例6: ReadConvertedFile

 public byte[] ReadConvertedFile()
 {
     var count = 0;
     ReadFileAgain:
     try
     {
         /*
         var ext = Path.GetExtension(FullFilePath);
         if (ext == ".xls" || ext == ".xlsx")
         {
             return ReadXlsxFile();
         }
         */
         using (var fs = new FileStream(FileToSave, FileMode.Open, FileAccess.Read))
         {
             var reader = new BinaryReader(fs);
             _convertedResult = reader.ReadBytes((int)fs.Length);
             reader.Close();
             reader.Dispose();
             fs.Close();
             fs.Dispose();
         }
     }
     catch (Exception)
     {
         System.Threading.Thread.Sleep(100);
         if (++count == 3)
         {
             throw;
         }
         goto ReadFileAgain;
     }
     return _convertedResult;
 }
开发者ID:raovat,项目名称:develop,代码行数:34,代码来源:FileConverter.cs

示例7: TIM

 public TIM(string path, byte arg0 = 0, bool paramsOnly = false)
 {
     this.arg0 = arg0 != 0;
     this.path = path;
     fs = new FileStream(path, FileMode.Open, FileAccess.Read);
     br = new BinaryReader(fs);
     texture = new Texture();
     bpp = RecognizeBPP();
     if (bpp == -1 && arg0==0)
     {
         Console.WriteLine("TIM: This is not TIM texture!");
         return;
     }
     if (arg0 == 0 && !paramsOnly)
     {
         ReadParameters(bpp);
         bmp = DrawTexture();
     }
     if (arg0 == 0 && paramsOnly)
     {
         ReadParameters(bpp);
     }
     br.Dispose();
     fs.Dispose();
 }
开发者ID:MaKiPL,项目名称:FF8-Rinoa-s-Toolset,代码行数:25,代码来源:TIM.cs

示例8: FixChannels

        public void FixChannels(string BRSTMPath, int amount)
        {
            BinaryReader br = new BinaryReader(File.Open(BRSTMPath, FileMode.Open), Encoding.ASCII);
            const string Magic = "DATA";
            int position = 0;
            for (int i = 0; i < br.BaseStream.Length; i += 4)
            {
                if (new String(br.ReadChars(4)) == Magic) //if we find the magic we can stop and we have our position
                {
                    position = i + 4;
                    br.Dispose();
                    br.Close();
                    break;
                }
            }

            BigEndianReader ber = new BigEndianReader(File.Open(BRSTMPath, FileMode.Open));
            ber.BaseStream.Seek(position, SeekOrigin.Begin);
            uint value = ber.ReadUInt32() + 0x20;
            ber.Dispose(); ber.Close();

            BigEndianWriter bw = new BigEndianWriter(File.Open(BRSTMPath, FileMode.Open));
            bw.Seek(position, SeekOrigin.Begin);
            bw.Write(value); bw.Flush(); bw.Close();

            BRSTMPath = '"' + BRSTMPath + '"'; //fix path
            DecodeBRSTM brstm = new DecodeBRSTM();
            brstm.DecodeBRSTMDSP(BRSTMPath, amount); //pass value
        }
开发者ID:ThatOneStruggle,项目名称:multi-channeller,代码行数:29,代码来源:DecodeBRSTM.cs

示例9: CreateFromRawCommand

        /// <summary>
        /// Creates a control command from raw data, starting at a certain offset in the raw data.
        /// </summary>
        /// <param name="rawCommand">The raw control command data.</param>
        /// <param name="startIndex">The start index to extract a control command at.</param>
        /// <returns>A control command that contains the information from the raw representation</returns>
        public static IControlCommand CreateFromRawCommand(byte[] rawCommand, int startIndex)
        {
            // inspect command length
            var length = rawCommand[startIndex];

            // build the memory stream from the range
            var ms = new MemoryStream(rawCommand, startIndex, length);
            var br = new BinaryReader(ms);

            // consume the already known length byte
            length = br.ReadByte();

            // extract the remaining meta data
            var dataType = (DataType)br.ReadInt32();
            var action = (ControlCommandAction)br.ReadInt32();

            ControlCommand command = null;
            if (dataType == DataType.Configuration)
            {
                command = new ConfigurationControlCommand();
            }
            else
            {
                command = new ControlCommand(dataType, action);
            }

            command.Length = length;
            command.ReadData(br);

            br.Dispose();

            return command;
        }
开发者ID:porter1130,项目名称:WP8-DEMO,代码行数:39,代码来源:ControlCommandFactory.cs

示例10: CalcCRC

        static void CalcCRC(string filename)
        {
            Debug.WriteLine(Path.GetFileName(filename));

            var br = new BinaryReader(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
            int len = (int)br.BaseStream.Length;
            if (len <= 2) return;

            var data = br.ReadBytes(len );

            var b1 = data[len-2];
            var b2 = data[len-1];
            //data[len - 2] = 0;
            //data[len - 1] = 0;

            br.Close();
            br.Dispose();

            int file_CRC_1 = (b1 << 8) + b2; //msb

            Debug.WriteLine("F: 0x{0:x4}  ", file_CRC_1);

            int checksum_A = crcBig(data, data.Length - 2, 0x0000, 0x1021);
            Debug.WriteLine("crc 0x0000 0x{0:x4} ", checksum_A);
        }
开发者ID:x86Labs,项目名称:nikon-firmware-tools,代码行数:25,代码来源:CRC.cs

示例11: Open

        public void Open(string fileName)
        {
            reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read));

            if (ReadReversed(reader) != 0x438CB47C)
            {
                Console.WriteLine("Invalid file");
                reader.Close();
                reader.Dispose();
            }

            Unknown1 = ReadReversed(reader);
            NumFilesInTable = ReadReversed(reader);
            Checksum = ReadReversed(reader);
            ChecksumTableSize = ReadReversed(reader);

            Checksums = new int[ChecksumTableSize];

            for (int i = 0; i < ChecksumTableSize; i++)
            {
                Checksums[i] = ReadReversed(reader);
            }

            Entrys = new BkArchiveEntry[NumFilesInTable];

            for (int i = 0; i < NumFilesInTable; i++)
            {
                Entrys[i].ID = ReadReversed(reader);
                Entrys[i].Offset = ReadReversed(reader);
                Entrys[i].Size = ReadReversed(reader);
            }
        }
开发者ID:jarlina,项目名称:PublicXboxStuff,代码行数:32,代码来源:BkArchive.cs

示例12: VerifyDigitalSignature

        /// <summary>
        /// Metoda za verifikaciju ispravnosti digitalnog potpisa dokumenta
        /// </summary>
        /// <param name="file"></param>
        public void VerifyDigitalSignature(string file)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            StreamReader streamReader = new StreamReader("javni_kljuc.txt");
            string publicKey = streamReader.ReadToEnd();
            rsa.FromXmlString(publicKey);
            streamReader.Close();
            streamReader.Dispose();

            FileStream dat = new FileStream(file, FileMode.Open, FileAccess.Read);
            BinaryReader binReader = new BinaryReader(dat);
            byte[] data = binReader.ReadBytes((int)dat.Length);
            string nameP = file + ".dp";

            TextReader streamreader = new StreamReader(nameP);
            string sign = streamreader.ReadLine();
            streamreader.Close();
            streamreader.Dispose();

            if (rsa.VerifyData(data, "SHA1", Convert.FromBase64String(sign)))
            {
                MessageBox.Show("Datoteka je ispravno potpisana", "My Application",
                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
                MessageBox.Show("Datoteka nije ispravno potpisana", "My Application", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            binReader.Close();
            binReader.Dispose();
            dat.Close();
            dat.Dispose();
        }
开发者ID:ivpusic,项目名称:cryptography_algorithms,代码行数:36,代码来源:DigSignatureHelper.cs

示例13: BinaryReader_DisposeTests_Negative

 public void BinaryReader_DisposeTests_Negative()
 {
     using (Stream memStream = CreateStream())
     {
         BinaryReader binaryReader = new BinaryReader(memStream);
         binaryReader.Dispose();
         ValidateDisposedExceptions(binaryReader);
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:9,代码来源:BinaryReaderTests.cs

示例14: button2_Click

 private void button2_Click(object sender, EventArgs e)
 {
     BinaryReader br = new BinaryReader(File.OpenRead(path));
     br.BaseStream.Position = 0x1E;// set read position
     byte[] buffer = br.ReadBytes(2);//Read the wrong order 00 01 = 10 00
     Array.Reverse(buffer); // reverse array to
     textBox1.Text = BitConverter.ToInt16(buffer, 0).ToString("x");//bitconvert to toint16, 32 four bytes use toInt32, ("x") = shows hex, .ToString() = decimal entire number.
     //bitconverter useful = turn a number into byte array.
     br.Dispose();
 }
开发者ID:ChrisPaine,项目名称:C-sharp,代码行数:10,代码来源:Form1.cs

示例15: ExtractFile

 public void ExtractFile(string savePath, Stream file)
 {
     byte[] fileData = new byte[file.Length];
     using (var br = new BinaryReader(file))
     {
         fileData = br.ReadBytes((int)file.Length);
         br.Dispose(); br.Close();
     }
     File.WriteAllBytes(savePath, fileData);
     file.Dispose(); file.Close();
 }
开发者ID:ThatOneStruggle,项目名称:Friendship-ISOEditor,代码行数:11,代码来源:RandFunctions.cs


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