當前位置: 首頁>>代碼示例>>C#>>正文


C# BufferedStream.Write方法代碼示例

本文整理匯總了C#中System.IO.BufferedStream.Write方法的典型用法代碼示例。如果您正苦於以下問題:C# BufferedStream.Write方法的具體用法?C# BufferedStream.Write怎麽用?C# BufferedStream.Write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.BufferedStream的用法示例。


在下文中一共展示了BufferedStream.Write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ShowUsage

        public override void ShowUsage()
        {
            //BufferedStream類主要也是用來處理流數據的,但是該類主要的功能是用來封裝其他流類。
            //為什麽要封裝其他流類,這麽做的意義是什麽?按照微軟的話說主要是減少某些流直接操作存儲設備的時間。
            //對於一些流來說直接向磁盤中存儲數據這種做法的效率並不高,用BufferedStream包裝過的流,先在內存中進行統一的處理再向磁盤中寫入數據,也會提高寫入的效率。

            Console.WriteLine("BufferedStream類主要也是用來處理流數據的,但是該類主要的功能是用來封裝其他流類。");
            FileStream fileStream1 = File.Open(@"C:\NewText.txt", FileMode.OpenOrCreate, FileAccess.Read);  //讀取文件流
            FileStream fileStream2 = File.Open(@"C:\Text2.txt", FileMode.OpenOrCreate, FileAccess.Write);   //寫入文件流

            byte[] array4 = new byte[4096];

            BufferedStream bufferedInput = new BufferedStream(fileStream1);         //封裝文件流
            BufferedStream bufferedOutput = new BufferedStream(fileStream2);        //封裝文件流

            int byteRead = bufferedInput.Read(array4, 0, array4.Length);
            bufferedOutput.Write(array4, 0, array4.Length);

            //= bufferedInput.Read(array4, 0, 4096);
            while (byteRead > 0)                                                    //讀取到了數據
            {
                bufferedOutput.Write(array4, 0, byteRead);
                Console.WriteLine(byteRead);
                break;
            };
            bufferedInput.Close();
            bufferedOutput.Close();
            fileStream1.Close();
            fileStream2.Close();
            Console.ReadKey();
        }
開發者ID:BerdyPango,項目名稱:Researches,代碼行數:31,代碼來源:BufferedStreamUsage.cs

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

示例3: Write_Arguments

 public static void Write_Arguments()
 {
     using (BufferedStream stream = new BufferedStream(new MemoryStream()))
     {
         byte[] array = new byte[10];
         Assert.Throws<ArgumentNullException>("array", () => stream.Write(null, 1, 1));
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(array, -1, 1));
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(array, 1, -1));
         Assert.Throws<ArgumentException>(() => stream.Write(array, 9, 2));
     }
 }
開發者ID:neris,項目名稱:corefx,代碼行數:11,代碼來源:BufferedStream.InvalidParameters.cs

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

示例5: GetCompressedFileBytes

        public static IEnumerable<byte> GetCompressedFileBytes(string file)
        {
            if (CheckSignature(file, 4, ZipSig) || CheckSignature(file, 3, GZipSig))
            {
                Console.WriteLine($"{file} seems to be a compressed file");

                return GetFileBytes(file);
            }

            // TODO: add blacklist for known compressed formats
            byte[] bytes = GetFileBytes(file).ToArray();
            using (MemoryStream mem = new MemoryStream())
            {
                using (BufferedStream buffer = new BufferedStream(new GZipStream(mem, CompressionMode.Compress)))
                    buffer.Write(bytes, 0, bytes.Length);

                byte[] result = mem.ToArray();
                Console.WriteLine($"{bytes.Length} -> {result.Length}");

                if (bytes.Length < result.Length)
                    return bytes;

                return result;
            }
        }
開發者ID:Spanfile,項目名稱:BackupUtil,代碼行數:25,代碼來源:FileHelper.cs

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

示例7: BufferColumnStream

        public void BufferColumnStream()
        {
            var data = new byte[1024];

            var memoryStream = new MemoryStream();

            Api.JetBeginTransaction(this.sesid);
            Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
            using (var stream = new BufferedStream(new ColumnStream(this.sesid, this.tableid, this.columnidLongText), SystemParameters.LVChunkSizeMost))
            {
                for (int i = 0; i < 10; ++i)
                {
                    stream.Write(data, 0, data.Length);
                    memoryStream.Write(data, 0, data.Length);
                }
            }

            this.UpdateAndGotoBookmark();
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            var hasher = new SHA512Managed();
            memoryStream.Position = 0;
            var expected = hasher.ComputeHash(memoryStream);

            using (var stream = new BufferedStream(new ColumnStream(this.sesid, this.tableid, this.columnidLongText), SystemParameters.LVChunkSizeMost))
            {
                var actual = hasher.ComputeHash(stream);
                CollectionAssert.AreEqual(expected, actual);
            }
        }
開發者ID:ayende,項目名稱:managed-esent,代碼行數:30,代碼來源:ColumnStreamTests.cs

示例8: DownloadContent

        internal static void DownloadContent(string url, string path, bool static_content)
        {
            if(File.Exists(path)) {
                DateTime last_updated_time = File.GetLastWriteTime (path);
                if(static_content || DateTime.Now - last_updated_time < CACHE_TIME) {
                    return;
                }
            }

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.UserAgent = "Banshee Recommendation Plugin";
            request.KeepAlive = false;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream stream = response.GetResponseStream();

            FileStream file_stream = File.OpenWrite(path);
            BufferedStream buffered_stream = new BufferedStream(file_stream);

            byte [] buffer = new byte[8192];
            int read;

            while(true) {
                read = stream.Read(buffer, 0, buffer.Length);
                if(read <= 0) {
                    break;
                }

                buffered_stream.Write(buffer, 0, read);
            }

            buffered_stream.Close();
            response.Close();
        }
開發者ID:jrmuizel,項目名稱:banshee-unofficial-plugins,代碼行數:34,代碼來源:RecommendationUtilities.cs

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

示例10: Compress

        public static byte[] Compress(byte[] inputData)
        {
            if (inputData == null)
                throw new ArgumentNullException("inputData");

            using (var compressIntoMs = MiNetServer.MemoryStreamManager.GetStream())
            {
                using (var gzs = new BufferedStream(new GZipStream(compressIntoMs, CompressionMode.Compress), 2*4096))
                {
                    gzs.Write(inputData, 0, inputData.Length);
                }
                return compressIntoMs.ToArray();
            }
        }
開發者ID:CRBairdUSA,項目名稱:MiNET,代碼行數:14,代碼來源:Compression.cs

示例11: Compress

        private static int BUFFER_SIZE = 8 * 1024 * 1024; //8MB //64kB

        public static byte[] Compress(byte[] inputData)
        {
            if (inputData == null)
                throw new ArgumentNullException("inputData must be non-null");

            using (var compressIntoMs = new MemoryStream())
            {
                using (var gzs = new BufferedStream(new GZipStream(compressIntoMs,
                 CompressionMode.Compress), BUFFER_SIZE))
                {
                    gzs.Write(inputData, 0, inputData.Length);
                }
                return compressIntoMs.ToArray();
            }
        }
開發者ID:DacoTaco,項目名稱:AudioStreaming,代碼行數:17,代碼來源:Compressor.cs

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

示例13: getQRCode

        public void getQRCode()
        {
            string url_login = "https://ssl.ptlogin2.qq.com/ptqrshow?appid=501004106&e=0&l=M&s=5&d=72&v=4&t=0.4634378447663039";
            httpClient.MaxResponseContentBufferSize = 256000;
            httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
            HttpResponseMessage response = httpClient.GetAsync(new Uri(url_login)).Result;
            HttpRequestMessage request = response.RequestMessage;
            if (response.StatusCode != HttpStatusCode.OK)
            {
                //異常,
            }
            SetCookies = response.Headers.GetValues("Set-Cookie");

            FileStream fs = new FileStream(dir + "code.png", FileMode.Create);       
            BufferedStream sw = new BufferedStream(fs,1024);
            byte[] imgdata = null;
            imgdata = response.Content.ReadAsByteArrayAsync().Result;
            //var data  =  response.Content.ReadAsByteArrayAsync().Result;
            sw.Write(imgdata,0, imgdata.Length);
            sw.Close();
            fs.Close();
        }
開發者ID:darkness080118,項目名稱:DarknessChatMachine,代碼行數:22,代碼來源:Client.cs

示例14: CreatePTableFile

        public static void CreatePTableFile(string filename, long ptableSize, int indexEntrySize, int cacheDepth = 16)
        {
            Ensure.NotNullOrEmpty(filename, "filename");
            Ensure.Nonnegative(cacheDepth, "cacheDepth");

            var sw = Stopwatch.StartNew();
            var tableId = Guid.NewGuid();
            using (var fs = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None,
                                           DefaultSequentialBufferSize, FileOptions.SequentialScan))
            {
                fs.SetLength((long)ptableSize);
                fs.Seek(0, SeekOrigin.Begin);

                var recordCount = (long)((ptableSize - PTableHeader.Size - PTable.MD5Size) / (long)indexEntrySize);
                using (var md5 = MD5.Create())
                using (var cs = new CryptoStream(fs, md5, CryptoStreamMode.Write))
                using (var bs = new BufferedStream(cs, DefaultSequentialBufferSize))
                {
                    // WRITE HEADER
                    var headerBytes = new PTableHeader(Version).AsByteArray();
                    cs.Write(headerBytes, 0, headerBytes.Length);

                    // WRITE INDEX ENTRIES
                    var buffer = new byte[indexEntrySize];
                    for (long i = 0; i < recordCount; i++)
                    {
                        bs.Write(buffer, 0, indexEntrySize);
                    }
                    bs.Flush();
                    cs.FlushFinalBlock();

                    // WRITE MD5
                    var hash = md5.Hash;
                    fs.Write(hash, 0, hash.Length);
                }
            }
            Console.WriteLine("Created PTable File[{0}, size of {1}] in {2}.", tableId, ptableSize, sw.Elapsed);
        }
開發者ID:SzymonPobiega,項目名稱:EventStore,代碼行數:38,代碼來源:opening_a_ptable_with_more_than_32bits_of_records.cs

示例15: Process

        void Process(string inPath, string outPath)
        {
            var buffer = new byte[BufferSize];
            var generator = BuildGenerator();

            using (var reader = new BufferedStream(new FileStream(inPath, FileMode.Open)))
            using (var writer = new BufferedStream(new FileStream(outPath, FileMode.Create)))
            {
                while (true)
                {
                    var read = reader.Read(buffer, 0, BufferSize);
                    if (read == 0)
                    {
                        break;
                    }
                    for (var i = 0; i < read; i++)
                    {
                        generator.MoveNext();
                        buffer[i] = (byte) (buffer[i] ^ generator.Current);
                    }
                    writer.Write(buffer, 0, read);
                }
            }
        }
開發者ID:JacekPrzemieniecki,項目名稱:University,代碼行數:24,代碼來源:MainWindow.cs


注:本文中的System.IO.BufferedStream.Write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。