CSharpTest.Net
SegmentedMemoryStream Constructor(Int32)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > SegmentedMemoryStream Class > SegmentedMemoryStream Constructor : SegmentedMemoryStream Constructor(Int32)

segmentSize

Glossary Item Box

Create a memory stream that uses the specified size of segments

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal segmentSize As Integer _
)
C# 
public SegmentedMemoryStream( 
   int segmentSize
)

Parameters

segmentSize

Example

Library/Library.Test/TestSegmentedStream.cs

C#Copy Code
using (SegmentedMemoryStream ms = new SegmentedMemoryStream(5))
{
    Write(ms, "12345");
    Write(ms, "abcd");
    Write(ms, "ABCDEF");
    Write(ms, "12345");
    Write(ms, "");

    ms.Flush();
    Assert.AreEqual(20L, ms.Length);
    Assert.AreEqual(20L, ms.Position);

    ms.Position = 0;
    Assert.AreEqual("12345abcdABCDEF12345", Read(ms, (int)ms.Length));

    ms.Position = 5;
    Assert.AreEqual("a", Read(ms, 1));
    Assert.AreEqual("bcd", Read(ms, 3));
    Assert.AreEqual("ABCDEF", Read(ms, 6));
    Assert.AreEqual("12345", Read(ms, 5));
    Assert.AreEqual(0, ms.Read(new byte[10], 0, 10));
}
VB.NETCopy Code
Using ms As New SegmentedMemoryStream(5)
    Write(ms, "12345")
    Write(ms, "abcd")
    Write(ms, "ABCDEF")
    Write(ms, "12345")
    Write(ms, "")

    ms.Flush()
    Assert.AreEqual(20L, ms.Length)
    Assert.AreEqual(20L, ms.Position)

    ms.Position = 0
    Assert.AreEqual("12345abcdABCDEF12345", Read(ms, DirectCast(ms.Length, Integer)))

    ms.Position = 5
    Assert.AreEqual("a", Read(ms, 1))
    Assert.AreEqual("bcd", Read(ms, 3))
    Assert.AreEqual("ABCDEF", Read(ms, 6))
    Assert.AreEqual("12345", Read(ms, 5))
    Assert.AreEqual(0, ms.Read(New Byte(10) {}, 0, 10))
End Using

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys