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


C# BufferedStream.SetLength方法代码示例

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


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

示例1: SetLength_NegativeValue

 public static void SetLength_NegativeValue()
 {
     using (MemoryStream underlying = new MemoryStream())
     using (BufferedStream stream = new BufferedStream(underlying))
     {
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.SetLength(-1));
         stream.SetLength(1);
         Assert.Equal(1, underlying.Length);
         Assert.Equal(1, stream.Length);
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:11,代码来源:BufferedStream.InvalidParameters.cs

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

示例3: 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;
         FileStream fs2;
         StreamWriter sw2;
         if(File.Exists("Co5609Test.tmp"))
             File.Delete("Co5609Test.tmp");
         strLoc = "Loc_9289x";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         iCountTestcases++;
         try 
         {
             bs2.SetLength(-2);
             iCountErrors++;
             printerr( "Error_190x9! Expected exception not thrown");
         } 
         catch (ArgumentOutOfRangeException aexc) 
         {
             printinfo("Info_9199x! Caught expected exception, exc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_t589v! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_27yxc";
         fs2 = new FileStream("Co5609Test.tmp", FileMode.Create);
         bs2 = new BufferedStream(fs2);
         bs2.SetLength(50);
         bs2.Position = 50;
         sw2 = new StreamWriter(bs2);
         Console.WriteLine(bs2.Position);
         for(char c = 'a' ; c < 'f' ; c++) 
             bs2.Write(new Byte[]{(Byte)c}, 0, 1 );
         bs2.Flush();
         fs2.Flush();
         Console.WriteLine(bs2.Position);
         iCountTestcases++;
         if(fs2.Length != 55) 
         {
             iCountErrors++;
             printerr( "Error_389xd! Incorrect stream length=="+fs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 55) 
         {
             iCountErrors++;
             printerr( "Error_3y8t3! Incorrect position=="+bs2.Position);
         }
         bs2.SetLength(30);
         iCountTestcases++;
         if(bs2.Length != 30) 
         {
             iCountErrors++;
             printerr( "Error_28xye! Incorrect length=="+bs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 30) 
         {
             iCountErrors++;
             printerr( "Error_3989a! Incorrect position=="+bs2.Position);
         }
         bs2.SetLength(100);
         bs2.Position = 100;
         iCountTestcases++;
         if(bs2.Length != 100) 
         {
             iCountErrors++;
             printerr( "Error_2090x! Incorrect length=="+bs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 100) 
         {
             iCountErrors++;
             printerr( "Error_1987t! Incorrect position=="+bs2.Position);
         }
         bs2.Flush();
         bs2.SetLength(50);
         iCountTestcases++;
         if(bs2.Length != 50) 
         {
             iCountErrors++;
             printerr( "Error_10x88! Incorrect length=="+bs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 50) 
         {
             iCountErrors++;
             printerr( "Error_738gb! Incorrect position=="+bs2.Position);
         }
         bs2.Close();
         strLoc = "Loc_99189";
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5609setlength.cs

示例4: 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);
     try
     {
         bs.SetLength( 100 );
         iCountErrors++;
         Console.WriteLine( "Error_8888! Expecte exception not occured ");
     } 
     catch( NotSupportedException ) 
     {
     } 
     catch( Exception )
     {
         iCountErrors++;
         Console.WriteLine( "Error_434234! Able to set the Network stream length ");
     } 
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:24,代码来源:co5609setlength.cs

示例5: runTest


//.........这里部分代码省略.........
         }
         iCountTestcases++;
         if(bs2.Position != 7) 
         {
             iCountErrors++;
             printerr( "Error_10978! Incorrect position=="+bs2.Position);
         }
         pos = bs2.Seek(-5, SeekOrigin.End);
         iCountTestcases++;
         if(pos != 3) 
         {
             iCountErrors++;
             printerr( "Error_2908y! Incorrect return=="+pos);
         }
         iCountTestcases++;
         if(bs2.Position != 3) 
         {
             iCountErrors++;
             printerr( "Error_984yb! Incorrect position=="+bs2.Position);
         }
         pos = bs2.Seek(2, SeekOrigin.Current);
         iCountTestcases++;
         if(pos != 5) 
         { 
             iCountErrors++;
             printerr( "Error_09utg! Incorrect return=="+pos);
         }
         iCountTestcases++;
         if(bs2.Position != 5) 
         {
             iCountErrors++;
             printerr( "Error_98g87! Incorrect position=="+bs2.Position);
         }
         bs2.SetLength(105);
         pos = bs2.Seek(100, SeekOrigin.Current);
         if(pos != 105) 
         {
             iCountErrors++;
             printerr( "Error_b858j! Incorrect return=="+pos);
         }
         iCountTestcases++;
         if(bs2.Position != 105) 
         {
             iCountErrors++;
             printerr( "Error_48yvb! Incorrect position=="+bs2.Position);
         }
         pos = bs2.Seek(0, SeekOrigin.Current);
         if(pos != 105) 
         {
             iCountErrors++;
             printerr( "Error_g987y! Incorrect return=="+pos);
         }
         iCountTestcases++;
         if(bs2.Position != 105) 
         {
             iCountErrors++;
             printerr( "ERror_g587h! Incorrec position=="+bs2.Position);
         }
         bs2.Close();
         strLoc = "Loc_897hg";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         bs2.Close();
         iCountTestcases++;
         try 
         {
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co5614seek_i64_so.cs


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