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


C# BufferedStream.Read方法代码示例

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


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

示例1: 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:geoffkizer,项目名称:corefx,代码行数:11,代码来源:BufferedStream.InvalidParameters.cs

示例2: TestBuffering

        public void TestBuffering(long length, int internalBufferCount, int clientBufferCount)
        {
            var random = new Random();
            var remoteData = new byte[length];
            random.NextBytes(remoteData);
            var buffer = new byte[clientBufferCount];
            var clientData = new List<byte>();
            Func<long, byte[], int> reader = (remoteOffset, buff) =>
            {
                int toRead = Math.Min(buff.Length, (int)(length - remoteOffset));
                Buffer.BlockCopy(remoteData, (int) remoteOffset, buff, 0, toRead);
                return  toRead;
            };
            var bufferedStream = new BufferedStream(length, reader, internalBufferCount);
            while (true)
            {
                int read = bufferedStream.Read(buffer, 0, buffer.Length);
                clientData.AddRange(buffer.Take(read));
                if(read==0)
                    break;
                
            }

            Assert.Equal(remoteData, clientData);
        }
开发者ID:FeodorFitsner,项目名称:BeeHive,代码行数:25,代码来源:BufferedStreamTests.cs

示例3: WriteAfterRead_NonSeekableStream_Throws

        public void WriteAfterRead_NonSeekableStream_Throws()
        {
            var wrapped = new WrappedMemoryStream(canRead: true, canWrite: true, canSeek: false, data: new byte[] { 1, 2, 3, 4, 5 });
            var s = new BufferedStream(wrapped);

            s.Read(new byte[3], 0, 3);
            Assert.Throws<NotSupportedException>(() => s.Write(new byte[10], 0, 10));
        }
开发者ID:dotnet,项目名称:corefx,代码行数:8,代码来源:BufferedStreamTests.cs

示例4: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BufferedStream bs2;
         MemoryStream memstr2;
         if(File.Exists("Co5604Test.tmp"))
             File.Delete("Co5604Test.tmp");
         strLoc = "Loc_857vi";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         bs2.Write(new Byte[]{65, 66}, 0, 2);
         bs2.Close();
         iCountTestcases++;
         try 
         {
             bs2.Flush();
             iCountErrors++;
             printerr("Error_2yc94! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_298uv! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_9t85y! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_09uf4";
         iCountTestcases++;
         try 
         {
             bs2.Write(new Byte[]{1,2,3}, 0, 3);
             iCountErrors++;
             printerr( "Error_129vc! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_27b99! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "ERror_0901v! Incorrect exception thrown, exc=="+exc.ToString());
         } 
         strLoc = "Loc_2099x";
         iCountTestcases++;
         try 
         {
             bs2.Read(new Byte[3], 0, 3);
             iCountErrors++;
             printerr( "Error_209cx! Expectede exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_t7587! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_20g8j! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_01990";
         iCountTestcases++;
         try 
         {
             bs2.Seek(54, SeekOrigin.Current);
             iCountErrors++;
             printerr( "Error_0190j! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_g6798! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_2998y! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_0939s";
         iCountTestcases++;
         try 
         {
             bs2.SetLength(100);
             iCountErrors++;
             printerr( "Error_209gb! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_989gh! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_0190x! Incorrect exception thrown, exc=="+exc.Message);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5604close.cs

示例5: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			BufferedStream bs2;
			MemoryStream memstr2;
			FileStream fs2;
			Int32 count;
			Byte[] bWriteArr, bReadArr;
			if(File.Exists("Co5616Test.tmp"))
				File.Delete("Co5616Test.tmp");			
			strLoc = "Loc_984yv";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			iCountTestcases++;
			try {
				bs2.Read(null, 0, 0);
				iCountErrors++;
				printerr( "Error_298yv! Expected exception not thrown");
			} catch (ArgumentNullException aexc) {
				printinfo("Info_g98b7! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_t8y78! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_9875g";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, -1, 0);
				iCountErrors++;
				printerr("Error_988bb! Expected exception not thrown");
			} catch (ArgumentOutOfRangeException aexc) {
				printinfo("Info_98yby! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_099hy! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_5g8ys";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, 0, -1);
				iCountErrors++;
				printerr( "Error_9t8yj! Expected exception not thrown");
			} catch (ArgumentOutOfRangeException aexc) {
				printinfo("Info_9488b! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_7687b! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_1228x";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			bs2.Write(new Byte[]{1}, 0, 1);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, 2, 0);
				iCountErrors++;
				printerr( "Error_3444j! Expected exception not thrown");
			} catch (ArgumentException aexc) {
				printinfo("Info_g8777! CAught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_t77gg! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_897yg";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			bs2.Write(new Byte[]{1}, 0, 1);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, 0, 2);
				iCountErrors++;
				printerr( "Error_98y8x! Expected exception not thrown");
			} catch (ArgumentException aexc) {
				printinfo("Info_g58yb! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_ytg78! Incorrect exception thrown, exc=="+exc.ToString());
			}			
			strLoc = "Loc_8g7yb";
			count = 0;
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			bWriteArr = new Byte[100];
			for(int i = 0 ; i < 100 ; i++) 
				bWriteArr[i] = (Byte)i;
			bs2.Write(bWriteArr, 0, 100);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5616read_barr_i_i.cs

示例6: ReadOnUnreadableStream_Throws_NotSupportedException

 public static void ReadOnUnreadableStream_Throws_NotSupportedException()
 {
     using (WrappedMemoryStream underlying = new WrappedMemoryStream(false, true, true))
     using (BufferedStream stream = new BufferedStream(underlying))
     {
         Assert.Throws<NotSupportedException>(() => stream.Read(new byte[] { 1 }, 0, 1));
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:8,代码来源:BufferedStream.InvalidParameters.cs

示例7: DeserializeChunk

    /// <summary>
    /// Deserializes the chunk.
    /// </summary>
    /// <param name="stream">Stream.</param>
    public void DeserializeChunk(BufferedStream stream)
    {
        lock (this.voxelDataLockObject)
        {
            // Read chunk data
            byte[] chunkData = new byte[EstimatedChunkBytes(this.width, this.height, this.depth)];
            stream.Read (chunkData, 0, EstimatedChunkBytes (this.width, this.height, this.depth));

            int counter = 0;

            // Parse chunk data
            for (int x = 0; x < this.width; x++)
            {
                for (int y = 0; y < this.height; y++)
                {
                    for (int z = 0; z < this.depth; z++)
                    {
                        short blockId = System.BitConverter.ToInt16(chunkData, counter);
                        byte rotation = chunkData[counter+2];
                        this.voxelData[x][y][z] = new VoxelData(blockId);
                        this.voxelData[x][y][z].rotation = rotation;
                        counter += 3;
                    }
                }
            }
        }
    }
开发者ID:geekytime,项目名称:cubicworld,代码行数:31,代码来源:CubicTerrainData.cs

示例8: SendFile

        //
        private void SendFile(string fileloc, string id)
        {
            try
            {
                IPEndPoint sendfileIEP = new IPEndPoint(IPAddress.Any, 0);
                UdpClient filesendSock = new UdpClient(sendfileIEP);

                IPEndPoint iep = (IPEndPoint)InClientList[id];
                iep.Port = 9003;    //파일전용 포트로 변경
                logWrite("SendFile() 파일전송 포트 변경 :" + iep.Port.ToString());

                FileInfo fi = new FileInfo(fileloc);
                logWrite("SendFile() FileInfo 인스턴스 생성 : " + fileloc);

                int read = 0;
                byte[] buffer = null;
                byte[] re = null;

                filesendSock.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 2000);

                if (fi.Exists == true)
                {
                    BufferedStream bs = new BufferedStream(new FileStream(fileloc, FileMode.Open, FileAccess.Read, FileShare.Read, 40960), 40960);

                    double sendfilesize = Convert.ToDouble(fi.Length);
                    double percent = (40960 / sendfilesize) * 100;
                    double total = 0.0;

                    lock (filesendSock)
                    {
                        while (true)
                        {
                            for (int i = 0; i < 3; i++) //udp 통신의 전송실패 방지
                            {
                                try
                                {
                                    logWrite("FileReceiver IP : " + iep.Address.ToString());
                                    logWrite("FileReceiver port : " + iep.Port.ToString());
                                    if (sendfilesize >= 40960.0)
                                        buffer = new byte[40960];
                                    else buffer = new byte[Convert.ToInt32(sendfilesize)];
                                    read = bs.Read(buffer, 0, buffer.Length);
                                    filesendSock.Send(buffer, buffer.Length, iep);
                                    //logWrite("filesendSock.Send() : " + i.ToString() + " 번째 시도!");
                                }
                                catch (Exception e)
                                {
                                    logWrite("SendFile() BufferedStream.Read() 에러 :" + e.ToString());
                                }
                                try
                                {
                                    re = filesendSock.Receive(ref iep);
                                    int reSize = int.Parse(Encoding.UTF8.GetString(re));
                                    if (reSize == buffer.Length) break;
                                }
                                catch (SocketException e1)
                                { }
                            }

                            if (re == null || re.Length == 0)
                            {
                                logWrite("filesendSock.Send() 상대방이 응답하지 않습니다. 수신자 정보 : " + iep.Address.ToString() + ":" + iep.Port.ToString());
                                break;
                            }
                            else
                            {
                                sendfilesize = (sendfilesize - 40960.0);
                                total += percent;
                                if (total > 100) total = 100.0;
                                string[] totalArray = (total.ToString()).Split('.');
                            }
                            if (total == 100.0)
                            {
                                logWrite("전송완료");
                                filesendSock.Close();
                            }
                            if (total == 100.0) break;
                        }
                    }
                }
                else
                {
                    logWrite("SendFile() 파일이 없음 : " + fileloc);
                }
            }
            catch (Exception exception)
            {
                logWrite(exception.ToString());
            }
        }
开发者ID:WeDoCrm,项目名称:server_product,代码行数:91,代码来源:MsgSvrForm.cs

示例9: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BufferedStream bs2;
         MemoryStream memstr2;
         if(File.Exists("Co5602Test.tmp"))
             File.Delete("Co5602Test.tmp");
         strLoc = "Loc_98yv7";
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream((Stream)null, 1);
             iCountErrors++;
             printerr( "Error_2yc83! Expected exception not thrown");
         } 
         catch (ArgumentNullException aexc) 
         {
             printinfo("Info_287c7! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_984yv! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_758xy";
         memstr2 = new MemoryStream();
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream(memstr2, 0);
             iCountErrors++;
             printerr( "Error_90838! Expected exception not thrown");
         } 
         catch (ArgumentOutOfRangeException aexc) 
         {
             printinfo( "Info_598by! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_198hg! Incorrect exception thrown, exc=="+exc.ToString());
         }
         memstr2.Close();
         strLoc = "Loc_567g7";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2, 2);
         bs2.Write(new Byte[]{65,66,67}, 0, 3);
         Byte[] b = new Byte[3];
         bs2.Position = 0;
         bs2.Read(b, 0, 3);
         for(int i = 0 ; i < b.Length ; i++) 
         {
             iCountTestcases++;
             if(b[i] != i+65) 
             {
                 iCountErrors++;
                 printerr( "Error_2958v! Expected=="+i+", got=="+b[i]);
             }
         }
         StreamReader sr2 = new StreamReader(memstr2);
         memstr2.Position = 0;
         iCountTestcases++;
         if(!sr2.ReadToEnd().Equals("ABC")) 
         {
             iCountTestcases++;
             printerr( "ERror_42987! Unexpected string on stream");
         }
         strLoc = "Loc_277gy";
         memstr2 = new MemoryStream();
         memstr2.Close();
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream(memstr2, 10);
             iCountErrors++;
             printerr("Error_2g8yb! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_578yg! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_3477c! Incorrect exception thrown, exc=="+exc.ToString());
         }
         m_PortSetEvent.Reset();
         Thread tcpListenerThread = new Thread(new ThreadStart(Co5603ctor_stream_i.StartListeningTcp));
         tcpListenerThread.Start();
         Console.WriteLine("Listening");
         Thread.Sleep( 1000 );
         m_PortSetEvent.WaitOne();
         Teleport("127.0.0.1");
         Thread.Sleep( 1000 );
         if(File.Exists("Co5602Test.tmp"))
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5603ctor_stream_i.cs

示例10: StartListeningTcp

    public static void StartListeningTcp() 
    {
        TcpThreadListener listener = new TcpThreadListener(0);
        NetworkStream ns = null;
        BufferedStream bs = null;

        try 
        {
            listener.Start();
            IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint;
            Interlocked.Exchange(ref iPortNumber, ipe.Port);
            Console.WriteLine("Using port: {0}", iPortNumber);
            m_PortSetEvent.Set();

            Socket s = listener.AcceptSocket();
            ns = new NetworkStream(s);
            bs = new BufferedStream( ns );   
            Byte[] b = new Byte[3];
            bs.Read(b, 0, 3);
            for(int i = 0 ; i < b.Length ; i++) 
            {
                if(b[i] != i) 
                {
                    iCountErrors++;
                    Console.WriteLine( "Error_4324! Expected=="+i+", got=="+b[i]);
                }
            }
            Console.WriteLine("We are done with the listening");
        }
        catch(Exception e) 
        {
            iCountErrors++ ;
            Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace);
            m_PortSetEvent.Set();
        }
        finally
        {
            if (listener != null)
            {
                listener.Stop();
            }
            if (ns != null)
            {
                ns.Close();
            }
            if(bs != null)
            {
                bs.Close();
            }
        } //finally

    }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:52,代码来源:co5603ctor_stream_i.cs

示例11: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BufferedStream bs2;
         MemoryStream memstr2;
         if(File.Exists("Co5602Test.tmp"))
             File.Delete("Co5602Test.tmp");
         strLoc = "Loc_98yv7";
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream((Stream)null);
             iCountErrors++;
             printerr( "Error_2yc83! Expected exception not thrown");
         } 
         catch (ArgumentNullException aexc) 
         {
             printinfo("Info_287c7! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_984yv! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_567g7";
         iCountTestcases++;
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         bs2.Write(new Byte[]{0,1,2}, 0, 3);
         iCountTestcases++;
         Byte[] b = new Byte[3];
         bs2.Position = 0;
         bs2.Read(b, 0, 3);
         for(int i = 0 ; i < b.Length ; i++) 
         {
             iCountTestcases++;
             if(b[i] != i) 
             {
                 iCountErrors++;
                 printerr( "Error_2958v! Expected=="+i+", got=="+b[i]);
             }
         }
         m_PortSetEvent.Reset();
         Thread tcpListenerThread = new Thread(new ThreadStart(Co5602ctor_stream.StartListeningTcp));
         tcpListenerThread.Start();
         Console.WriteLine("Listening");
         Thread.Sleep( 1000 );
         m_PortSetEvent.WaitOne();
         Teleport("127.0.0.1");
         Thread.Sleep( 1000 );
         if(File.Exists("Co5602Test.tmp"))
             File.Delete("Co5602Test.tmp");
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
         return true;
     }
     else
     {
         Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:74,代码来源:co5602ctor_stream.cs


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