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


C# BufferedStream.Flush方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            FileStream fs1 = new FileStream("out.bin",FileMode.Create,FileAccess.Write,FileShare.Read);
            FileStream fs2 = new FileStream("out2.bin",FileMode.Create,FileAccess.Write,FileShare.Read);
            bf1 = new BufferedStream(fs1);
            bf2 = new BufferedStream(fs2);
            try
            {
                Server server = new Server(10, 4096* 100 * 2);
                server.Sequential = false;
                server.Start(new IPEndPoint(IPAddress.Any, 40004));
                server.MessageReceived += OnMessageReceived;

                server.ClientConnected += OnClientConnected;
                server.ClientDisconnected += OnClientDisconnected;
                Console.ReadKey();
            }
            finally
            {
                bf1.Flush();
                bf2.Flush();
                bf1.Close();
                bf2.Close();
                fs1.Close();
                fs2.Close();
            }
        }
开发者ID:demonix,项目名称:KeClientTracer,代码行数:27,代码来源:Program.cs

示例2: Set

		public void Set(string name, string key, RavenJObject data, UuidType uuidType)
		{
			Api.JetSetCurrentIndex(session, Lists, "by_name_and_key");
			Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
			Api.MakeKey(session, Lists, key, Encoding.Unicode, MakeKeyGrbit.None);

			var exists = Api.TrySeek(session, Lists, SeekGrbit.SeekEQ);


			using (var update = new Update(session, Lists, exists ? JET_prep.Replace : JET_prep.Insert))
			{
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["name"], name, Encoding.Unicode);
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["key"], key, Encoding.Unicode);
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["etag"], uuidGenerator.CreateSequentialUuid(uuidType).TransformToValueForEsentSorting());
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["created_at"], SystemTime.UtcNow);

				using (var columnStream = new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"]))
				{
					if (exists)
						columnStream.SetLength(0);
					using (Stream stream = new BufferedStream(columnStream))
					{
						data.WriteTo(stream);
						stream.Flush();
					}
				}
				update.Save();
			}
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:29,代码来源:Lists.cs

示例3: Serialize

        public byte[] Serialize(object o)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }

            var type = o.GetType();
            if (!type.IsDefined(typeof(SerializableAttribute), true))
            {
                throw new ArgumentException(
                    string.Format("The provided object cannot be serialized; [{0}] is not serializable", type));
            }

            using (var stream = new MemoryStream())
            {
                var buffer = new BufferedStream(stream);
                var formatter = new BinaryFormatter();

                formatter.Serialize(buffer, o);
                buffer.Flush();

                return stream.GetBuffer();
            }
        }
开发者ID:katasource,项目名称:shironet,代码行数:25,代码来源:DefaultSerializer.cs

示例4: button3_Click

 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         string str1 = textBox1.Text;
         string str2 = textBox2.Text + "\\" + textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1, textBox1.Text.Length - textBox1.Text.LastIndexOf("\\") - 1);
         Stream myStream1, myStream2;
         BufferedStream myBStream1, myBStream2;
         byte[] myByte = new byte[1024];
         int i;
         myStream1 = File.OpenRead(str1);
         myStream2 = File.OpenWrite(str2);
         myBStream1 = new BufferedStream(myStream1);
         myBStream2 = new BufferedStream(myStream2);
         i = myBStream1.Read(myByte, 0, 1024);
         while (i > 0)
         {
             myBStream2.Write(myByte, 0, i);
             i = myBStream1.Read(myByte, 0, 1024);
         }
         myBStream2.Flush();
         myStream1.Close();
         myBStream2.Close();
         MessageBox.Show("文件复制完成");
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
开发者ID:TGHGH,项目名称:C-1200,代码行数:30,代码来源:Form1.cs

示例5: BadXmlTests

        public void BadXmlTests()
        {
            try {
            EncodeHelper.Deserialize("<garbage />", typeof(System.Object));
            Assert.Fail("You should not have been able to deserialize this preceding xml");
              }
              catch {
              }

              MemoryStream ms = new MemoryStream();
              using (StreamWriter sw = new StreamWriter(ms)) {
            sw.Write("<garbage />");
            sw.Flush();
            object test = EncodeHelper.Deserialize(ms);
            Assert.AreEqual(null, test);
              }

              try {
            //Test the Deserialize method that builds an error message.
            ms = new MemoryStream();
            using (BufferedStream sw = new BufferedStream(ms)) {
              sw.Write(Encoding.UTF8.GetPreamble(), 0, 3);
              byte[] msg = System.Text.Encoding.UTF8.GetBytes("<garbage>");
              sw.Write(msg, 0, msg.Length);
              sw.Flush();
              ms.Position = 0;
              object test = EncodeHelper.Deserialize(ms);
              Assert.AreEqual(null, test);
            }
              }
              catch (Exception ex) {
            if (ex.Message.IndexOf("Couldn't parse XML") == -1)
              Assert.Fail("We should have failed for a bad xml file.");
              }
        }
开发者ID:x252618759,项目名称:google-checkout-dotnet-sample-code,代码行数:35,代码来源:EncodeHelperTests.cs

示例6: AddAttachment

		public Etag AddAttachment(string key, Etag etag, Stream data, RavenJObject headers)
		{
			Api.JetSetCurrentIndex(session, Files, "by_name");
			Api.MakeKey(session, Files, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
			var isUpdate = Api.TrySeek(session, Files, SeekGrbit.SeekEQ);
			if (isUpdate)
			{
				var existingEtag = Etag.Parse(Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["etag"]));
				if (existingEtag != etag && etag != null)
				{
					throw new ConcurrencyException("PUT attempted on attachment '" + key +
						"' using a non current etag")
					{
						ActualETag = existingEtag,
						ExpectedETag = etag
					};
				}
			}
			else
			{
				if (data == null)
					throw new InvalidOperationException("When adding new attachment, the attachment data must be specified");

				if (Api.TryMoveFirst(session, Details))
					Api.EscrowUpdate(session, Details, tableColumnsCache.DetailsColumns["attachment_count"], 1);
			}

			Etag newETag = uuidGenerator.CreateSequentialUuid(UuidType.Attachments);
			using (var update = new Update(session, Files, isUpdate ? JET_prep.Replace : JET_prep.Insert))
			{
				Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["name"], key, Encoding.Unicode);
				if (data != null)
				{
					long written;
					using (var columnStream = new ColumnStream(session, Files, tableColumnsCache.FilesColumns["data"]))
					{
						if (isUpdate)
							columnStream.SetLength(0);
						using (var stream = new BufferedStream(columnStream))
						{
							data.CopyTo(stream);
							written = stream.Position;
							stream.Flush();
						}
					}
					if (written == 0) // empty attachment
					{
						Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["data"], new byte[0]);
					}
				}

				Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["etag"], newETag.TransformToValueForEsentSorting());
				Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["metadata"], headers.ToString(Formatting.None), Encoding.Unicode);

				update.Save();
			}
			logger.Debug("Adding attachment {0}", key);

			return newETag;
		}
开发者ID:925coder,项目名称:ravendb,代码行数:60,代码来源:DocumentStorageActions.cs

示例7: GetObjectPartly

        public static void GetObjectPartly()
        {
            const string localFilePath = "<your localFilePath>";
            const string bucketName = "<your bucketName>";
            const string fileKey = "<your fileKey>";
            const string accessId = "<your access id>";
            const string  accessKey = "<your access key>";

            _client = new OssClient(accessId, accessKey);

            using (var fileStream = new FileStream(localFilePath, FileMode.OpenOrCreate))
            {
                var bufferedStream = new BufferedStream(fileStream);
                var objectMetadata = _client.GetObjectMetadata(bucketName, fileKey);
                var fileLength = objectMetadata.ContentLength;
                const int partSize = 1024 * 1024 * 10;

                var partCount = CalPartCount(fileLength, partSize);

                for (var i = 0; i < partCount; i++)
                {
                    var startPos = partSize * i;
                    var endPos = partSize * i + (partSize < (fileLength - startPos) ? partSize : (fileLength - startPos)) - 1;
                    Download(bufferedStream, startPos, endPos, localFilePath, bucketName, fileKey);
                }
                bufferedStream.Flush();
            }
        }
开发者ID:bys-james-shi,项目名称:OpenSource,代码行数:28,代码来源:GetObjectByRangeSample.cs

示例8: Authenticate

		public override void Authenticate(NpgsqlConnector context, byte[] password)
		{
			NpgsqlPasswordPacket pwpck = new NpgsqlPasswordPacket(password);
			BufferedStream stream = new BufferedStream(context.Stream);
			pwpck.WriteToStream(stream);
			stream.Flush();
		}
开发者ID:dstimac,项目名称:revenj,代码行数:7,代码来源:NpgsqlStartupState.cs

示例9: Authenticate

		public override void Authenticate(NpgsqlConnector context, string password)
		{
			NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Authenticate");
			NpgsqlPasswordPacket pwpck = new NpgsqlPasswordPacket(password, context.BackendProtocolVersion);
			BufferedStream stream = new BufferedStream(context.Stream);
			pwpck.WriteToStream(stream);
			stream.Flush();
		}
开发者ID:Orvid,项目名称:SQLInterfaceCollection,代码行数:8,代码来源:NpgsqlStartupState.cs

示例10: Stream2Test

        public void Stream2Test()
        {
            var ms = new BufferedStream(new MemoryStream());
            Console.WriteLine(ms.CanWrite);
            Console.WriteLine(ms.CanRead);
            ms.Write(new byte[3] { 1, 2, 3 }, 0, 3);
            ms.Flush();

            var bys = new byte[10];
            var len = ms.Read(bys, 0, 10);
            Console.WriteLine(len + "->" + bys[0]);
        }
开发者ID:Centny,项目名称:cswf,代码行数:12,代码来源:SomeTest.cs

示例11: Execute

        public void Execute()
        {
            MemoryStream buffer = new MemoryStream();
            formatter.Serialize(buffer, message);

            byte[] bytes = buffer.ToArray();
            byte[] size = BitConverter.GetBytes((int)buffer.Length);

            Stream stream = new BufferedStream(client.GetStream());
            stream.Write(size, 0, size.Length);
            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();
        }
开发者ID:ccidral,项目名称:courier,代码行数:13,代码来源:SendMessage.cs

示例12: Decompress

 public static void Decompress(Stream instream, Stream outstream)
 {
     BufferedStream stream = new BufferedStream(outstream);
     BufferedStream zStream = new BufferedStream(instream);
     if ((zStream.ReadByte() == 0x42) && (zStream.ReadByte() == 90))
     {
         BZip2InputStream stream3 = new BZip2InputStream(zStream);
         for (int i = stream3.ReadByte(); i != -1; i = stream3.ReadByte())
         {
             stream.WriteByte((byte) i);
         }
         stream.Flush();
     }
 }
开发者ID:bmadarasz,项目名称:ndihelpdesk,代码行数:14,代码来源:BZip2.cs

示例13: Case1

        /// <summary>
        /// BufferedStream使用装饰模式
        /// 继承Stream基类,提供同样的接口
        /// 可以封装其他继承自Stream的类,提供缓存的功能
        /// </summary>
        static void Case1()
        {
            string filePath = @"test.txt";
            if (File.Exists(filePath))
                File.Delete(filePath);

            using(FileStream fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
            {
                using (BufferedStream bs = new BufferedStream(fs))
                {
                    Output(bs, "I am Simon.\r\n");
                    Output(bs, "How are you?");
                    bs.Flush();
                }
            }
        }
开发者ID:0iron0,项目名称:Simon.Pattern.Demo,代码行数:21,代码来源:DecorateDemo.cs

示例14: Buffered_Stream_buffers_and_forwards_writes_and_flushes_before_close

        public void Buffered_Stream_buffers_and_forwards_writes_and_flushes_before_close()
        {
            var mock = new Mock<Stream>();
            Stream stream = mock.Object;
            mock.SetupGet(d => d.CanRead).Returns(true);
            mock.SetupGet(d => d.CanWrite).Returns(true);

            BufferedStream bs = new BufferedStream(stream);
            bs.WriteByte((byte)'a');
            bs.Flush();
            bs.Close();

            mock.Verify(d => d.Write(It.Is<byte[]>(array => array.Length > 0 && array[0] == 'a'), 0, 1));
            mock.Verify(d => d.Flush());
            mock.Verify(d => d.Close());
        }
开发者ID:davedf,项目名称:tdd-exercises-csharp,代码行数:16,代码来源:HelloWorldMockExample.cs

示例15: CreateTestFile

        /// <summary>
        /// 테스트용 임시 파일을 생성한다.
        /// </summary>
        public FileInfo CreateTestFile(string filepath, long size) {
            var fi = new FileInfo(filepath);

            var buffer = new byte[BufferSize];

            ArrayTool.GetRandomBytes(buffer);

            using(var bs = new BufferedStream(fi.OpenWrite())) {
                long writeCount = 0;
                do {
                    bs.Write(buffer, 0, BufferSize);
                    writeCount += BufferSize;
                } while(size > writeCount);

                bs.Flush();
            }

            return fi;
        }
开发者ID:debop,项目名称:NFramework,代码行数:22,代码来源:AbstractFtpFixture.cs


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