CSharpTest.Net
ClampedStream Constructor(Stream,Int64,Int64,Boolean)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > ClampedStream Class > ClampedStream Constructor : ClampedStream Constructor(Stream,Int64,Int64,Boolean)

rawStream
The stream to use for read/write
start
The position in the stream that should start the range of allowed bytes
length
The maximum length that can be read from the stream
disposeOfStream
True to dispose of the rawStream when this stream is disposed

Glossary Item Box

Creates a stream that limits the users ability to modify data to the specified range

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal rawStream As Stream, _
   ByVal start As Long, _
   ByVal length As Long, _
   ByVal disposeOfStream As Boolean _
)
C# 
public ClampedStream( 
   Stream rawStream,
   long start,
   long length,
   bool disposeOfStream
)

Parameters

rawStream
The stream to use for read/write
start
The position in the stream that should start the range of allowed bytes
length
The maximum length that can be read from the stream
disposeOfStream
True to dispose of the rawStream when this stream is disposed

Example

Library/Library.Test/TestClampedStream.cs

C#Copy Code
MemoryStream ms = new MemoryStream();
BufferedStream bs = new BufferedStream(ms, 1024);

using (Stream s = new ClampedStream(bs, 0, long.MaxValue, false))
{
    s.WriteByte(1);
    Assert.AreEqual(0, ms.Position);
    s.Flush();
    Assert.AreEqual(1, ms.Position);
    ms.Position = 0;
    Assert.AreEqual(1, ms.ReadByte());
}
VB.NETCopy Code
Dim ms As New MemoryStream()
Dim bs As New BufferedStream(ms, 1024)

Using s As Stream = New ClampedStream(bs, 0, Long.MaxValue, False)
    s.WriteByte(1)
    Assert.AreEqual(0, ms.Position)
    s.Flush()
    Assert.AreEqual(1, ms.Position)
    ms.Position = 0
    Assert.AreEqual(1, ms.ReadByte())
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