当前位置: 首页>>代码示例>>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;未经允许,请勿转载。