本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
示例4: SetLength_Disposed
public void SetLength_Disposed ()
{
BufferedStream stream = new BufferedStream (new MemoryStream ());
stream.Close ();
stream.SetLength (16);
}
示例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");
}
示例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);
}
示例7: SetLengthException2
public void SetLengthException2 ()
{
BufferedStream stream = new BufferedStream (mem);
mem.Close ();
stream.SetLength (1);
}
示例8: SetLengthException
public void SetLengthException ()
{
BufferedStream stream = new BufferedStream (mem);
stream.SetLength (-1);
}
示例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");
}
示例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);
}
示例11: SetLengthWithClosedBaseStream
public void SetLengthWithClosedBaseStream ()
{
StdioFileStream fs = new StdioFileStream ("temp", FileMode.Create);
BufferedStream bs = new BufferedStream (fs);
fs.Close ();
bs.SetLength (1000);
}
示例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);
}