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

Glossary Item Box

Immediatly truncates the file to zero-length and re-initializes an empty file

Syntax

Visual Basic (Declaration) 
Public Sub Clear() 
C# 
public void Clear()

Example

Library/Library.Test/TestTransactedCompoundFile.cs

C#Copy Code
using (TempFile temp = new TempFile())
{
    byte[] sample = new byte[1024];
    new Random().NextBytes(sample);
    List<uint> handles = new List<uint>();
    using (TransactedCompoundFile file = new TransactedCompoundFile(temp.TempPath))
    {
        for (int i = 0; i < 100; i++)
        {
            var hid = file.Create();
            handles.Add(hid);
            file.Write(hid, sample, i, sample.Length - i);
            CompareBytes(sample, i, sample.Length - i, IOStream.ReadAllBytes(file.Read(hid)));
            file.Commit();
        }
        file.Clear();
        for (int i = 0; i < 100; i++)
        {
            try
            {
                IOStream.ReadAllBytes(file.Read(handles[i]));
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException) { }
        }
    }
}
VB.NETCopy Code
Using temp As New TempFile()
    Dim sample As Byte() = New Byte(1024) {}
    New Random().NextBytes(sample)
    Dim [handles] As New List(Of UInteger)()
    Using file As New TransactedCompoundFile(temp.TempPath)
        Dim i As Integer = 0
        While i < 100
            Dim hid As var = file.Create()
            [handles].Add(hid)
            file.Write(hid, sample, i, sample.Length - i)
            CompareBytes(sample, i, sample.Length - i, IOStream.ReadAllBytes(file.Read(hid)))
            file.Commit()
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
        file.Clear()
        Dim i As Integer = 0
        While i < 100
            Try
                IOStream.ReadAllBytes(file.Read([handles](i)))
                Assert.Fail()
            Catch generatedExceptionName As ArgumentOutOfRangeException
            End Try
            System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
        End While
    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