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


C# IO.BinaryWriter类代码示例

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


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

示例1: Save

        public void Save()
        {
            Close();

            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            Count = Images.Count;
            IndexList.Clear();

            int offSet = 8 + Count * 4;
            for (int i = 0; i < Count; i++)
            {
                IndexList.Add((int)stream.Length + offSet);
                Images[i].Save(writer);
                //Images[i] = null;
            }

            writer.Flush();
            byte[] fBytes = stream.ToArray();
            //  writer.Dispose();

            _stream = File.Create(FileName);
            writer = new BinaryWriter(_stream);
            writer.Write(LibVersion);
            writer.Write(Count);
            for (int i = 0; i < Count; i++)
                writer.Write(IndexList[i]);

            writer.Write(fBytes);
            writer.Flush();
            writer.Close();
            writer.Dispose();
            Close();
        }
开发者ID:Pete107,项目名称:Mir2,代码行数:35,代码来源:MLibraryV2.cs

示例2: CustomAttributeWriter

		CustomAttributeWriter(ICustomAttributeWriterHelper helper) {
			this.helper = helper;
			this.recursionCounter = new RecursionCounter();
			this.outStream = new MemoryStream();
			this.writer = new BinaryWriter(outStream);
			this.genericArguments = null;
		}
开发者ID:GodLesZ,项目名称:ConfuserDeobfuscator,代码行数:7,代码来源:CustomAttributeWriter.cs

示例3: WriteMagic

 static void WriteMagic(BinaryWriter writer)
 {
     foreach (char magic in spriteFontMagic)
     {
         writer.Write((byte)magic);
     }
 }
开发者ID:Grave,项目名称:DxEngine,代码行数:7,代码来源:SpriteFontWriter.cs

示例4: WriteStatic

 private void WriteStatic(BinaryWriter bw, HuedTile stat)
 {
     bw.Write((ushort)stat.ID);
     bw.Write((ushort)0);
     bw.Write((sbyte)stat.Z);
     bw.Write((ushort)stat.Hue);
 }
开发者ID:cbnolok,项目名称:SphereSvrSource,代码行数:7,代码来源:BlockWriter.cs

示例5: Save

        public void Save(Stream output)
        {
            BinaryWriter writer = new BinaryWriter(output);

            writer.Write(this.version);
            writer.Write((int)0);
            writer.Write((int)0);

            // Double the string length since it's UTF16
            writer.Write((byte)(this.partName.Length * 2));
            MadScience.StreamHelpers.WriteStringUTF16(output, false, this.partName);

            writer.Write(this.blendType);
            this.blendTgi.Save(output);

            writer.Write((uint)this.geomBoneEntries.Count);
            for (int i = 0; i < this.geomBoneEntries.Count; i++)
            {
                this.geomBoneEntries[i].Save(output);
            }

            uint tgiOffset = (uint)output.Position - 8;
            // Why is this +12?  I dunno. :)
            this.keytable.size = 8;
            this.keytable.Save(output);
            output.Seek(4, SeekOrigin.Begin);
            writer.Write(tgiOffset);
            writer.Write(this.keytable.size);

            writer = null;
        }
开发者ID:ellacharmed,项目名称:madscientistproductions,代码行数:31,代码来源:FacialBlend.cs

示例6: Write

        /// <summary>
        /// 
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="writer"></param>
        public void Write(IPolygon polygon, BinaryWriter writer)
        {
            writer.Write((int) ShapeGeometryTypes.Polygon);

            // Write BoundingBox            
            WriteBoundingBox(polygon, writer);

            // Write NumParts and NumPoints            
            writer.Write((int) (polygon.NumInteriorRings + 1));
            writer.Write((int)  polygon.NumPoints);

            // Write IndexParts
            int count = 0;
            writer.Write((int) count);
            if (polygon.NumInteriorRings != 0)
            {
                // Write external shell index
                count += polygon.ExteriorRing.NumPoints;
                writer.Write((int) count);
                for (int i = 1; i < polygon.NumInteriorRings; i++)
                {
                    // Write internal holes index
                    count += polygon.GetInteriorRingN(i - 1).NumPoints;
                    writer.Write((int) count);
                }
            }

            // Write Coordinates
            for (int i = 0; i < polygon.NumPoints; i++)
                Write(polygon.Coordinates[i], writer);
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:36,代码来源:ShapeWriter.cs

示例7: WaveFileWriter

        /// <summary>
        /// Creates a <see cref="WaveFileWriter"/> that writes to a <see cref="Stream"/>.
        /// </summary>
        public WaveFileWriter(Stream outStream, WaveFormat format)
        {
            _ofstream = outStream;
            _writer = new BinaryWriter(outStream, UTF8);

            _writer.Write(UTF8.GetBytes("RIFF"));
            _writer.Write(0); // placeholder
            _writer.Write(UTF8.GetBytes("WAVEfmt "));
            _waveFormat = format;

            _writer.Write(18 + format.ExtraSize); // wave format Length
            format.Serialize(_writer);

            // CreateFactChunk
            if (format.Encoding != WaveFormatTag.Pcm)
            {
                _writer.Write(UTF8.GetBytes("fact"));
                _writer.Write(4);
                _factSampleCountPos = outStream.Position;
                _writer.Write(0); // number of samples
            }

            // WriteDataChunkHeader
            _writer.Write(UTF8.GetBytes("data"));
            _dataSizePos = outStream.Position;
            _writer.Write(0); // placeholder

            Length = 0;
        }
开发者ID:ManagedBass,项目名称:ManagedBass,代码行数:32,代码来源:WaveFileWriter.cs

示例8: Main

        static void Main(string[] args)
        {
            FileStream filStream;
            BinaryWriter binWriter;

            Console.Write("Enter name of the file: ");
            string fileName = Console.ReadLine();
            if (File.Exists(fileName))
            {
                Console.WriteLine("File - {0} already exists!", fileName);
            }
            else
            {
                filStream = new FileStream(fileName, FileMode.CreateNew);
                binWriter = new BinaryWriter(filStream);
                decimal aValue = 2.16M;
                binWriter.Write("Sample Run");
                for (int i = 0; i < 11; i++)
                {

                    binWriter.Write(i);
                }
                binWriter.Write(aValue);

                binWriter.Close();
                filStream.Close();
                Console.WriteLine("File Created successfully");
            }

            Console.ReadKey();
        }
开发者ID:moeen-aqrabawi,项目名称:C-.NET,代码行数:31,代码来源:BinaryExample.cs

示例9: TestIncompleteRewind

 public void TestIncompleteRewind()
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(ms);
     bw.Write(1);
     bw.Write(2);
     bw.Write(3);
     bw.Write(4);
     bw.Write(5);
     bw.Write(6);
     bw.Write(7);
     bw.Flush();
     ms.Position = 0;
     RewindableStream stream = new RewindableStream(ms);
     stream.StartRecording();
     BinaryReader br = new BinaryReader(stream);
     Assert.AreEqual(br.ReadInt32(), 1);
     Assert.AreEqual(br.ReadInt32(), 2);
     Assert.AreEqual(br.ReadInt32(), 3);
     Assert.AreEqual(br.ReadInt32(), 4);
     stream.Rewind(true);
     Assert.AreEqual(br.ReadInt32(), 1);
     Assert.AreEqual(br.ReadInt32(), 2);
     stream.StartRecording();
     Assert.AreEqual(br.ReadInt32(), 3);
     Assert.AreEqual(br.ReadInt32(), 4);
     Assert.AreEqual(br.ReadInt32(), 5);
     stream.Rewind(true);
     Assert.AreEqual(br.ReadInt32(), 3);
     Assert.AreEqual(br.ReadInt32(), 4);
     Assert.AreEqual(br.ReadInt32(), 5);
     Assert.AreEqual(br.ReadInt32(), 6);
     Assert.AreEqual(br.ReadInt32(), 7);
 }
开发者ID:yaozd,项目名称:sharpcompress,代码行数:34,代码来源:RewindableStreamTest.cs

示例10: DeCrypting

 private static string DeCrypting()
 {
     var res = string.Empty;
     var file = new FileStream(Controller.GetPath(), FileMode.Open, FileAccess.Read, FileShare.None, 32, FileOptions.SequentialScan);
     var reader = new BinaryReader(file);
     var writer = new BinaryWriter(new FileStream(Processor.GetNewName(Controller.GetPath()), FileMode.Create, FileAccess.Write,
         FileShare.None, 32, FileOptions.WriteThrough));
     try
     {
         var pos = 0;
         while (pos < file.Length)
         {
             var c = reader.ReadUInt16();
             //var pow = Processor.fast_exp(c, Controller.GetKc(), Controller.GetR());
             var pow = Processor.Pows(c, Controller.GetKc(), Controller.GetR());
             if (pos < 256) res += pow + " ";
             writer.Write((byte)(pow));
             pos += 2;
         }
     }
     finally
     {
         writer.Close();
         reader.Close();
     }
     return "Decoding Complete!\n" + res;
 }
开发者ID:Emaxan,项目名称:TI_Laba4_RSA,代码行数:27,代码来源:Decoding.cs

示例11: DiscordAudioPacket

        public DiscordAudioPacket(char seq, int timestamp, int ssrc, byte[] encodedaudio)
        {
            this.seq = seq;
            this.timestamp = timestamp;
            this.ssrc = ssrc;
            this.encodedAudio = encodedaudio;

            byte[] fullPacket = new byte[RTP_HEADER_BYTE_LENGTH + encodedAudio.Length];
            using (MemoryStream ms = new MemoryStream(fullPacket))
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                {
                    writer.BaseStream.Position = RTP_VERSION_PAD_EXTEND_INDEX;
                    writer.Write(RTP_VERSION_PAD_EXTEND);

                    writer.BaseStream.Position = RTP_PAYLOAD_INDEX;
                    writer.Write(RTP_PAYLOAD_TYPE);

                    writer.BaseStream.Position = SEQ_INDEX;
                    writer.Write(seq);

                    writer.BaseStream.Position = TIMESTAMP_INDEX;
                    writer.Write(timestamp);

                    writer.BaseStream.Position = SSRC_INDEX;
                    writer.Write(ssrc);

                    writer.BaseStream.Position = RTP_HEADER_BYTE_LENGTH;
                    writer.Write(fullPacket);
                }
            }
        }
开发者ID:ElAfroNinja,项目名称:DiscordSharp,代码行数:32,代码来源:DiscordAudioPacket.cs

示例12: BwWriteLE4

 // DSFチャンクの数字はリトルエンディアンバイトオーダー
 private void BwWriteLE4(BinaryWriter bw, uint v)
 {
     bw.Write((byte)(v & 0xff));
     bw.Write((byte)((v >> 8) & 0xff));
     bw.Write((byte)((v >> 16) & 0xff));
     bw.Write((byte)((v >> 24) & 0xff));
 }
开发者ID:klangobjekte,项目名称:bitspersampleconv2,代码行数:8,代码来源:WWDsfWriter.cs

示例13: Write

 public void Write(BinaryWriter bw)
 {
     Shading.Write(bw);
     Main.Write(bw);
     _.Write(bw);
     __.Write(bw);
 }
开发者ID:cedianoost,项目名称:3DS-Theme-Editor,代码行数:7,代码来源:FolderSet.cs

示例14: writeBinary

        public void writeBinary()
        {
            string nom = tbName.Text + ".bytes"; byte i;
            BinaryReader br = null;
            BinaryWriter bw = null;
            FileStream fs = null;
            //Ecriture d'octets dans le fichier
            bw = new BinaryWriter(File.Create(nom));

            i = Convert.ToByte(width.Text);
            bw.Write(i);

            i = Convert.ToByte(height.Text);
            bw.Write(i);

            i = Convert.ToByte(random.Checked);
            bw.Write(i);

            for (int j = 3; j < Convert.ToInt32(width.Text); j++)
            {
                bw.Write(Convert.ToSByte(0));
            }

            foreach (DataGridViewRow data in dataGridView1.Rows)
            {
                for(int j = 0; j < dataGridView1.Columns.Count;j++)
                {
                    i = Convert.ToByte(data.Cells[j].Value);

                    bw.Write(i);
                }
            }

            bw.Close();
        }
开发者ID:JustineSieye,项目名称:CACAHUETE_BOMBERBOT,代码行数:35,代码来源:Form1.cs

示例15: MessageShouldBeSameAfterSerializationAndDeserialization

        public void MessageShouldBeSameAfterSerializationAndDeserialization()
        {
            var writer = new BinaryWriter(new MemoryStream());
            IMessageFactory msgFactory = new MessageFactory(new Message[]
                {
                    new ISomeServiceComplexRequest()
                });

            var fixture = new Fixture();
            fixture.Customize<ISomeServiceComplexRequest>(ob =>
                ob.With(x => x.datas,
                    fixture.CreateMany<SubData>().ToList()));
            fixture.Customize<ComplexData>(ob => ob
                .With(x => x.SomeArrString, fixture.CreateMany<string>().ToList())
                .With(x => x.SomeArrRec, fixture.CreateMany<SubData>().ToList()));

            var msg = fixture.CreateAnonymous<ISomeServiceComplexRequest>();

            //serialize and deserialize msg1
            msg.Serialize(writer);
            writer.Seek(0, SeekOrigin.Begin);
            var reader = new BinaryReader(writer.BaseStream);
            Message retMsg = msgFactory.Deserialize(reader);

            retMsg.Should().BeOfType<ISomeServiceComplexRequest>();
            msg.ShouldBeEqualTo((ISomeServiceComplexRequest)retMsg);
        }
开发者ID:tlotter,项目名称:MassiveOnlineUniversalServerEngine,代码行数:27,代码来源:MessageSerializationTests.cs


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