當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。