CSharpTest.Net
ClampedStream Constructor(Stream,Int64,Int64)
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)

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

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 _
)
C# 
public ClampedStream( 
   Stream rawStream,
   long start,
   long length
)

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

Example

Library/Library.Test/TestClampedStream.cs

C#Copy Code
using (MemoryStream ms = new MemoryStream(SequencedBytes(20)))
using (Stream s = new ClampedStream(ms, 10, 5))
{
    byte[] test = new byte[200];
    Assert.AreEqual(5, s.Read(test, 0, 200));
    Array.Resize(ref test, 5);
    Assert.AreEqual(new byte[] { 10, 11, 12, 13, 14 }, test);
    s.Position = 0;
    s.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5);
    s.Position = 0;
    Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5 }, IOStream.ReadAllBytes(s));
}
VB.NETCopy Code
Using ms As New MemoryStream(SequencedBytes(20))
    Using s As Stream = New ClampedStream(ms, 10, 5)
        Dim test As Byte() = New Byte(200) {}
        Assert.AreEqual(5, s.Read(test, 0, 200))
        Array.Resize(test, 5)
        Assert.AreEqual(New Byte() {10, 11, 12, 13, 14}, test)
        s.Position = 0
        s.Write(New Byte() {1, 2, 3, 4, 5}, 0, 5)
        s.Position = 0
        Assert.AreEqual(New Byte() {1, 2, 3, 4, 5}, IOStream.ReadAllBytes(s))
    End Using
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