CSharpTest.Net
Write Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > TransactedCompoundFile Class : Write Method

handle
bytes
offset
length

Glossary Item Box

Writes the bytes provided to the handle that was previously obtained by a call to Create(). The length must not be more than ((16*BlockSize)-32) bytes in length. The exact header size (32 bytes) may change without notice in a future release.

Syntax

Visual Basic (Declaration) 
Public Sub Write( _
   ByVal handle As UInteger, _
   ByVal bytes() As Byte, _
   ByVal offset As Integer, _
   ByVal length As Integer _
) 
C# 
public void Write( 
   uint handle,
   byte[] bytes,
   int offset,
   int length
)

Parameters

handle
bytes
offset
length

Exceptions

ExceptionDescription
System.ArgumentOutOfRangeExceptionThe exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method.

Example

Library/Library.Test/TestTransactedCompoundFile.cs

C#Copy Code
Dictionary<uint, byte[]> store = new Dictionary<uint, byte[]>();
using (TempFile temp = new TempFile())
{
    uint id;
    byte[] bytes;
    using (TransactedCompoundFile test = new TransactedCompoundFile(new TransactedCompoundFile.Options(temp.TempPath) { BlockSize = 512, CreateNew = true }))
    {
        for (int i = 0; i < 10000; i++)
        {
            switch(i < 1000 ? 0 : rand.Next(3))
            {
                case 0:
                    {
                        id = test.Create();
                        bytes = RandomBytes(rand.Next(1000));
                        store.Add(id, bytes);
                        test.Write(id, bytes, 0, bytes.Length);
                        break;
                    }
                case 1:
                    {
                        id = RandomPick(store.Keys);
                        bytes = store[id];
                        CompareBytes(bytes, 0, bytes.Length, IOStream.ReadAllBytes(test.Read(id)));
                        break;
                    }
                case 2:
                    {
                        id = RandomPick(store.Keys);
                        Assert.IsTrue(store.Remove(id));
                        test.Delete(id);
                        break;
                    }
            }
        }

        foreach (var kv in store)
        {
            CompareBytes(kv.Value, 0, kv.Value.Length, IOStream.ReadAllBytes(test.Read(kv.Key)));
        }
    }
}
VB.NETCopy Code
Dim store As New Dictionary(Of UInteger, Byte())()
Using temp As New TempFile()
    Dim id As UInteger
    Dim bytes As Byte()
    Using test As New TransactedCompoundFile(New TransactedCompoundFile.Options(temp.TempPath) With { _
        Key .BlockSize = 512, _
        Key .CreateNew = True _
    })
        Dim i As Integer = 0
        While i < 10000
            Select Case If(i < 1000, 0, rand.[Next](3))
                Case 0
                    If True Then
                        id = test.Create()
                        bytes = RandomBytes(rand.[Next](1000))
                        store.Add(id, bytes)
                        test.Write(id, bytes, 0, bytes.Length)
                        Exit Select
                    End If
                Case 1
                    If True Then
                        id = RandomPick(store.Keys)
                        bytes = store(id)
                        CompareBytes(bytes, 0, bytes.Length, IOStream.ReadAllBytes(test.Read(id)))
                        Exit Select
                    End If
                Case 2
                    If True Then
                        id = RandomPick(store.Keys)
                        Assert.IsTrue(store.Remove(id))
                        test.Delete(id)
                        Exit Select
                    End If
            End Select
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While

        For Each kv As var In store
            CompareBytes(kv.Value, 0, kv.Value.Length, IOStream.ReadAllBytes(test.Read(kv.Key)))
        Next
    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