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


C# System.IO.BinaryWriter.Flush方法代码示例

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


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

示例1: TestRaw

        static void TestRaw()
        {
            using (var vorbis = new NVorbis.VorbisReader(@"..\..\..\TestFiles\2test.ogg"))
            using (var outFile = System.IO.File.Create(@"..\..\..\TestFiles\2test.wav"))
            using (var writer = new System.IO.BinaryWriter(outFile))
            {
                writer.Write(Encoding.ASCII.GetBytes("RIFF"));
                writer.Write(0);
                writer.Write(Encoding.ASCII.GetBytes("WAVE"));
                writer.Write(Encoding.ASCII.GetBytes("fmt "));
                writer.Write(18);
                writer.Write((short)1); // PCM format
                writer.Write((short)vorbis.Channels);
                writer.Write(vorbis.SampleRate);
                writer.Write(vorbis.SampleRate * vorbis.Channels * 2);  // avg bytes per second
                writer.Write((short)(2 * vorbis.Channels)); // block align
                writer.Write((short)16); // bits per sample
                writer.Write((short)0); // extra size

                writer.Write(Encoding.ASCII.GetBytes("data"));
                writer.Flush();
                var dataPos = outFile.Position;
                writer.Write(0);

                var buf = new float[vorbis.SampleRate / 10 * vorbis.Channels];
                int count;
                while ((count = vorbis.ReadSamples(buf, 0, buf.Length)) > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        var temp = (int)(32767f * buf[i]);
                        if (temp > 32767)
                        {
                            temp = 32767;
                        }
                        else if (temp < -32768)
                        {
                            temp = -32768;
                        }
                        writer.Write((short)temp);
                    }
                }
                writer.Flush();

                writer.Seek(4, System.IO.SeekOrigin.Begin);
                writer.Write((int)(outFile.Length - 8L));

                writer.Seek((int)dataPos, System.IO.SeekOrigin.Begin);
                writer.Write((int)(outFile.Length - dataPos - 4L));

                writer.Flush();
            }
        }
开发者ID:renaudbedard,项目名称:nvorbis,代码行数:53,代码来源:NAudioDecodingTests.cs

示例2: SerializeVoxelAreaData

		public static byte[] SerializeVoxelAreaData (VoxelArea v) {
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.linkedSpans.Length);
			
			for (int i=0;i<v.linkedSpans.Length;i++) {
				writer.Write(v.linkedSpans[i].area);
				writer.Write(v.linkedSpans[i].bottom);
				writer.Write(v.linkedSpans[i].next);
				writer.Write(v.linkedSpans[i].top);
			}
			
			//writer.Close();
			writer.Flush();
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			stream.Position = 0;
			zip.AddEntry ("data",stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			zip.Save(stream2);
			byte[] bytes = stream2.ToArray();
			stream.Close();
			stream2.Close();
			return bytes;
		}
开发者ID:henryj41043,项目名称:TheUnseen,代码行数:27,代码来源:VoxelClasses.cs

示例3: SerializeVoxelAreaData

		public static byte[] SerializeVoxelAreaData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.linkedSpans.Length);
			
			for (int i=0;i<v.linkedSpans.Length;i++) {
				writer.Write(v.linkedSpans[i].area);
				writer.Write(v.linkedSpans[i].bottom);
				writer.Write(v.linkedSpans[i].next);
				writer.Write(v.linkedSpans[i].top);
			}
			
			//writer.Close();
			writer.Flush();
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			stream.Position = 0;
			zip.AddEntry ("data",stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			zip.Save(stream2);
			byte[] bytes = stream2.ToArray();
			stream.Close();
			stream2.Close();
			return bytes;
#else
			throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
		}
开发者ID:SpacesAdventure,项目名称:Kio-2,代码行数:31,代码来源:VoxelClasses.cs

示例4: CreateSelfSignCertificate

        static void CreateSelfSignCertificate(CertOption option)
        {
            var fileName = option.CertFileName;
            var subject = option.Subject;
            var password = option.Password;

            try
            {
                var securePassword = Certificate.ConvertSecureString(password);
                var startDate = DateTime.Now;
                var endDate = startDate.AddYears(option.Years);
                var certData = Certificate.CreateSelfSignCertificatePfx(subject, startDate, endDate, securePassword);

                using (var writer = new System.IO.BinaryWriter(System.IO.File.Open(fileName, System.IO.FileMode.Create)))
                {
                    writer.Write(certData);
                    writer.Flush();
                    writer.Close();
                }
                securePassword = Certificate.ConvertSecureString(password);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:UrmnafBortHyuga,项目名称:csharplesson,代码行数:26,代码来源:Program.cs

示例5: Save

		public static void Save(string directory, string file,string ext, XCImageCollection images)
		{
			System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Create(directory+"\\"+file+ext));
			foreach(XCImage tile in images)
				bw.Write(tile.Bytes);
			bw.Flush();
			bw.Close();
		}
开发者ID:pmprog,项目名称:OpenXCOM.Tools,代码行数:8,代码来源:UncompressedCollection.cs

示例6: WriteZippedResources

 public void WriteZippedResources()
 {
     using (var binWriter = new System.IO.BinaryWriter(this.fileSystem.File.OpenWrite(MyDhtmlResourceSet.ZippedResources.LocalPath)))
     {
         binWriter.Write(Properties.Resources.Pickles_BaseDhtmlFiles);
         binWriter.Flush();
         binWriter.Close();
     }
 }
开发者ID:Wowbies,项目名称:pickles,代码行数:9,代码来源:DhtmlResourceProcessor.cs

示例7: SaveToFile

 public void SaveToFile(string fileName)
 {
     using(var writer = new System.IO.BinaryWriter(System.IO.File.OpenWrite(fileName)))
     {
         writer.Write(_header);
         writer.Write(_bytes);
         writer.Flush();
     }
 }
开发者ID:ArchSlave,项目名称:Fractal,代码行数:9,代码来源:NetPbm.cs

示例8: Main

        static void Main(string[] args)
        {
            var options = new SwitchOptions();
            if (!CommandLine.ParseArguments(args, options))
                return;

            try
            {
                            if (String.IsNullOrEmpty(options.outFile))
                            {
                                Console.WriteLine("You must supply an outfile.");
                                return;
                            }

                            var source = new System.IO.StreamReader(options.inFile);
                            var lexed = new LexResult();
                            var r = Lexer.Lex(source, lexed);
                            if (r == 0x00)
                            {
                                var destination = System.IO.File.Open(options.outFile, System.IO.FileMode.Create);
                                var writer = new System.IO.BinaryWriter(destination);
                                r = Assembler.Assemble(lexed, writer);
                                writer.Flush();
                                destination.Flush();
                                writer.Close();
                            }
                            Console.WriteLine("Finished with code " + r);
            }
            /*case "emulate":
                        {
                            var source = System.IO.File.Open(options.inFile, System.IO.FileMode.Open);
                            var emulator = new IN8();
                            source.Read(emulator.MEM, 0, 0xFFFF);

                            // Attach devices
                            var teletypeTerminal = new TT3();
                            emulator.AttachHardware(teletypeTerminal, 0x04);

                            while (emulator.STATE_FLAGS == 0x00) emulator.Step();

                            Console.WriteLine(String.Format("Finished in state {0:X2}", emulator.STATE_FLAGS));
                            Console.WriteLine(String.Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2} {7:X2}",
                                emulator.A, emulator.B, emulator.C, emulator.D, emulator.E, emulator.H, emulator.L, emulator.O));
                            Console.WriteLine(String.Format("{0:X4} {1:X4} {2:X8}", emulator.IP, emulator.SP, emulator.CLOCK));
                            break;
                        }
                }
            }*/
            catch (Exception e)
            {
                Console.WriteLine("An error occured.");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
开发者ID:Blecki,项目名称:InnerWorkings,代码行数:55,代码来源:Program.cs

示例9: GetCollisionShape

        public override CollisionShape GetCollisionShape()
        {
            if (collisionShapePtr == null) {
                Terrain t = GetComponent<Terrain>();
                if (t == null)
                {
                    Debug.LogError("Needs to be attached to a game object with a Terrain component." + name);
                    return null;
                }
                BTerrainCollisionObject tco = GetComponent<BTerrainCollisionObject>();
                if (tco == null)
                {
                    Debug.LogError("Needs to be attached to a game object with a BTerrainCollisionObject." + name);
                }
                TerrainData td = t.terrainData;
                int width = td.heightmapWidth;
                int length = td.heightmapHeight;
                float maxHeight = td.size.y;

                //generate procedural data
                byte[] terr = new byte[width * length * sizeof(float)];
                System.IO.MemoryStream file = new System.IO.MemoryStream(terr);
                System.IO.BinaryWriter writer = new System.IO.BinaryWriter(file);

                for (int i = 0; i < length; i++)
                {
                    float[,] row = td.GetHeights(0, i, width, 1);
                    for (int j = 0; j < width; j++)
                    {
                        writer.Write((float)row[0, j] * maxHeight);
                    }
                }

                writer.Flush();
                file.Position = 0;

                pinnedTerrainData = GCHandle.Alloc(terr,GCHandleType.Pinned);

                collisionShapePtr = new HeightfieldTerrainShape(width, length, pinnedTerrainData.AddrOfPinnedObject(), 1f, 0f, maxHeight, upIndex, scalarType, false);
                ((HeightfieldTerrainShape)collisionShapePtr).SetUseDiamondSubdivision(true);
                ((HeightfieldTerrainShape)collisionShapePtr).LocalScaling = new BulletSharp.Math.Vector3(td.heightmapScale.x, 1f, td.heightmapScale.z);
                //just allocated several hundred float arrays. Garbage collect now since 99% likely we just loaded the scene
                GC.Collect();
            }
            return collisionShapePtr;
        }
开发者ID:Cyberbanan,项目名称:BulletSharpUnity3d,代码行数:46,代码来源:BHeightfieldTerrainShape.cs

示例10: WriteToSocket

 private void WriteToSocket(byte[] buffer)
 {
     try
     {
         System.IO.StreamWriter sw = new System.IO.StreamWriter(ns);
         sw.WriteLine(buffer.Length.ToString());
         sw.Flush();
         System.IO.BinaryWriter bw = new System.IO.BinaryWriter(ns);
         System.Console.WriteLine("size of array: " + buffer.Length);
         bw.Write(buffer);
         bw.Flush();
     }
     catch (Exception)
     {
         Idp.DataChanged -= Idp_DataChanged;
         ns.Close();
         SocketForClient.Close();
     }
 }
开发者ID:tordf,项目名称:CameraServer,代码行数:19,代码来源:SocketWriter.cs

示例11: SaveStateBinary

 public byte[] SaveStateBinary()
 {
     var ms = new System.IO.MemoryStream(savebuff2, true);
     var bw = new System.IO.BinaryWriter(ms);
     SaveStateBinary(bw);
     bw.Flush();
     ms.Close();
     return savebuff2;
 }
开发者ID:cas1993per,项目名称:bizhawk,代码行数:9,代码来源:LibRetroEmulator.cs

示例12: DecryptFile

        /// <summary>
        /// Descriptografa um arquivo em outro arquivo.
        /// </summary>
        /// <param name="p_inputfilename">Nome do arquivo de entrada.</param>
        /// <param name="p_outputfilename">Nome do arquivo de saída.</param>
        public void DecryptFile(string p_inputfilename, string p_outputfilename)
        {
            System.IO.FileStream v_inputfile, v_outputfile;
            System.IO.StreamReader v_reader;
            System.IO.BinaryWriter v_writer;
            int v_bytestoread;
            string v_chunk;
            byte[] v_decryptedchunk;

            try
            {
                v_inputfile = new System.IO.FileStream(p_inputfilename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                v_outputfile = new System.IO.FileStream(p_outputfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);

                v_reader = new System.IO.StreamReader(v_inputfile);
                v_writer = new System.IO.BinaryWriter(v_outputfile);

                v_bytestoread = (int) v_inputfile.Length;

                while (! v_reader.EndOfStream)
                {
                    v_chunk = v_reader.ReadLine();

                    // descriptografando
                    v_decryptedchunk = this.DecryptToBytes(v_chunk);

                    // escrevendo porcao descriptografada
                    v_writer.Write(v_decryptedchunk);
                }

                v_reader.Close();
                v_writer.Flush();
                v_writer.Close();
            }
            catch (System.IO.IOException e)
            {
                throw new Spartacus.Utils.Exception(e);
            }
            catch (System.Exception e)
            {
                throw new Spartacus.Utils.Exception(e);
            }
        }
开发者ID:lubota,项目名称:spartacus,代码行数:48,代码来源:Spartacus.Utils.Cryptor.cs

示例13: button1_Click

        // ***** Start pairing (play sound)*****
        private void button1_Click(object sender, EventArgs e)
        {
            if (clsHvcw.GenerateSound(textSSID.Text, textPassword.Text, txtToken) == true)
            {
                // Read sound file
                byte[] buf = System.IO.File.ReadAllBytes(clsHvcw.SoundFile);

                // Stop when sound playing
                if (player != null)
                    StopSound();

                player = new System.Media.SoundPlayer();

                // Wav header definition
                WAVHDR wavHdr = new WAVHDR();

                uint fs = 8000;

                wavHdr.formatid = 0x0001;                                       // PCM uncompressed
                wavHdr.channel = 1;                                             // ch=1 mono
                wavHdr.fs = fs;                                                 // Frequency
                wavHdr.bytespersec = fs * 2;                                    // 16bit
                wavHdr.blocksize = 2;                                           // 16bit mono so block size (byte/sample x # of channels) is 2
                wavHdr.bitspersample = 16;                                      // bit/sample
                wavHdr.size = (uint)buf.Length;                                 // Wave data byte number
                wavHdr.fileSize = wavHdr.size + (uint)Marshal.SizeOf(wavHdr);   // Total byte number

                // Play sound through memory stream
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream((int)wavHdr.fileSize);
                System.IO.BinaryWriter bWriter = new System.IO.BinaryWriter(memoryStream);

                // Write Wav header
                foreach (byte b in wavHdr.getByteArray())
                {
                    bWriter.Write(b);
                }
                // Write PCM data
                foreach (byte data in buf)
                {
                    bWriter.Write(data);
                }
                bWriter.Flush();

                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                player.Stream = memoryStream;

                // Async play
                player.Play();

                // Wait until sound playing is over with following:
                // player.PlaySync();
            }
            else
            {
                MessageBox.Show("Pairing sound creation failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:Qrain,项目名称:photo-tool,代码行数:58,代码来源:Sound.cs

示例14: SaveStateBinary

		public byte[] SaveStateBinary()
		{
			var ms = new System.IO.MemoryStream(SaveStateBuff2, true);
			var bw = new System.IO.BinaryWriter(ms);
			SaveStateBinary(bw);
			bw.Flush();
			if (ms.Position != SaveStateBuff2.Length)
				throw new InvalidOperationException("Unexpected savestate length!");
			bw.Close();
			return SaveStateBuff2;
		}
开发者ID:ddugovic,项目名称:RASuite,代码行数:11,代码来源:QuickNES.cs

示例15: Complete

        /// <summary>
        /// Emits a return statement and finalizes the generated code.  Do not emit any more
        /// instructions after calling this method.
        /// </summary>
        public override unsafe void Complete()
        {
            // Check there aren't any outstanding exception blocks.
            if (this.activeExceptionRegions != null && this.activeExceptionRegions.Count > 0)
                throw new InvalidOperationException("The current method contains unclosed exception blocks.");

            Return();
            FixLabels();
            fixed (byte* bytes = this.bytes)
                this.dynamicILInfo.SetCode(bytes, this.offset, this.maxStackSize);
            this.dynamicILInfo.SetLocalSignature(this.LocalSignature);

            if (this.exceptionRegions != null && this.exceptionRegions.Count > 0)
            {
                // Count the number of exception clauses.
                int clauseCount = 0;
                foreach (var exceptionRegion in this.exceptionRegions)
                    clauseCount += exceptionRegion.Clauses.Count;

                var exceptionBytes = new byte[4 + 24 * clauseCount];
                var writer = new System.IO.BinaryWriter(new System.IO.MemoryStream(exceptionBytes));

                // 4-byte header, see Partition II, section 25.4.5.
                writer.Write((byte)0x41);               // Flags: CorILMethod_Sect_EHTable | CorILMethod_Sect_FatFormat
                writer.Write(exceptionBytes.Length);    // 3-byte data size.
                writer.Flush();
                writer.BaseStream.Seek(4, System.IO.SeekOrigin.Begin);

                // Exception clauses, see Partition II, section 25.4.6.
                foreach (var exceptionRegion in this.exceptionRegions)
                {
                    foreach (var clause in exceptionRegion.Clauses)
                    {
                        switch (clause.Type)
                        {
                            case ExceptionClauseType.Catch:
                                writer.Write(0);                                // Flags
                                break;
                            case ExceptionClauseType.Filter:
                                writer.Write(1);                                // Flags
                                break;
                            case ExceptionClauseType.Finally:
                                writer.Write(2);                                // Flags
                                break;
                            case ExceptionClauseType.Fault:
                                writer.Write(4);                                // Flags
                                break;
                        }
                        writer.Write(exceptionRegion.Start);                    // TryOffset
                        writer.Write(clause.ILStart - exceptionRegion.Start);   // TryLength
                        writer.Write(clause.ILStart);                           // HandlerOffset
                        writer.Write(clause.ILLength);                          // HandlerLength
                        if (clause.Type == ExceptionClauseType.Catch)
                            writer.Write(clause.CatchToken);                    // ClassToken
                        else if (clause.Type == ExceptionClauseType.Filter)
                            writer.Write(clause.FilterHandlerStart);            // FilterOffset
                        else
                            writer.Write(0);
                    }
                }
                writer.Flush();
                this.dynamicILInfo.SetExceptions(exceptionBytes);
            }
        }
开发者ID:leesanghyun2,项目名称:mp-onlinevideos2,代码行数:68,代码来源:DynamicILGenerator.cs


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