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


C# BufferedStream.ReadByte方法代码示例

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


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

示例1: ShouldNotFlushUnderlyingStreamIfReadOnly

        public async Task ShouldNotFlushUnderlyingStreamIfReadOnly(bool underlyingCanSeek)
        {
            var underlying = new DelegateStream(
                canReadFunc: () => true,
                canWriteFunc: () => false,
                canSeekFunc: () => underlyingCanSeek,
                readFunc: (_, __, ___) => 123,
                writeFunc: (_, __, ___) =>
                {
                    throw new NotSupportedException();
                },
                seekFunc: (_, __) => 123L
            );

            var wrapper = new CallTrackingStream(underlying);

            var buffered = new BufferedStream(wrapper);
            buffered.ReadByte();

            buffered.Flush();
            Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.Flush)));

            await buffered.FlushAsync();
            Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:25,代码来源:BufferedStream.FlushTests.cs

示例2: ConcurrentOperationsAreSerialized

        public async Task ConcurrentOperationsAreSerialized()
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)i).ToArray();
            var mcaos = new ManuallyReleaseAsyncOperationsStream();
            var stream = new BufferedStream(mcaos, 1);

            var tasks = new Task[4];
            for (int i = 0; i < 4; i++)
            {
                tasks[i] = stream.WriteAsync(data, 250 * i, 250);
            }
            Assert.False(tasks.All(t => t.IsCompleted));

            mcaos.Release();
            await Task.WhenAll(tasks);

            stream.Position = 0;
            for (int i = 0; i < tasks.Length; i++)
            {
                Assert.Equal(i, stream.ReadByte());
            }
        }
开发者ID:dotnet,项目名称:corefx,代码行数:22,代码来源:BufferedStreamTests.cs

示例3: CopyToAsyncTest_ReadBeforeCopy_CopiesAllData

        public async Task CopyToAsyncTest_ReadBeforeCopy_CopiesAllData(bool wrappedStreamCanSeek)
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();

            var wrapped = new ManuallyReleaseAsyncOperationsStream();
            wrapped.Release();
            wrapped.Write(data, 0, data.Length);
            wrapped.Position = 0;
            wrapped.SetCanSeek(wrappedStreamCanSeek);
            var src = new BufferedStream(wrapped, 100);

            src.ReadByte();

            var dst = new MemoryStream();
            await src.CopyToAsync(dst);

            var expected = new byte[data.Length - 1];
            Array.Copy(data, 1, expected, 0, expected.Length);
            Assert.Equal(expected, dst.ToArray());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:20,代码来源:BufferedStreamTests.cs

示例4: 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
		{
			FileStream fs2;
			MemoryStream ms2;
			BufferedStream bs2;
			String filName = s_strTFAbbrev + "TestFile.tmp";
			Int32 ii = 0;
			Byte[] bytArr;
			Int32 i32;
			bytArr = new Byte[] {
				Byte.MinValue
				,Byte.MaxValue
				,100
				,Byte.MaxValue-100
			};
			if(File.Exists(filName))
				File.Delete(filName);
			strLoc = "Loc_8yfv7";
			fs2 = new FileStream(filName, FileMode.Create);
			bs2 = new BufferedStream(fs2);
			for(ii = 0 ; ii < bytArr.Length ; ii++)
				bs2.WriteByte(bytArr[ii]);		   
			bs2.Flush();
			bs2.Close();
			strLoc = "Loc_987hg";
			fs2 = new FileStream(filName, FileMode.Open);
			bs2 = new BufferedStream(fs2);
			for(ii = 0 ; ii < bytArr.Length ;ii++) {
				iCountTestcases++;
				if((i32 = bs2.ReadByte()) != bytArr[ii]) {
					iCountErrors++;
					printerr( "Error_298hg_"+ii+"! Expected=="+bytArr[ii]+" , got=="+i32);
				}
			}
			i32 = bs2.ReadByte();
			if(i32 != -1) {
				iCountErrors++;
				printerr( "Error_2389! -1 return expected, i32=="+i32);
			} 
			fs2.Close();
			strLoc = "Loc_398yc";
			ms2 = new MemoryStream();
			bs2 = new BufferedStream(ms2);
			for(ii = 0 ; ii < bytArr.Length ; ii++)
				bs2.WriteByte(bytArr[ii]);
			bs2.Flush();
			bs2.Position = 0;
			bs2.Flush();
			for(ii = 0 ; ii < bytArr.Length ; ii++) {
				iCountTestcases++;
				if((i32 = bs2.ReadByte()) != bytArr[ii]) {
					iCountErrors++;
					printerr( "Error_38yv8_"+ii+"! Expected=="+bytArr[ii]+", got=="+i32);
				}
			}
			i32 = bs2.ReadByte();
			if(i32 != -1) {
				iCountErrors++;
				printerr( "Error_238v8! -1 return expected, i32=="+i32);
			}
			bs2.Position = 0;
			for(ii = 0 ; ii < bytArr.Length; ii++)
				bs2.WriteByte(bytArr[ii]);
			if(File.Exists(filName))
				File.Delete(filName);
		} 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,代码行数:87,代码来源:co5744readbyte.cs

示例5: 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 );   
            int iByte ;
            for(int i = 0 ; i < 100 ; i++) 
            {
                iByte = bs.ReadByte ();
                if(iByte != i) 
                {
                    iCountErrors++;
                    Console.WriteLine( "Error_4324! Expected=="+i+", got=="+iByte);
                }
            }
            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:ArildF,项目名称:masters,代码行数:53,代码来源:co5743writebyte.cs


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