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


C# BufferedStream.Read方法代码示例

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


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

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

示例2: Read_Arguments

 public static void Read_Arguments()
 {
     using (BufferedStream stream = new BufferedStream(new MemoryStream()))
     {
         byte[] array = new byte[10];
         Assert.Throws<ArgumentNullException>("array", () => stream.Read(null, 1, 1));
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.Read(array, -1, 1));
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.Read(array, 1, -1));
         Assert.Throws<ArgumentException>(() => stream.Read(array, 9, 2));
     }
 }
开发者ID:neris,项目名称:corefx,代码行数:11,代码来源:BufferedStream.InvalidParameters.cs

示例3: ToTransportMessage

		public static TransportMessage ToTransportMessage(this SqsTransportMessage sqsTransportMessage, IAmazonS3 amazonS3, SqsConnectionConfiguration connectionConfiguration)
        {
            var messageId = sqsTransportMessage.Headers[Headers.MessageId];

			var result = new TransportMessage(messageId, sqsTransportMessage.Headers);

            if (!string.IsNullOrEmpty(sqsTransportMessage.S3BodyKey))
            {
                var s3GetResponse = amazonS3.GetObject(connectionConfiguration.S3BucketForLargeMessages, sqsTransportMessage.S3BodyKey);
                result.Body = new byte[s3GetResponse.ResponseStream.Length];
                using (BufferedStream bufferedStream = new BufferedStream(s3GetResponse.ResponseStream))
                {
                    int count;
                    int transferred = 0;
                    while ((count = bufferedStream.Read(result.Body, transferred, 8192)) > 0)
                    {
                        transferred += count;
                    }
                }
            }
            else
			{
				result.Body = Convert.FromBase64String(sqsTransportMessage.Body);
			}

            result.TimeToBeReceived = sqsTransportMessage.TimeToBeReceived;

			if (sqsTransportMessage.ReplyToAddress != null)
			{
				result.Headers[Headers.ReplyToAddress] = sqsTransportMessage.ReplyToAddress.ToString();
			}

            return result;
        }
开发者ID:briangoncalves,项目名称:NServiceBus.AmazonSQS,代码行数:34,代码来源:SqsMessageExtensions.cs

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

示例5: DumpResource

 // ----------------- Dumping a .resources file ------------------
 public DumpResource(String filename)
 {
     BufferedStream stream = new BufferedStream(Console.OpenStandardOutput());
       Out = new StreamWriter(stream, new UTF8Encoding());
       ResourceReader rr;
       if (filename.Equals("-")) {
     BufferedStream input = new BufferedStream(Console.OpenStandardInput());
     // A temporary output stream is needed because ResourceReader expects
     // to be able to seek in the Stream.
     byte[] contents;
     {
       MemoryStream tmpstream = new MemoryStream();
       byte[] buf = new byte[1024];
       for (;;) {
     int n = input.Read(buf, 0, 1024);
     if (n == 0)
       break;
     tmpstream.Write(buf, 0, n);
       }
       contents = tmpstream.ToArray();
       tmpstream.Close();
     }
     MemoryStream tmpinput = new MemoryStream(contents);
     rr = new ResourceReader(tmpinput);
       } else {
     rr = new ResourceReader(filename);
       }
       foreach (DictionaryEntry entry in rr) // uses rr.GetEnumerator()
     DumpMessage(entry.Key as String, null, entry.Value as String);
       rr.Close();
       Out.Close();
       stream.Close();
 }
开发者ID:WalkOnCode,项目名称:android_real_web_server,代码行数:34,代码来源:msgunfmt.cs

示例6: ReadStream

		//client side on wp didn't has BufferedStream because this, I'm need made
		//the implementation style it...
		protected MemoryStream ReadStream(BufferedStream stream, int bufferSize)
		{
			byte[] streamSize = new byte[4];
			stream.Read(streamSize, 0, streamSize.Length);
			int totalStreamSize = BitConverter.ToInt32(streamSize, 0);

			return ReadStream(stream, bufferSize, totalStreamSize);
		}
开发者ID:sergiosilvajr,项目名称:mpos,代码行数:10,代码来源:AbstractServer.cs

示例7: ToByte

        public static Byte[] ToByte(this Stream InputStream)
        {
            BufferedStream bf = new BufferedStream(InputStream);
            byte[] buffer = new byte[InputStream.Length];
            bf.Read(buffer, 0, buffer.Length);

            return buffer;
        }
开发者ID:rafaelberrocalj,项目名称:BPA,代码行数:8,代码来源:ConvertMethods.cs

示例8: convertFileToBufferData

 public static byte[] convertFileToBufferData(string path)
 {
     FileStream fs = new FileStream(path,FileMode.Open);
     BufferedStream bf = new BufferedStream(fs);
     byte[] buffer = new byte[bf.Length];
     bf.Read(buffer, 0, buffer.Length);
     byte[] buffer_new = buffer;
     return buffer_new;
 }
开发者ID:geekprogramming,项目名称:GPManagement,代码行数:9,代码来源:ConvertUtil.cs

示例9: Read

        public void Read(byte[] data)
        {
            if (data == null || data.Length == 0) return;

            using (var buffer = new BufferedStream(new MemoryStream(data)))
            {
                var head = new byte[4];
                buffer.Read(head, 0, head.Length);
                ReadHead(head);

                if (this.Length > 0)
                {
                    var body = new byte[this.Length];
                    buffer.Read(body, 0, body.Length);
                    ReadBody(body);
                    ParseBody();
                }
            }
        }
开发者ID:BeanHsiang,项目名称:Greedy,代码行数:19,代码来源:MySqlPacket.cs

示例10: TwoPlusTwo

 static TwoPlusTwo()
 {
     using (BufferedStream reader = new BufferedStream(new FileStream(HAND_RANK_DATA_FILENAME, FileMode.Open)))
     {
         reader.Read(b, 0, tableSize);
     }
     //for (int i = 0; i < HAND_RANK_SIZE; i++)
     //{
     //    HR[i] = BitConverter.ToInt32(b, i*4);
     //}
 }
开发者ID:cheng93,项目名称:TexasHoldem,代码行数:11,代码来源:TwoPlusTwo.cs

示例11: CalculateHash

        /// <exception cref="IOException">The underlying stream is null or closed. </exception>
        /// <exception cref="DirectoryNotFoundException">The specified path is invalid, (for example, it is on an unmapped drive). </exception>
        /// <exception cref="UnauthorizedAccessException"><paramref name="path" /> specified a directory.-or- The caller does not have the required permission. </exception>
        /// <exception cref="FileNotFoundException">The file specified in <paramref name="path" /> was not found. </exception>
        /// <exception cref="CryptographicUnexpectedOperationException"><see cref="F:System.Security.Cryptography.HashAlgorithm.HashValue" /> is null. </exception>
        /// <exception cref="ObjectDisposedException">The object has already been disposed.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="oldValue" /> is null. </exception>
        /// <exception cref="ArgumentException"><paramref name="oldValue" /> is the empty string (""). </exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        /// <exception cref="OperationCanceledException">The token has had cancellation requested.</exception>
        public string CalculateHash(string file, HashAlgorithm algorithm, CancellationToken token)
        {
            byte[] buffer;
            byte[] oldBuffer;
            int bytesRead;
            int oldBytesRead;
            long size;
            long totalBytesRead = 0;
            using (var bufferedStream = new BufferedStream(File.OpenRead(file)))
            {
                using (algorithm)
                {
                    size = bufferedStream.Length;
                    buffer = new byte[4096];
                    bytesRead = bufferedStream.Read(buffer, 0, buffer.Length);
                    totalBytesRead += bytesRead;

                    do
                    {
                        token.ThrowIfCancellationRequested();
                        oldBytesRead = bytesRead;
                        oldBuffer = buffer;

                        buffer = new byte[4096];
                        bytesRead = bufferedStream.Read(buffer, 0, buffer.Length);
                        totalBytesRead += bytesRead;

                        if (bytesRead == 0)
                        {
                            algorithm.TransformFinalBlock(oldBuffer, 0, oldBytesRead);
                        }
                        else
                        {
                            algorithm.TransformBlock(oldBuffer, 0, oldBytesRead, oldBuffer, 0);
                        }
                        HashProgressUpdate?.Invoke(this, new ProgressEventArgs((double) totalBytesRead*100/size));
                    } while (bytesRead != 0);
                    return BitConverter.ToString(algorithm.Hash).Replace("-", string.Empty).ToUpper();
                }
            }
        }
开发者ID:5oundtech,项目名称:WoblaExplorer,代码行数:51,代码来源:ChecksumCalculators.cs

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

示例13: CreateFileFromStream

 public static void CreateFileFromStream(Stream stream, string destination)
 {
     using (BufferedStream bufferedStream = new BufferedStream(stream))
     {
         using (FileStream fileStream = File.OpenWrite(destination))
         {
             byte[] buffer = new byte[8192];
             int count;
             while ((count = bufferedStream.Read(buffer, 0, buffer.Length)) > 0)
                 fileStream.Write(buffer, 0, count);
         }
     }
 }
开发者ID:jcore,项目名称:JCore.SitecoreModules.ePubStudio,代码行数:13,代码来源:RenderItemHelper.cs

示例14: GetResponseContentBody

        /// <summary>
        /// Gets the content body of the response.
        /// </summary>
        /// <remarks>
        /// The content body is assumed to be UTF8, consistent with the handling of <c>PutObjectRequest.ContentBody</c>.
        /// </remarks>
        /// <param name="response">The response to process.</param>
        /// <param name="encoding">The encoding of the body, or UTF8 if null.</param>
        /// <returns>The textual content of the response body.</returns>
        public static string GetResponseContentBody(this GetObjectResponse response, Encoding encoding = null)
        {
            if (encoding == null) encoding = Encoding.UTF8;

            var s = new MemoryStream();
            BufferedStream bufferedStream = new BufferedStream(response.ResponseStream);
            byte[] buffer = new byte[ushort.MaxValue];
            int bytesRead = 0;
            while ((bytesRead = bufferedStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                s.Write(buffer, 0, bytesRead);
            }

            return encoding.GetString(s.ToArray());
        }
开发者ID:pbutlerm,项目名称:dataservices-sdk-dotnet,代码行数:24,代码来源:Utility.cs

示例15: VrTexture

        protected ushort TextureWidth; // Vr Texture Width

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Open a Vr texture from a file.
        /// </summary>
        /// <param name="file">Filename of the file that contains the texture data.</param>
        public VrTexture(string file)
        {
            byte[] data;
            try
            {
                using (BufferedStream stream = new BufferedStream(new FileStream(file, FileMode.Open, FileAccess.Read), 0x1000))
                {
                    data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                }
            }
            catch { data = new byte[0]; }

            TextureData = data;
        }
开发者ID:memerdot,项目名称:puyotools,代码行数:25,代码来源:VrTexture.cs


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