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


C# BufferedStream.Close方法代码示例

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


在下文中一共展示了BufferedStream.Close方法的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: 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

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

示例4: Main

        static void Main(string[] args)
        {
            string remoteName = Environment.MachineName;

            Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            clientSocket.Connect(new IPEndPoint(Dns.GetHostEntry(remoteName).AddressList[0], 1800));

            Console.WriteLine("Client is connected.\n");

            using (Stream netStream = new NetworkStream(clientSocket, true), 
                bufStream = new BufferedStream(netStream, streamBufferSize))
            {
                Console.WriteLine("NetworkStream {0} seeking.\n", bufStream.CanSeek ? "supports" : "does not support");

                if (bufStream.CanWrite)
                {
                    SendData(netStream, bufStream);
                }

                if (bufStream.CanRead)
                {
                    ReceiveData(netStream, bufStream);
                }

                Console.WriteLine("\nShutting down the connection.");

                bufStream.Close();
            }
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:30,代码来源:Program.cs

示例5: checkUTFWithoutBOM

 ////////////////////////////////////////////////////////////////
 //    OPEN SOURCE CODE
 //    Based on the Utf8Checker class found here: http://utf8checker.codeplex.com/
 ////////////////////////////////////////////////////////////////
 private static bool checkUTFWithoutBOM(string PhysicalPath)
 {
     BufferedStream fstream = new BufferedStream(File.OpenRead(PhysicalPath));
     bool res = IsUtf8(fstream);
     fstream.Close();
     return res;
 }
开发者ID:jmalarcon,项目名称:FileEncodingConverter,代码行数:11,代码来源:Program.cs

示例6: Buffered_Stream_Closes_Output_On_Close

 public void Buffered_Stream_Closes_Output_On_Close()
 {
     var mock = new Mock<Stream>();
     Stream stream= mock.Object;
     mock.Setup(s => s.CanRead).Returns(true);
     BufferedStream bs = new BufferedStream(stream);
     bs.Close();
     mock.Verify(s=>s.Close());
 }
开发者ID:davedf,项目名称:tdd-exercises-csharp,代码行数:9,代码来源:HelloWorldMockExample.cs

示例7: Buffered_Stream_Rethrows_Exceptions_From_Underlying_Stream

        public void Buffered_Stream_Rethrows_Exceptions_From_Underlying_Stream()
        {
            var mock = new Mock<Stream>();
            Stream stream = mock.Object;
            mock.SetupGet(d => d.CanRead).Returns(true);
            mock.Setup(d=>d.Close()).Throws(new IOException());

            BufferedStream bs = new BufferedStream(stream);
            bs.Close();
        }
开发者ID:davedf,项目名称:tdd-exercises-csharp,代码行数:10,代码来源:HelloWorldMockExample.cs

示例8: Main

        static void Main(string[] args)
        {
            string fileName = "test2";
            //StreamReader sr = new StreamReader(fileName + ".vex", Encoding.ASCII);
            FileStream fs = new FileStream(fileName + ".vex", FileMode.Open, FileAccess.Read);
            BufferedStream bs = new BufferedStream(fs);
            JsonLexer lx = new JsonLexer(bs);
            List<Token> tokens = lx.Lex();
            fs.Close();
            bs.Close();
               // Document doc = JavaScriptConvert.DeserializeObject<Document>(json);
            Debug.WriteLine(tokens);

            //var g = from s in doc.Library.Items
            //        from l in s.Timeline.Layers
            //        select
            //            new
            //            {
            //                Name = s.Timeline.Name,
            //                Frames =
            //                    from f in l.Frames
            //                    where f.StartFrame == f.FrameIndex
            //                    select f
            //            };
            //try
            //{
            //    foreach (var tl in g)
            //    {
            //        foreach (var e in tl.Frames)
            //        {
            //            if (e != null)
            //            {
            //                Debug.WriteLine("tl: " + tl.Name + " \tl:" + e.LayerIndex + " f:" + e.FrameIndex + " \tsf:" + e.StartFrame);
            //            }
            //        }
            //    }
            //}
            //catch(Exception)
            //{
            //}

            //SwfCompilationUnit scu;
            //VexObject v;
            //Debug.WriteLine(Convert(fileName + ".swf", out scu, out v));
            //var tags = from ts in scu.Tags
            //        where ts.TagType == TagType.DefineSprite
            //        select (DefineSpriteTag)ts;

            //foreach (var t in tags)
            //{
            //    Debug.WriteLine(t.SpriteId + " t: " + t.FrameCount);
            //}
        }
开发者ID:Hamsand,项目名称:Swf2XNA,代码行数:53,代码来源:Program.cs

示例9: doReceive

        public void doReceive(Socket socket)
        {
            Console.WriteLine("输入存储路径");
           string filesPath= @Console.ReadLine();
            NetworkStream nsw = null;
            BufferedStream bsw = null;
            NetworkStream nsr = null;
            BufferedStream bsr = null;

            try
            {
                nsw = new NetworkStream(socket);
                bsw = new BufferedStream(nsw);
                nsr = new NetworkStream(socket);
                bsr = new BufferedStream(nsr);

                Console.WriteLine("************开始接收XML文件**************");
                receiveFile(xmlPath, bsr);
                Console.WriteLine("************成功接收XML文件**************");

                readXML(filesPath, bsr);

            }
            catch (Exception e) { }
            finally
            {
                if (bsw != null)
                {
                    bsw.Close();
                    bsw = null;
                }
                if (nsw != null)
                {
                    nsw.Close();
                    nsw = null;

                }


                if (bsr != null)
                {
                    bsr.Close();
                    bsr = null;
                }
                if (nsr != null)
                {
                    nsr.Close();
                    nsr = null;

                }
            }
        }
开发者ID:ITPuppy,项目名称:myRepo,代码行数:52,代码来源:ReceiveFile.cs

示例10: Load

        public Dataset Load(FileInfo file)
        {
            Stream ins = null;
            DcmParser parser = null;
            Dataset ds = null;

            try
            {
                try
                {
                    ins = new BufferedStream(new FileStream(file.FullName, FileMode.Open, FileAccess.Read));
                    parser = new DcmParser(ins);
                    FileFormat format = parser.DetectFileFormat();
                    if (format != null)
                    {
                        ds = new Dataset();
                        parser.DcmHandler = ds.DcmHandler;
                        parser.ParseDcmFile(format, Tags.PixelData);

                        //MessageBox.Show("Pomyślnie!");

                        return ds;
                    }
                    else
                    {
                        //MessageBox.Show("failed!");
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.StackTrace);
                }
            }
            finally
            {
                if (ins != null)
                {
                    try
                    {
                        ins.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }

            return null;
        }
开发者ID:blackhawk1990,项目名称:MUCalc,代码行数:49,代码来源:DICOMLoad.cs

示例11: DumpResource

 public DumpResource(String baseDirectory, String resourceName, String cultureName)
 {
     // We are only interested in the messages belonging to the locale
       // itself, not in the inherited messages. Therefore we instantiate just
       // the GettextResourceSet, not a GettextResourceManager.
       Assembly satelliteAssembly =
     GetSatelliteAssembly(baseDirectory, resourceName, cultureName);
       GettextResourceSet catalog =
     InstantiateResourceSet(satelliteAssembly, resourceName, cultureName);
       BufferedStream stream = new BufferedStream(Console.OpenStandardOutput());
       Out = new StreamWriter(stream, new UTF8Encoding());
       Dump(catalog);
       Out.Close();
       stream.Close();
 }
开发者ID:ryo,项目名称:netbsd-src,代码行数:15,代码来源:msgunfmt.cs

示例12: WriteResource

 // Read all msgid/msgstr pairs (each string being NUL-terminated and
 // UTF-8 encoded) and write the .resources file to the given filename.
 WriteResource(String filename)
 {
     Stream input = new BufferedStream(Console.OpenStandardInput());
       reader = new StreamReader(input, new UTF8Encoding());
       if (filename.Equals("-")) {
     BufferedStream output = new BufferedStream(Console.OpenStandardOutput());
     // A temporary output stream is needed because ResourceWriter.Generate
     // expects to be able to seek in the Stream.
     MemoryStream tmpoutput = new MemoryStream();
     ResourceWriter rw = new ResourceWriter(tmpoutput);
     ReadAllInput(rw);
     #if __CSCC__
     // Use the ResourceReader to check against pnet-0.6.0 ResourceWriter
     // bug.
     try {
       ResourceReader rr = new ResourceReader(new MemoryStream(tmpoutput.ToArray()));
       foreach (System.Collections.DictionaryEntry entry in rr);
     } catch (IOException e) {
       throw new Exception("class ResourceWriter is buggy", e);
     }
     #endif
     tmpoutput.WriteTo(output);
     rw.Close();
     output.Close();
       } else {
     #if __CSCC__
     MemoryStream tmpoutput = new MemoryStream();
     ResourceWriter rw = new ResourceWriter(tmpoutput);
     ReadAllInput(rw);
     // Use the ResourceReader to check against pnet-0.6.0 ResourceWriter
     // bug.
     try {
       ResourceReader rr = new ResourceReader(new MemoryStream(tmpoutput.ToArray()));
       foreach (System.Collections.DictionaryEntry entry in rr);
     } catch (IOException e) {
       throw new Exception("class ResourceWriter is buggy", e);
     }
     BufferedStream output = new BufferedStream(new FileStream(filename, FileMode.Create, FileAccess.Write));
     tmpoutput.WriteTo(output);
     rw.Close();
     output.Close();
     #else
     ResourceWriter rw = new ResourceWriter(filename);
     ReadAllInput(rw);
     rw.Close();
     #endif
       }
 }
开发者ID:WalkOnCode,项目名称:android_real_web_server,代码行数:50,代码来源:msgfmt.cs

示例13: GeneratePDF

        //-------------------------------------------------------------------------------------------
        /// <summary>
        /// This method generates a PDF copy of the check to be printed on standard 3 sheet check paper.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="invoice"></param>
        /// <returns>Returns the path to the PDF file on the local file system.</returns>
        public string GeneratePDF()
        {
            string filepath = System.IO.Path.GetTempFileName() + ".pdf";

               FileStream fos = new FileStream(filepath, FileMode.Create);
               BufferedStream bos = new BufferedStream(fos);
               PDF pdf = new PDF(bos);
               Page p = new PDFjet.NET.Page(pdf, Letter.PORTRAIT);

               // these two variables are lazy loaded from the db so we cache them here
               Logistics_Addresses payeeAddress = PayeeAddress;
               string payeeName = PayeeName;
               for (int i = 0; i < 3; i++)
               {
                    int yoffset = i * 251;
                    // these lines draw a seperation line between the 3 parts on a full check sheet which is useful for debugging
                    //Line l = new Line(0, yoffset, 400, yoffset);
                    //l.DrawOn(p);
                    //yoffset += 25;
                    // draw the date
                    DrawText(pdf, p, PostAt.ToString("MM/dd/yy"), 515, yoffset + 70);

                    int xnameoffset = (i == 0) ? 85 : 30;
                    DrawText(pdf, p, payeeName, xnameoffset, yoffset + 105);
                    DrawText(pdf, p, "**" + String.Format("{0:f}", Amount), 500, yoffset + 107);
                    int amountnodecimals = Convert.ToInt32(Math.Truncate(Amount));
                    int decimals = Convert.ToInt32((Amount - amountnodecimals) * 100);
                    DrawText(pdf, p, NumberConvertor.NumberToText(amountnodecimals).ToLower() + " dollar(s) " + NumberConvertor.NumberToText(decimals).ToLower() + " cents *****************", 30, yoffset + 130);

                    // draw the mailing address for windowed envelopes
                    string mailingAddress = (payeeAddress == null) ? "" : payeeAddress.ToString();
                    if (!String.IsNullOrEmpty(mailingAddress))
                    {
                         string[] addressLines = Regex.Split(mailingAddress, "\r\n");
                         for (int a = 0; a < addressLines.Length; a++)
                         {
                              DrawText(pdf, p, addressLines[a], 50, yoffset + 155 + (a * 12));
                         }
                    }

                    // draw the memo
                    DrawText(pdf, p, Memo, 30, yoffset + 215);
               }
               pdf.Flush();
               bos.Close();

               return filepath;
        }
开发者ID:weavver,项目名称:data,代码行数:55,代码来源:Accounting_Checks.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: Compress

 public static void Compress(Stream instream, Stream outstream, int blockSize)
 {
     BufferedStream inStream = new BufferedStream(outstream);
     inStream.WriteByte(0x42);
     inStream.WriteByte(90);
     BufferedStream stream2 = new BufferedStream(instream);
     int num = stream2.ReadByte();
     BZip2OutputStream stream3 = new BZip2OutputStream(inStream);
     while (num != -1)
     {
         stream3.WriteByte((byte) num);
         num = stream2.ReadByte();
     }
     stream2.Close();
     stream3.Close();
 }
开发者ID:bmadarasz,项目名称:ndihelpdesk,代码行数:16,代码来源:BZip2.cs


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