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


C# BinaryWriter.Flush方法代码示例

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


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

示例1: 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

示例2: 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

示例3: FinalizePacket

        /// <summary>
        /// Writes a packet's header and encrypts the contents of the packet (not the header).
        /// </summary>
        /// <param name="PacketID">The ID of the packet.</param>
        /// <param name="PacketData">The packet's contents.</param>
        /// <returns>The finalized packet!</returns>
        private static byte[] FinalizePacket(byte PacketID, DESCryptoServiceProvider CryptoService, byte[] PacketData)
        {
            MemoryStream FinalizedPacket = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(FinalizedPacket);

            PasswordDeriveBytes Pwd = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(PlayerAccount.Client.Password),
                Encoding.ASCII.GetBytes("SALT"), "SHA1", 10);

            MemoryStream TempStream = new MemoryStream();
            CryptoStream EncryptedStream = new CryptoStream(TempStream,
                CryptoService.CreateEncryptor(PlayerAccount.EncKey, Encoding.ASCII.GetBytes("@1B2c3D4e5F6g7H8")),
                CryptoStreamMode.Write);
            EncryptedStream.Write(PacketData, 0, PacketData.Length);
            EncryptedStream.FlushFinalBlock();

            PacketWriter.Write(PacketID);
            //The length of the encrypted data can be longer or smaller than the original length,
            //so write the length of the encrypted data.
            PacketWriter.Write((byte)(3 + TempStream.Length));
            PacketWriter.Flush();
            //Also write the length of the unencrypted data.
            PacketWriter.Write((byte)PacketData.Length);
            PacketWriter.Flush();

            PacketWriter.Write(TempStream.ToArray());
            PacketWriter.Flush();

            byte[] ReturnPacket = FinalizedPacket.ToArray();

            PacketWriter.Close();

            return ReturnPacket;
        }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:39,代码来源:LotPacketSenders.cs

示例4: FlushAndWriteCatalogs

        public void FlushAndWriteCatalogs(BinaryWriter writer)
        {
            writer.Write((uint)m_stringsDict.Count);
            writer.Flush();
            m_stringsCatalogWriter.Flush();
            m_stringsCatalogStream.WriteTo(writer.BaseStream);

            writer.Write((uint)m_typeNameTagsDict.Count);
            writer.Flush();
            m_typeNameCatalogWriter.Flush();
            m_typeNameCatalogStream.WriteTo(writer.BaseStream);

            writer.Write((uint)m_typeSpecTagsDict.Count);
            writer.Flush();
            m_typeCatalogWriter.Flush();
            m_typeCatalogStream.WriteTo(writer.BaseStream);

            writer.Write((uint)m_methodSignaturesDict.Count);
            writer.Flush();
            m_methodSignatureCatalogWriter.Flush();
            m_methodSignatureCatalogStream.WriteTo(writer.BaseStream);

            writer.Write((uint)m_methodDeclTagsDict.Count);
            writer.Flush();
            m_methodDeclCatalogWriter.Flush();
            m_methodDeclCatalogStream.WriteTo(writer.BaseStream);

            writer.Write((uint)m_methodSpecDict.Count);
            writer.Flush();
            m_methodSpecCatalogWriter.Flush();
            m_methodSpecCatalogStream.WriteTo(writer.BaseStream);
        }
开发者ID:elasota,项目名称:clarity,代码行数:32,代码来源:HighFileBuilder.cs

示例5: FinalizePacket

        public override byte[] FinalizePacket(byte PacketID, byte[] PacketData)
        {
            MemoryStream FinalizedPacket = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(FinalizedPacket);

            MemoryStream TempStream = new MemoryStream();
            CryptoStream EncryptedStream = new CryptoStream(TempStream,
                m_EncryptTransformer, CryptoStreamMode.Write);
            EncryptedStream.Write(PacketData, 0, PacketData.Length);
            EncryptedStream.FlushFinalBlock();

            PacketWriter.Write(PacketID);
            //The length of the encrypted data can be longer or smaller than the original length,
            //so write the length of the encrypted data.
            PacketWriter.Write((ushort)((long)PacketHeaders.ENCRYPTED + TempStream.Length));
            //Also write the length of the unencrypted data.
            PacketWriter.Write((ushort)PacketData.Length);
            PacketWriter.Flush();

            PacketWriter.Write(TempStream.ToArray());
            PacketWriter.Flush();

            byte[] ReturnPacket = FinalizedPacket.ToArray();

            PacketWriter.Close();

            return ReturnPacket;
        }
开发者ID:ddfczm,项目名称:Project-Dollhouse,代码行数:28,代码来源:ARC4Encryptor.cs

示例6: EscribirBanner

        public static void EscribirBanner(string salida, Estructuras.Banner banner)
        {
            BinaryWriter bw = new BinaryWriter(new FileStream(salida, FileMode.Create));
            Console.Write("Banner...");

            bw.Write(banner.version);
            bw.Write(banner.CRC16);
            bw.Write(banner.reserved);
            bw.Write(banner.tileData);
            bw.Write(banner.palette);
            bw.Write(StringToTitle(banner.japaneseTitle));
            bw.Write(StringToTitle(banner.englishTitle));
            bw.Write(StringToTitle(banner.frenchTitle));
            bw.Write(StringToTitle(banner.germanTitle));
            bw.Write(StringToTitle(banner.italianTitle));
            bw.Write(StringToTitle(banner.spanishTitle));
            bw.Flush();

            int rem = (int)bw.BaseStream.Position % 0x200;
            if (rem != 0)
            {
                while (rem < 0x200)
                {
                    bw.Write((byte)0xFF);
                    rem++;
                }
            }
            bw.Flush();

            Console.WriteLine(Tools.Helper.GetTranslation("Messages", "S09"), bw.BaseStream.Length);
            bw.Close();
        }
开发者ID:MetLob,项目名称:tinke,代码行数:32,代码来源:NDS.cs

示例7: ProcessRequest

        public static void ProcessRequest(ClientWebRequest equest)
        {
            lock(syncobj) {
            if(db == null) {
            db = new PubKeyDatabase("default",File.Open("OpenNetDB_client",FileMode.OpenOrCreate));

            }
            if(db.Length == 0) {
            db.AddPublicKey(db.GenPublicPrivateKey(2048));
            db.GetPublicKeyOnly(db[0]);
            }
            Uri url = new Uri("http:/"+equest.UnsanitizedRelativeURI.Replace("idw.local.ids","127.0.0.1"));
            if(!drivers.ContainsKey(url.Host)) {
            Console.WriteLine("Connecting to "+url.Host);
                HttpWebRequest request = HttpWebRequest.Create("http://"+url.Host+"/OpenNetProvider") as HttpWebRequest;
            request.AllowWriteStreamBuffering = false;
            Stream receiver = new TrashyStream(request.GetResponse().GetResponseStream());
            BinaryReader mreader = new BinaryReader(receiver);
            byte[] guid = mreader.ReadBytes(16);
            Console.WriteLine(BitConverter.ToString(guid));
            request = HttpWebRequest.Create("http://"+url.Host+"/OpenNetProvider") as HttpWebRequest;
            request.Method = "POST";
            request.ContentLength = 9999999999;
            request.AllowWriteStreamBuffering = false;
            Stream sender = new TrashyStream(request.GetRequestStream());
            BinaryWriter mwriter = new BinaryWriter(sender);
            mwriter.Write(guid);
            mwriter.Flush();
            byte[] theirpubkey = mreader.ReadBytes(mreader.ReadInt32());
            Stream dbStr = File.Open("keyDB.db", FileMode.OpenOrCreate);

            byte[] ourpublickey = db.GetPublicKeyOnly(db[0]);
            byte[] ourprivatekey = db[0];
            mwriter.Write(ourpublickey.Length);
            mwriter.Write(ourpublickey);
            mwriter.Flush();
            db.AddPublicKey(theirpubkey);
            Stream securedStream = new TrashyStream(db.CreateAuthenticatedStream(ourprivatekey, new DualStream(sender, receiver), 32));

            Console.WriteLine("Secure stream negotiated");

            driver = new OpenNetProtocolDriver(securedStream);
            drivers.Add(url.Host,driver);
                Console.WriteLine("Driver initialized");

            }
                mvent.Reset();
            currentRequest = equest;
                currentURL = url;
                driver = drivers[url.Host];
                drivers[url.Host].onConnectionEstablished += HandleonConnectionEstablished;

                drivers[url.Host].OpenStream();

                mvent.WaitOne();

            }
        }
开发者ID:IDWMaster,项目名称:OpenServer,代码行数:58,代码来源:MyClass.cs

示例8: getBlob

        public void getBlob(int parent_refno)
        {
            string connStr = "Data Source=192.168.45.17;Initial Catalog=NLS;User Id=gvandell;Password=$#Escher1;";
            string sPath = null;
            int bufferSize = 100;
            byte[] outbyte = new byte[bufferSize];
            SqlConnection CN = new SqlConnection();
            SqlCommand CM = new SqlCommand();
            FileStream FS = null;
            BinaryWriter BW = null;
            long retVal;
            int StartIndex;
            string strSQL = "select VerificationDocsID, DocumentBIN from GlobalVerificationDocs where VerificationDocsID in (select top 1 VerificationDocsID from vw_doc_packets where parent_refno = " + parent_refno + " and grouping_name = '" + "Unsecured Doc Packet" + "' order by VerificationDocsID desc)";

            CN.ConnectionString = connStr;
            CN.Open();

            CM.Connection = CN;
            CM.CommandType = CommandType.Text;
            CM.CommandText = strSQL;

            SqlDataReader sqlDR = CM.ExecuteReader(CommandBehavior.SequentialAccess);
            while (sqlDR.Read())
            {
                sPath = HttpContext.Current.Server.MapPath(@"/docs/");
                FS = new FileStream(HttpContext.Current.Server.MapPath(@"/docs/SFC_" + DateTime.Today.Year + DateTime.Today.Month + DateTime.Today.Day + ".zip"), FileMode.OpenOrCreate, FileAccess.Write);

                BW = new BinaryWriter(FS);

                StartIndex = 0;
                retVal = sqlDR.GetBytes(1, StartIndex, outbyte, 0, bufferSize);

                while (retVal == bufferSize)
                {
                    BW.Write(outbyte, 0, (int)retVal);
                    BW.Flush();

                    StartIndex += bufferSize;
                    retVal = sqlDR.GetBytes(1, StartIndex, outbyte, 0, bufferSize);

                }

                BW.Write(outbyte, 0, (int)retVal);
                BW.Flush();

                BW.Close();
                FS.Close();
            }

            sqlDR.Close();
            CN.Close();
        }
开发者ID:rdmitruk,项目名称:getBlobFromDB,代码行数:52,代码来源:DataFunctions.cs

示例9: Pack

        public static void Pack(string fileIn, string fileOut, ref sFolder unpacked)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            br.BaseStream.Position = 0x08;
            uint block_size = br.ReadUInt32();
            br.Close();

            BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut));

            bw.Write(new char[] { 'L', 'I', 'N', 'K' });
            bw.Write(unpacked.files.Count);
            bw.Write(block_size);
            bw.Write(0x00);

            unpacked.files.Sort(SortFiles);

            uint offset = block_size;
            List<byte> buffer = new List<byte>();
            for (int i = 0; i < unpacked.files.Count; i++)
            {
                br = new BinaryReader(File.OpenRead(unpacked.files[i].path));
                br.BaseStream.Position = unpacked.files[i].offset;
                buffer.AddRange(br.ReadBytes((int)unpacked.files[i].size));
                while (buffer.Count % block_size != 0)
                    buffer.Add(0x00);
                br.Close();

                bw.Write(offset / block_size);
                bw.Write(unpacked.files[i].size);

                sFile upFile = unpacked.files[i];
                upFile.offset = offset;
                upFile.path = fileOut;
                unpacked.files[i] = upFile;

                offset += unpacked.files[i].size;
                if (offset % block_size != 0)  // Padding
                    offset += (block_size - (offset % block_size));
            }
            byte[] rem = new byte[0];
            if (bw.BaseStream.Position % block_size != 0)
                rem = new byte[block_size - (bw.BaseStream.Position % block_size)];
            bw.Write(rem);
            bw.Flush();

            bw.Write(buffer.ToArray());
            bw.Flush();

            bw.Close();
        }
开发者ID:MetLob,项目名称:tinke,代码行数:50,代码来源:LINK.cs

示例10: Append

        public static void Append(ref BinaryWriter bw, ref BinaryReader br)
        {
            const int block_size = 0x80000; // 512 KB
            int size = (int)br.BaseStream.Length;

            while (br.BaseStream.Position + block_size < size)
            {
                bw.Write(br.ReadBytes(block_size));
                bw.Flush();
            }

            int rest = size - (int)br.BaseStream.Position;
            bw.Write(br.ReadBytes(rest));
            bw.Flush();
        }
开发者ID:MetLob,项目名称:tinke,代码行数:15,代码来源:IOutil.cs

示例11: Serialize

		/// <summary>
		/// Serializes the instance to the specified stream.
		/// </summary>
		/// <param name="stream">The stream.</param>
		public void Serialize(Stream stream) {
			var writer = new BinaryWriter(stream);
			writer.Write(this.IsPrivateAssociation);
			writer.WriteBuffer(this.Secret);
			writer.Write((int)(this.ExpiresUtc - TimestampEncoder.Epoch).TotalSeconds);
			writer.Flush();
		}
开发者ID:rafek,项目名称:dotnetopenid,代码行数:11,代码来源:AssociationDataBag.cs

示例12: Export

 public static void Export(DataTable dt, string fileName)
 {
     if (!Path.GetExtension(fileName).Equals(".xls", StringComparison.OrdinalIgnoreCase))
     {
         throw new ArgumentException("Not an Excel file!", fileName);
     }
     string stOutput = "";
     string sHeaders = "";
     for (int j = 0; j < dt.Columns.Count; j++)
     {
         sHeaders = sHeaders + dt.Rows[0][j] + "\t";
     }
     stOutput += sHeaders + "\r\n";
     for (int i = 0; i < dt.Rows.Count - 1; i++)
     {
         string stLine = "";
         for (int j = 0; j < dt.Columns.Count; j++)
         {
             stLine = stLine + dt.Rows[i][j] + "\t";
         }
         stOutput += stLine + "\r\n";
     }
     using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
     using (var bw = new BinaryWriter(fs))
     {
         byte[] output = Encoding.GetEncoding(1254).GetBytes(stOutput);
         bw.Write(output, 0, output.Length);
         bw.Flush();
     }
 }
开发者ID:webyneter,项目名称:Components-Analysis,代码行数:30,代码来源:ExcelProvider.cs

示例13: SendServerInfo

        /// <summary>
        /// Send information about this CityServer to the LoginServer...
        /// </summary>
        /// <param name="Client">The client connected to the LoginServer.</param>
        public static void SendServerInfo(NetworkClient Client)
        {
            PacketStream Packet = new PacketStream(0x64, 0);
            Packet.WriteByte(0x64);

            MemoryStream PacketBody = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(PacketBody);

            PacketWriter.Write((string)GlobalSettings.Default.CityName);
            PacketWriter.Write((string)GlobalSettings.Default.CityDescription);
            PacketWriter.Write((string)Settings.BINDING.Address.ToString());
            PacketWriter.Write((int)Settings.BINDING.Port);
            PacketWriter.Write((byte)1); //CityInfoStatus.OK
            PacketWriter.Write((ulong)GlobalSettings.Default.CityThumbnail);
            PacketWriter.Write((string)GlobalSettings.Default.ServerID);
            PacketWriter.Write((ulong)GlobalSettings.Default.Map);
            PacketWriter.Flush();

            Packet.WriteUInt16((ushort)(PacketBody.ToArray().Length + PacketHeaders.UNENCRYPTED));

            Packet.Write(PacketBody.ToArray(), 0, (int)PacketWriter.BaseStream.Length);
            Packet.Flush();

            PacketWriter.Close();

            Client.Send(Packet.ToArray());
        }
开发者ID:Blayer98,项目名称:Project-Dollhouse,代码行数:31,代码来源:LoginPacketSenders.cs

示例14: TestMethod1

        public void TestMethod1()
        {
            string str = Reencoder.GetUrlContent("http://www.shinmai.co.jp/olympic/jouhou/shochi.htm");

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);
            bw.Write(str);
            bw.Flush();

            ms.Position = 0;

            using (TextReader rdr = new StreamReader(ms, Encoding.GetEncoding("shift-jis")))
            {
                using (
                    TextWriter wrtr =
                        new StreamWriter(
                            @"C:\Users\User\Documents\Visual Studio 2013\Projects\tds3\discussions\bin\x86\Debug\qwe.html",
                            false,
                            Encoding.UTF8))
                {
                    wrtr.Write(rdr.ReadToEnd());
                }
            }

            //var writer = new BinaryWriter(
            //        new FileStream(@"C:\Users\User\Documents\Visual Studio 2013\Projects\tds3\discussions\bin\x86\Debug\qwe.html",
            //                       FileMode.OpenOrCreate)
            // );

            //writer.Write(reencoded);
            //writer.Close();
        }
开发者ID:gdlprj,项目名称:duscusys,代码行数:32,代码来源:ReencoderTest.cs

示例15: Create

        public static NetPackage Create(int contentID, int orderID, NetCommandType commandID, int packageCount, byte[] data, IPEndPoint iep)
        {
            using (BinaryWriter bw = new BinaryWriter(new MemoryStream()))
            {
                int packageID = GeneratePackageID();

                bw.Write(MagicNumber);
                bw.Write(packageID);
                bw.Write(contentID);
                bw.Write(orderID);

                if (orderID == 1)
                {
                    bw.Write((int)commandID);
                    bw.Write(packageCount);
                }

                bw.Write(data, 0, data.Length);
                bw.Flush();
                bw.BaseStream.Seek(0, SeekOrigin.Begin);

                NetPackage package = new NetPackage();

                package.RemoteEP = new IPEndPoint(iep.Address, iep.Port);
                package.ID = packageID;
                package.ContentID = contentID;
                package.OrderID = orderID;
                package.CommandID = commandID;
                package.PackageCount = packageCount;
                package.Buffer = ((MemoryStream)bw.BaseStream).ToArray();
                package.Size = data.Length;

                return package;
            }
        }
开发者ID:patrick963534,项目名称:g11,代码行数:35,代码来源:NetPackage.cs


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