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


C# BinaryWriter.Dispose方法代码示例

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


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

示例1: EncryptTokenData

        /// <summary>
        /// Encrypts IdentityToken data with the RSA algorithm.
        /// </summary>
        /// <returns>A byte array.</returns>
        public static byte[] EncryptTokenData(this RSA rsa, byte[] dataToEncrypt, string secPolicyUri)
        {
            int cipherTextBlockSize = rsa.KeySize / 8;
            int plainTextBlockSize;
            switch (secPolicyUri)
            {
                case SecurityPolicyUris.Basic128Rsa15:
                    plainTextBlockSize = Math.Max(cipherTextBlockSize - 11, 1);
                    break;

                case SecurityPolicyUris.Basic256:
                    plainTextBlockSize = Math.Max(cipherTextBlockSize - 42, 1);
                    break;

                case SecurityPolicyUris.Basic256Sha256:
                    plainTextBlockSize = Math.Max(cipherTextBlockSize - 42, 1);
                    break;

                default:
                    plainTextBlockSize = 1;
                    break;
            }

            int blockCount = CeilingDivide(dataToEncrypt.Length + 4, plainTextBlockSize);
            int plainTextSize = blockCount * plainTextBlockSize;
            int cipherTextSize = blockCount * cipherTextBlockSize;

            // setup source
            var source = SerializableBytes.CreateWritableStream();
            var writer = new BinaryWriter(source);
            try
            {
                // encode length.
                writer.Write(dataToEncrypt.Length);

                // encode data.
                writer.Write(dataToEncrypt);

                // round up to multiple of plainTextBlockSize
                source.SetLength(plainTextSize);
                source.Seek(0L, SeekOrigin.Begin);

                // setup target
                byte[] cipherText = new byte[cipherTextSize];
                var target = new MemoryStream(cipherText, true);
                try
                {
                    rsa.EncryptStream(source, target, secPolicyUri);
                    return cipherText;
                }
                finally
                {
                    target.Dispose();
                }
            }
            finally
            {
                writer.Dispose();
            }
        }
开发者ID:yuriik83,项目名称:workstation-uaclient,代码行数:64,代码来源:RsaExtensions.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: SendPacket

        public async Task SendPacket(IPacket packet, Stream netStream)
        {
            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            if (packet is IAutoSerializePacket)
                (packet as IAutoSerializePacket).AutoSerialize(bw);
            else
            {
                bw.Write(packet.ID);
                packet.SerializePacket(bw);
            }

            bw.Flush();

            // Copy ms -> redirect writer to new ms -> prepend packet size prefix -> append packet paylod
            FinalizePacket(ref bw);
            ms.Dispose(); // Dispose of expired ms, writer's basestream is created in FinalizePacket
            ms = bw.BaseStream as MemoryStream;
            // this here failed? ye wait a moment
            await netStream.WriteAsync(ms.ToArray(), 0, (int)ms.Length);

            if (OnPacketSent != null)
                OnPacketSent(null, new PacketEventArgs(null, packet, (int)ms.Length));

            ms.Dispose();
            bw.Dispose();

        }
开发者ID:Numbers11,项目名称:uNet,代码行数:29,代码来源:PacketProcessor.cs

示例4: AsymetriycCrypt

        /// <summary>
        /// Metoda za asimetrično kriptiranje
        /// </summary>
        /// <param name="file"></param>
        public void AsymetriycCrypt(string file)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            StreamReader streamReader = new StreamReader("javni_kljuc.txt");
            string publicKey = streamReader.ReadToEnd();
            rsa.FromXmlString(publicKey);
            streamReader.Close();

            string record = file + ".rsa";

            FileStream fstreamU = File.OpenRead(file),
            fstreamO = new FileStream(record, FileMode.Create, FileAccess.ReadWrite);

            BinaryWriter bw = new BinaryWriter(fstreamO);

            BinaryReader binReader = new BinaryReader(fstreamU);
            byte[] bytes = binReader.ReadBytes((int)fstreamU.Length);
            binReader.Close();

            byte[] crypt = rsa.Encrypt(bytes, false);

            bw.Write(crypt);
            bw.Flush();
            bw.Close();
            bw.Dispose();

            fstreamU.Close();
            fstreamU.Dispose();
        }
开发者ID:ivpusic,项目名称:cryptography_algorithms,代码行数:33,代码来源:AsymCryptHelper.cs

示例5: AsymetriycDecrypt

        /// <summary>
        /// Metoda za asimetrično dekriptiranje
        /// </summary>
        /// <param name="file"></param>
        public void AsymetriycDecrypt(string file)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            RSACryptoServiceProvider.UseMachineKeyStore = false;
            StreamReader streamReader = new StreamReader("privatni_kljuc.txt");
            string privateKey = streamReader.ReadToEnd();
            rsa.FromXmlString(privateKey);
            streamReader.Close();

            int indexEcb = file.LastIndexOf(".rsa");
            string zapis = file.Substring(0, indexEcb);

            FileStream fstreamU = File.OpenRead(file),
            fstreamO = new FileStream(zapis, FileMode.Create, FileAccess.ReadWrite);

            BinaryWriter bw = new BinaryWriter(fstreamO);
            BinaryReader binReader = new BinaryReader(fstreamU);
            byte[] bytes = binReader.ReadBytes((int)fstreamU.Length);

            binReader.Close();

            byte[] decrypt = rsa.Decrypt(bytes, false);
            bw.Write(decrypt);

            bw.Flush();
            bw.Close();
            bw.Dispose();

            fstreamU.Close();
            fstreamU.Dispose();
        }
开发者ID:ivpusic,项目名称:cryptography_algorithms,代码行数:35,代码来源:AsymCryptHelper.cs

示例6: Write

        public void Write(string fileName, bool overwrite)
        {
            _stream = new MemoryStream();
            _writer = new BinaryWriter(_stream);

            if (File.Exists(fileName) && !overwrite)
            {
                return;
            }
            
            _writer.Write(_file.Version);
            WriteStringTable();

            WriteBlock(_file.MainBlock);

            string dir = Path.GetDirectoryName(fileName);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            File.WriteAllBytes(fileName, _stream.ToArray());

            _writer.Close();
            _stream.Close();
            _writer.Dispose();
            _stream.Dispose();
        }
开发者ID:andreberg,项目名称:TLII.IO,代码行数:28,代码来源:AdmWriter.cs

示例7: WriteToFileSystem

        public static void WriteToFileSystem(string filename, byte[] input)
        {
            FileStream fs = null;
            BinaryWriter bw = null;
            try
            {
                fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                bw = new BinaryWriter(fs);
                using (var ms = new MemoryStream(input))
                {
                    bw.Write(ms.ToArray());
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Writing to the path '" + filename + "' failed.", ex);
            }
            finally
            {
                if (bw != null)
                {
                    bw.Close();
                    bw.Dispose();
                }

                if (fs != null)
                {
                    fs.Close();
                    fs.Dispose();
                }
            }
        }
开发者ID:devoneonline,项目名称:Tfs-Api,代码行数:32,代码来源:StreamUtility.cs

示例8: button3_Click

 private void button3_Click(object sender, EventArgs e)
 {
     BinaryWriter bw = new BinaryWriter(File.OpenWrite(path));
     //bw.Write(textBox1.Text);
     short myshort = 1;
     byte[] buffer = BitConverter.GetBytes(myshort);
     Array.Reverse(buffer);
     bw.Dispose();
 }
开发者ID:Aniruddha-Tapas,项目名称:C-Sharp-Applications,代码行数:9,代码来源:Form1.cs

示例9: WriteBinaryFile

 public static void WriteBinaryFile(List<char> input) {
     FileStream fs = new FileStream("C:\\TEMP\\BINARY.BIN",FileMode.Create, FileAccess.ReadWrite);
     BinaryWriter bw = new BinaryWriter(fs,System.Text.Encoding.UTF8);
     foreach(char i in input) {
         bw.Write(i);
     }
     bw.Flush();
     bw.Close();
     bw.Dispose();
 }
开发者ID:TheCriticalPath,项目名称:Project-Euler,代码行数:10,代码来源:FileHelper.cs

示例10: button2_Click

 private void button2_Click(object sender, EventArgs e)
 {
     BinaryWriter bw = new BinaryWriter(File.OpenWrite(path));
     short myshort = 1;
     byte[] buffer = BitConverter.GetBytes(myshort);
     Array.Reverse(buffer);//convert bytes in the wrong directions
     bw.Write('C');//write just a character.
     bw.Write(1);//write in wrong direction like before.
     bw.Dispose();
 }
开发者ID:ChrisPaine,项目名称:C-sharp,代码行数:10,代码来源:Form1.cs

示例11: FirmTest

 static void FirmTest(string[] args)
 { 
   FwFile myfirm = new FwFile();
   myfirm.Test(args.Length >1 ? args[2] : Directory.GetCurrentDirectory() + @"\rofs3.fpsx");
   string binfile = Directory.GetFiles( Directory.GetCurrentDirectory() + @"\ROFS2", "?_code.bin" )[0];
   UseExternalTools.ExtractImage(Directory.GetCurrentDirectory(), Directory.GetCurrentDirectory() + @"\ROFS2"+binfile, Directory.GetCurrentDirectory() + @"\ROFSROOT");
   if ( File.Exists( "test.hex" ) )
     File.Delete( "test.hex" );
   BinaryWriter bw = new BinaryWriter( new FileStream( "test.hex", FileMode.CreateNew, FileAccess.Write ) );
   bw.Write( ( int ) 0x01020304 );
   bw.Dispose();
 }
开发者ID:flaithbheartaigh,项目名称:nokias60cenrepeditor,代码行数:12,代码来源:Program.cs

示例12: SetExpertMode

 private static void SetExpertMode(string source, string dest, bool expertMode)
 {
     BinaryReader reader = new BinaryReader(new FileStream(source, FileMode.Open));
     int version = reader.ReadInt32();
     if (version < 149) {
         MessageBox.Show("Error: Outdated terraria version");
         return;
     }
     ulong magic = reader.ReadUInt64();
     if ((magic & 72057594037927935uL) != 27981915666277746uL) {
         MessageBox.Show("Error: Invalid header");
         return;
     }
     // Skip other file metadata...
     reader.ReadBytes(12);
     int positionCount = reader.ReadInt16();
     int afterMetadataPos = reader.ReadInt32();
     int afterHeaderPos = reader.ReadInt32();
     // Skip positions...
     reader.ReadBytes((positionCount - 2) * 4);
     // Skip frame importance...
     reader.ReadBytes(reader.ReadInt16() / 8 + 1);
     if (reader.BaseStream.Position != afterMetadataPos) {
         MessageBox.Show("After Metadata Position Mismatch: expected " +
             afterMetadataPos + ", was " + reader.BaseStream.Position);
         return;
     }
     // Skip the first part of the header...
     reader.ReadString();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     reader.ReadInt32();
     // Get the offset...
     long expertModeFlagOffset = reader.BaseStream.Position;
     bool wasExpertMode = reader.ReadBoolean();
     reader.Dispose();
     // Notify the user if the world is changed...
     if (wasExpertMode == expertMode) {
         MessageBox.Show(expertMode ? "World was already Expert Mode." : "World was already not Expert Mode.");
         return;
     }
     BinaryWriter writer = new BinaryWriter(new FileStream(dest, FileMode.Open));
     writer.BaseStream.Position = expertModeFlagOffset;
     writer.Write(expertMode);
     writer.Dispose();
     MessageBox.Show(expertMode ? "World is now Expert Mode!" : "World is no longer Expert Mode!");
 }
开发者ID:antag99,项目名称:TNoob,代码行数:51,代码来源:TNoob.cs

示例13: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Text File|*.txt";//default type
            sfd.FileName = "MyTextFile";// default name
            sfd.Title = "Save Title"; // title name
            if (sfd.ShowDialog() == DialogResult.OK){

                string path = sfd.FileName;
                BinaryWriter bw = new BinaryWriter(File.Create(path));
                bw.Write("This is a test");
                bw.Dispose();
            }
        }
开发者ID:ChrisPaine,项目名称:C-sharp,代码行数:14,代码来源:Form1.cs

示例14: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     SaveFileDialog sfd = new SaveFileDialog();
     sfd.Filter = "Text File |*.txt";
     sfd.FileName = "MyTextFile";
     sfd.Title = "Save File Dialog";
     if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string path = sfd.FileName;
         BinaryWriter bw = new BinaryWriter(File.Create(path));
         bw.Write("New File");
         bw.Dispose();
     }
 }
开发者ID:Aniruddha-Tapas,项目名称:C-Sharp-Applications,代码行数:14,代码来源:Form1.cs

示例15: SaveFeeds

        public static void SaveFeeds(IEnumerable<Feed> feeds) {
            // Save to temp file first in case of error.
            var tempFileName = Path.GetTempFileName();

            FileStream stream = null;
            BinaryWriter writer = null;

            try {
                stream = File.Open(tempFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                writer = new BinaryWriter(stream);

                writer.Write(SaveHeader);
                writer.Write(SaveVersion);

                writer.Write(feeds.Count());
                foreach (var feed in feeds) {
                    writer.Write(feed.Title);
                    writer.Write(feed.Url);
                    writer.Write(feed.SiteUrl);
                    writer.Write(feed.Description ?? String.Empty);
                    writer.Write(feed.Updated.ToBinary());
                    writer.Write(feed.IsPreserved);
                    writer.Write(feed.Category ?? String.Empty);

                    writer.Write(feed.Items.Count);
                    foreach (var item in feed.Items) {
                        writer.Write(item.Title);
                        writer.Write(item.Url);
                        writer.Write(item.PodcastUrl ?? String.Empty);
                        writer.Write(item.Published.ToBinary());
                        writer.Write(item.Summary);
                        writer.Write(item.IsRead);
                    }
                }
            }
            finally {
                if (writer != null) {
                    writer.Dispose();
                }

                if (stream != null) {
                    stream.Dispose();
                }

                // Copy temp file to actual file.
                File.Copy(tempFileName, GetFeedsPath(), overwrite: true);
                File.Delete(tempFileName);
            }
        }
开发者ID:alexmcbride,项目名称:podcatcherdotnet,代码行数:49,代码来源:FeedSerializer.cs


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