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


C# StdioFileStream.ReadByte方法代码示例

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


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

示例1: ReadBytePastEndOfStream

		public void ReadBytePastEndOfStream () 
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "temp";
			DeleteFile (path);
			using (StdioFileStream stream = new StdioFileStream (path, FileMode.OpenOrCreate, FileAccess.Read)) {
				stream.Seek (0, SeekOrigin.End);
				Assert.AreEqual (-1, stream.ReadByte (), "ReadByte");
				stream.Close ();
			}
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:10,代码来源:StdioFileStreamTest.cs

示例2: TestFlushNotOwningHandle

		public void TestFlushNotOwningHandle ()
		{
			string path = Path.Combine (TempFolder, "TestFlushNotOwningHandle");
			DeleteFile (path);

			StdioFileStream s = new StdioFileStream (path, FileMode.Create);
			using (StdioFileStream s2 = new StdioFileStream (s.Handle, FileAccess.Write, false)) {
				byte[] buf = new byte [2];
				buf [0] = (int)'1';
				s2.Write (buf, 0, 1);
			}

			s.Position = 0;
			Assert.AreEqual (s.ReadByte (), (int)'1');
			s.Close ();
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:16,代码来源:StdioFileStreamTest.cs

示例3: TestReadByteVerifyAccessMode

		public void TestReadByteVerifyAccessMode ()
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "temp";
			DeleteFile (path);

			StdioFileStream stream = null;

			try {
				stream = new StdioFileStream (path, FileMode.OpenOrCreate, FileAccess.Write);
				int readByte = stream.ReadByte ();
			} finally {
				if (stream != null)
					stream.Close();
				DeleteFile (path);
			}
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:16,代码来源:StdioFileStreamTest.cs

示例4: TestClose

		public void TestClose ()
		{
#if FALSE
			string path = TempFolder + Path.DirectorySeparatorChar + "TestClose";
			DeleteFile (path);

			StdioFileStream stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);

			stream.Write (new byte [] {1, 2, 3, 4}, 0, 4);
			stream.ReadByte ();                	
			stream.Close ();

			try {                	
				stream.ReadByte ();
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#01");
			}

			try {                	
				stream.WriteByte (64);
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#02");
			}

			try {                	
				stream.Flush ();
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#03");
			}

			try { 
				long l = stream.Length;
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#04");
			}

			try { 
				long l = stream.Position;
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#05");
			}

			try { 
				FilePosition fp = stream.FilePosition;
				fp.Dispose ();
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (ObjectDisposedException), e.GetType (), "test#05");
			}

			Assert.AreEqual (false, stream.CanRead, "test#06");
			Assert.AreEqual (false, stream.CanSeek, "test#07");
			Assert.AreEqual (false, stream.CanWrite, "test#08");                	

			DeleteFile (path);                	
#endif
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:62,代码来源:StdioFileStreamTest.cs

示例5: TestSeek

		public void TestSeek ()
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "TestSeek";
			DeleteFile (path);

			StdioFileStream stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);
			stream.Write (new byte[] {1, 2, 3, 4, 5, 6, 7, 8 , 9, 10}, 0, 10);

			stream.Seek (5, SeekOrigin.End);
			Assert.AreEqual (-1, stream.ReadByte (), "test#01");

			stream.Seek (-5, SeekOrigin.End);
			Assert.AreEqual (6, stream.ReadByte (), "test#02");

			try {
				stream.Seek (-11, SeekOrigin.End);
				Assert.Fail ();
			} catch (Exception e) {
				Assert.AreEqual (typeof (IOException), e.GetType (), "test#03");
			}

			stream.Seek (19, SeekOrigin.Begin);
			Assert.AreEqual (-1, stream.ReadByte (), "test#04");

			stream.Seek (1, SeekOrigin.Begin);
			Assert.AreEqual (2, stream.ReadByte (), "test#05");

			stream.Seek (3, SeekOrigin.Current);
			Assert.AreEqual (6, stream.ReadByte (), "test#06");

			stream.Seek (-2, SeekOrigin.Current);
			Assert.AreEqual (5, stream.ReadByte (), "test#07");

			stream.Flush ();

			// Test that seeks work correctly when seeking inside the buffer
			stream.Seek (0, SeekOrigin.Begin);
			stream.WriteByte (0);
			stream.WriteByte (1);
			stream.Seek (0, SeekOrigin.Begin);
			byte[] buf = new byte [1];
			buf [0] = 2;
			stream.Write (buf, 0, 1);
			stream.Write (buf, 0, 1);
			stream.Flush ();
			stream.Seek (0, SeekOrigin.Begin);
			Assert.AreEqual (2, stream.ReadByte (), "test#08");
			Assert.AreEqual (2, stream.ReadByte (), "test#09");

			stream.Close ();

			DeleteFile (path);
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:53,代码来源:StdioFileStreamTest.cs

示例6: Seek

		public void Seek ()
		{
			string path = TempFolder + DSC + "FST.Seek.Test";
			DeleteFile (path);			

			StdioFileStream stream = new StdioFileStream (path, FileMode.CreateNew, FileAccess.ReadWrite);
			StdioFileStream stream2 = new StdioFileStream (path, FileMode.Open, FileAccess.ReadWrite);

			stream.Write (new byte [] {1, 2, 3, 4, 5, 6, 7, 8, 10}, 0, 9);
			Assert.AreEqual (5, stream2.Seek (5, SeekOrigin.Begin), "test#01");
			Assert.AreEqual (-1, stream2.ReadByte (), "test#02");

			Assert.AreEqual (2, stream2.Seek (-3, SeekOrigin.Current), "test#03");
			Assert.AreEqual (-1, stream2.ReadByte (), "test#04");

			Assert.AreEqual (12, stream.Seek (3, SeekOrigin.Current), "test#05");
			Assert.AreEqual (-1, stream.ReadByte (), "test#06");

			Assert.AreEqual (5, stream.Seek (-7, SeekOrigin.Current), "test#07");
			Assert.AreEqual (6, stream.ReadByte (), "test#08");

			Assert.AreEqual (5, stream2.Seek (5, SeekOrigin.Begin), "test#09");
			Assert.AreEqual (6, stream2.ReadByte (), "test#10");

			stream.Close ();
			stream2.Close ();

			DeleteFile (path);
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:29,代码来源:StdioFileStreamTest.cs


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