本文整理汇总了C#中BufferedStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# BufferedStream.WriteByte方法的具体用法?C# BufferedStream.WriteByte怎么用?C# BufferedStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BufferedStream
的用法示例。
在下文中一共展示了BufferedStream.WriteByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldAlwaysFlushUnderlyingStreamIfWritable
public async Task ShouldAlwaysFlushUnderlyingStreamIfWritable(bool underlyingCanRead, bool underlyingCanSeek)
{
var underlying = new DelegateStream(
canReadFunc: () => underlyingCanRead,
canWriteFunc: () => true,
canSeekFunc: () => underlyingCanSeek,
readFunc: (_, __, ___) => 123,
writeFunc: (_, __, ___) => { },
seekFunc: (_, __) => 123L
);
var wrapper = new CallTrackingStream(underlying);
var buffered = new BufferedStream(wrapper);
buffered.Flush();
Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
buffered.WriteByte(0);
buffered.Flush();
Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.Flush)));
await buffered.FlushAsync();
Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
}
示例2: UnderlyingStreamThrowsExceptions
public void UnderlyingStreamThrowsExceptions()
{
var stream = new BufferedStream(new ThrowsExceptionFromAsyncOperationsStream());
Assert.Equal(TaskStatus.Faulted, stream.ReadAsync(new byte[1], 0, 1).Status);
Assert.Equal(TaskStatus.Faulted, stream.WriteAsync(new byte[10000], 0, 10000).Status);
stream.WriteByte(1);
Assert.Equal(TaskStatus.Faulted, stream.FlushAsync().Status);
}
示例3: CopyToAsyncTest_RequiresAsyncFlushingOfWrites
public async Task CopyToAsyncTest_RequiresAsyncFlushingOfWrites()
{
byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();
var manualReleaseStream = new ManuallyReleaseAsyncOperationsStream();
var src = new BufferedStream(manualReleaseStream);
src.Write(data, 0, data.Length);
src.Position = 0;
var dst = new MemoryStream();
data[0] = 42;
src.WriteByte(42);
dst.WriteByte(42);
Task copyTask = src.CopyToAsync(dst);
manualReleaseStream.Release();
await copyTask;
Assert.Equal(data, dst.ToArray());
}
示例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;
}
}
示例5: Teleport
public static void Teleport(string address)
{
TcpClient tcpClient = new TcpClient();
IPEndPoint epSend = null;
IPAddress sendAddress = IPAddress.Parse(address);
epSend = new IPEndPoint(sendAddress, iPortNumber);
tcpClient.Connect(epSend);
Stream stream = tcpClient.GetStream();
BufferedStream bs = new BufferedStream( stream);
for(int iLoop = 0 ; iLoop < 100 ; iLoop++)
bs.WriteByte( Convert.ToByte( iLoop ));
bs.Flush();
}