• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IO.BinaryWriter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GnuPlot

        // use static factory methods!
        private GnuPlot(Table table)
        {
            try {
                // TODO avoid necessary write access in app directory
                using (FileStream fs = new FileStream (BinaryFile, FileMode.Create, FileAccess.Write))
                    using (BinaryWriter bw = new BinaryWriter (fs)) {
                        Table3D t3D = table as Table3D;
                        if (t3D != null)
                            WriteGnuPlotBinary (bw, t3D);
                        else
                            WriteGnuPlotBinary (bw, (Table2D)table);
                    }
            } catch (Exception ex) {
                throw new GnuPlotException ("Could not write binary data file.\n" + ex.Message);
            }
            try {
                StartProcess (table);
            } catch (System.ComponentModel.Win32Exception ex) {
                // from MSDN
                // These are the Win32 error code for file not found or access denied.
                const int ERROR_FILE_NOT_FOUND = 2;
                const int ERROR_ACCESS_DENIED = 5;

                switch (ex.NativeErrorCode) {
                case ERROR_FILE_NOT_FOUND:
                    throw new GnuPlotProcessException ("Could not find gnuplot executable path:\n" + exePath + "\n\n" + ex.Message);
                case ERROR_ACCESS_DENIED:
                    throw new GnuPlotProcessException ("Access denied, no permission to start gnuplot process!\n" + ex.Message);
                default:
                    throw new GnuPlotProcessException ("Unknown error. Could not start gnuplot process.\n" + ex.Message);
                }
            }
        }
开发者ID:dschultzca,项目名称:ScoobyRom,代码行数:34,代码来源:GnuPlot.cs


示例17: Patch

 public void Patch(BinaryWriter file)
 {
     for (int i = 0; i < times; i++)
     {
         file.Write(repeat);
     }
 }
开发者ID:smolson4,项目名称:wzmapeditor,代码行数:7,代码来源:Run.cs


示例18: Decrypt

 //解密
 public string Decrypt(string m,string key)
 {
     string msg = null;
     string[] array = m.Split('~');
     int length = array.Length;
     byte[] by = new byte[length];
     for (int i = 0; i < length;i++ )
     {
         int l = int.Parse(array[i]);
         byte[] k = System.BitConverter.GetBytes(l);
         by[i] = k[0];
     }
     try
     {
         FileStream aFile = new FileStream("2.txt", FileMode.Create);
         BinaryWriter sw = new BinaryWriter(aFile);
         sw.Write(by);
         sw.Close();
         aFile.Close();
     }
     catch (IOException e){}
     test.DES_Decrypt("2.txt", key, "3.txt");
     try
     {
         FileStream file = new FileStream("3.txt", FileMode.Open);
         StreamReader read = new StreamReader(file);
         msg=read.ReadToEnd();
         read.Close();
         file.Close();
     }
     catch (IOException) { }
     return msg;
 }
开发者ID:wuqingzhou828,项目名称:client,代码行数:34,代码来源:DES.cs


示例19: GetEncoding

        public override byte[] GetEncoding()
        {
            try
            {
                MemoryStream outputStream = new MemoryStream();
                BinaryWriter binaryWriter = new BinaryWriter(new BufferedStream(outputStream));

                MessagesEncodingUtil.WriteMessageType(binaryWriter, this);

                if (PeerAddress.PrivateEndPoint == null)
                    MessagesEncodingUtil.WriteString(binaryWriter, "null");
                else
                    MessagesEncodingUtil.WriteString(binaryWriter, PeerAddress.PrivateEndPoint.ToString());

                if (PeerAddress.PublicEndPoint == null)
                    MessagesEncodingUtil.WriteString(binaryWriter, "null");
                else
                    MessagesEncodingUtil.WriteString(binaryWriter, PeerAddress.PublicEndPoint.ToString());

                binaryWriter.Flush();

                byte[] buffer = outputStream.ToArray();

                if (buffer.Length <= EncodingConstants.MAX_MESSAGE_LENGTH)
                    return outputStream.ToArray();
                else
                    throw new BinaryEncodingException();
            }
            catch (Exception)
            {
                throw new BinaryEncodingException("Decode");
            }
        }
开发者ID:ionhristiniuc,项目名称:chatapp,代码行数:33,代码来源:PeerAddressMessage.cs


示例20: ServerConnection

 public ServerConnection(TcpClient client, SslStream stream, BinaryReader binaryReader, BinaryWriter binaryWriter)
 {
     _client = client;
     _stream = stream;
     _binaryReader = binaryReader;
     _binaryWriter = binaryWriter;
 }
开发者ID:OrcusTechnologies,项目名称:Orcus.Plugins.ServerStressTest,代码行数:7,代码来源:ServerConnection.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.BufferedStream类代码示例发布时间:2022-05-26
下一篇:
C# IO.BinaryReader类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap