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


C# BufferedStream.SetLength方法代码示例

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


在下文中一共展示了BufferedStream.SetLength方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:neris,项目名称:corefx,代码行数:11,代码来源:BufferedStream.InvalidParameters.cs

示例2: SetLengthWithClosedBaseStream

		public void SetLengthWithClosedBaseStream ()
		{
			string fn = Path.Combine (TempFolder, "temp");
			try {
				FileStream fs = new FileStream (fn, FileMode.Create);
				BufferedStream bs = new BufferedStream (fs);
				fs.Close ();
				
				bs.SetLength (1000);
			} finally {
				File.Delete (fn);
			}
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:13,代码来源:FileStreamTest.cs

示例3: Merge


//.........这里部分代码省略.........


                            //Read and write the pathfinding data
                            sourcebuffered.Seek(65536, SeekOrigin.Begin);
                            inputbuffered.Seek(65536, SeekOrigin.Begin);

                            sourcebuffered.Read(source, 0, 65536);
                            inputbuffered.Read(input, 0, 65536);

                            Compare(source, input, 0xfa, 65536);

                            sourcebuffered.Seek(65536, SeekOrigin.Begin);
                            sourcebuffered.Write(source, 0, 65536);


                            //Read and write the marker data
                            sourcebuffered.Seek(131072, SeekOrigin.Begin);
                            byte[] sourcemarkercountbytes = new byte[4];
                            sourcebuffered.Read(sourcemarkercountbytes, 0, 4);
                            int sourcemarkercount = BitConverter.ToInt32(sourcemarkercountbytes, 0);

                            inputbuffered.Seek(131072, SeekOrigin.Begin);
                            byte[] inputmarkercountbytes = new byte[4];
                            inputbuffered.Read(inputmarkercountbytes, 0, 4);
                            int inputmarkercount = BitConverter.ToInt32(inputmarkercountbytes, 0);

                            List<Marker> sourcemarkers = new List<Marker>();

                            for (int r = 0; r < sourcemarkercount; ++r)
                            {
                                byte[] data = new byte[12];
                                sourcebuffered.Read(data, 0, 12);

                                byte[] stringlength = new byte[2];
                                sourcebuffered.Read(stringlength, 0, 2);
                                int len = BitConverter.ToUInt16(stringlength, 0);

                                byte[] str = new byte[len];
                                sourcebuffered.Read(str, 0, len);
                                sourcebuffered.Seek(len, SeekOrigin.Current);

                                Marker marker = new Marker(data, stringlength, str);
                                sourcemarkers.Add(marker);
                            }

                            for (int r = 0; r < inputmarkercount; ++r)
                            {
                                byte[] data = new byte[12];
                                inputbuffered.Read(data, 0, 12);

                                byte[] stringlength = new byte[2];
                                inputbuffered.Read(stringlength, 0, 2);
                                int len = BitConverter.ToUInt16(stringlength, 0);

                                byte[] str = new byte[len];
                                inputbuffered.Read(str, 0, len);
                                inputbuffered.Seek(len, SeekOrigin.Current);

                                Marker marker = new Marker(data, stringlength, str);

                                //Make sure we arn't copying a marker that already exists
                                if (!sourcemarkers.Contains(marker))
                                {
                                    sourcemarkercount++;

                                    byte[] write = marker.GetBytes();
                                    sourcebuffered.SetLength(sourcebuffered.Length + write.Length);
                                    sourcebuffered.Seek(-write.Length, SeekOrigin.End);
                                    sourcebuffered.Write(write, 0, write.Length);
                                }
                            }

                            sourcebuffered.Seek(131072, SeekOrigin.Begin);
                            sourcemarkercountbytes = BitConverter.GetBytes(sourcemarkercount);
                            sourcebuffered.Write(sourcemarkercountbytes, 0, 4);
                        }
                        catch
                        {
                            return false;
                        }
                        finally
                        {
                            if (sourcebuffered != null)
                                sourcebuffered.Close();

                            if (inputbuffered != null)
                                inputbuffered.Close();

                            if (sourcefile != null)
                                sourcefile.Close();

                            if (inputfile != null)
                                inputfile.Close();
                        }
                    }
                }
            }

            return true;
        }
开发者ID:FaNtA91,项目名称:pokemonapi,代码行数:101,代码来源:MapMerger.cs

示例4: SetLength_Disposed

	public void SetLength_Disposed ()
	{
		BufferedStream stream = new BufferedStream (new MemoryStream ());
		stream.Close ();
		stream.SetLength (16);
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:6,代码来源:BufferedStreamTest.cs

示例5: PositionAfterSetLength

	public void PositionAfterSetLength () 
	{
		BufferedStream stream = new BufferedStream (new MemoryStream ());
		stream.SetLength (32);
		stream.Position = 32;
		stream.SetLength (16);
		Assert.AreEqual (16, stream.Position, "Position==16");
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:BufferedStreamTest.cs

示例6: SetLengthException3

	 public void SetLengthException3 ()
	 {
		BufferedStream stream = new BufferedStream (mem);
	 	mem = null;
		// Strangely, this does not throw an exception on .NET 1.1
		stream.SetLength (1);	 	
	 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:BufferedStreamTest.cs

示例7: SetLengthException2

	 public void SetLengthException2 ()
	 {
		BufferedStream stream = new BufferedStream (mem);
	 	mem.Close ();
		stream.SetLength (1);	 	
	 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:6,代码来源:BufferedStreamTest.cs

示例8: SetLengthException

	 public void SetLengthException ()
	 {
		BufferedStream stream = new BufferedStream (mem);
		stream.SetLength (-1);	 	
	 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:BufferedStreamTest.cs

示例9: SetLength

	public void SetLength ()
	{
		BufferedStream stream = new BufferedStream (mem);
		stream.Write (new byte [] {0,1,2,3,4,5}, 0, 6);
		
		Assert.AreEqual (6, stream.Length, "test#01");
		stream.SetLength (60);
		Assert.AreEqual (60, stream.Length, "test#02");
		
		stream.SetLength (2);
		Assert.AreEqual (2, stream.Length, "test#03");	
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:12,代码来源:BufferedStreamTest.cs

示例10: SetLengthWithClosedBaseStream

		public void SetLengthWithClosedBaseStream ()
		{
			string path = TempFolder + Path.DirectorySeparatorChar + "temp";
			StdioFileStream fs = new StdioFileStream (path, FileMode.Create);
			BufferedStream bs = new BufferedStream (fs);
			fs.Close ();

			bs.SetLength (1000);
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:9,代码来源:StdioFileStreamTest.cs

示例11: SetLengthWithClosedBaseStream

		public void SetLengthWithClosedBaseStream ()
		{
			StdioFileStream fs = new StdioFileStream ("temp", FileMode.Create);
			BufferedStream bs = new BufferedStream (fs);
			fs.Close ();

			bs.SetLength (1000);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:8,代码来源:StdioFileStreamTest.cs

示例12: SetLength

	public void SetLength ()
	{
		BufferedStream stream = new BufferedStream (mem);
		stream.Write (new byte [] {0,1,2,3,4,5}, 0, 6);
		
		AssertEquals ("test#01", 6, stream.Length);
		stream.SetLength (60);
		AssertEquals ("test#02", 60, stream.Length);
		
		stream.SetLength (2);
		AssertEquals ("test#03", 2, stream.Length);	
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:12,代码来源:BufferedStreamTest.cs


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