CSharpTest.Net
ClampedStream Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace : ClampedStream Class

Glossary Item Box

Provides a stream that clamps the usage of the input stream to a specific range, length or offset

Syntax

Visual Basic (Declaration) 
Public Class ClampedStream 
   Inherits System.IO.Stream
C# 
public class ClampedStream : System.IO.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

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.IO.Stream
         CSharpTest.Net.IO.ClampedStream

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys