public virtual void Test() { PagingMemoryStorage storage = new _PagingMemoryStorage_13(); IBin testBin = storage.Open(new BinConfiguration(string.Empty, true, 0, false)); Assert.AreEqual(Data.Length, testBin.Length()); int actualLength = (int)testBin.Length(); byte[] read = new byte[actualLength]; testBin.Read(0, read, actualLength); ArrayAssert.AreEqual(Data, read); }
public virtual long Length() { lock (this) { return(_bin.Length()); } }
private long BackupLength() { IBin backupBin = BackupStorage().Open(new BinConfiguration(TempFile(), true, 0, true )); long backupLength = backupBin.Length(); backupBin.Sync(); backupBin.Close(); return(backupLength); }
public virtual void TestInitialLength() { Storage().Open(new BinConfiguration(TempFile(), false, 1000, false)).Close(); IBin bin = Storage().Open(new BinConfiguration(TempFile(), false, 0, false)); try { Assert.AreEqual(1000, bin.Length()); } finally { bin.Close(); } }
/// <exception cref="System.Exception"></exception> private void AssertReadWriteAheadFileEnd(IBin adapter, string str) { byte[] data = Sharpen.Runtime.GetBytesForString(str); byte[] read = new byte[2048]; int readBytes = adapter.Read(10, data, data.Length); Assert.AreEqual(-1, readBytes); Assert.AreEqual(0, adapter.Length()); readBytes = adapter.Read(0, data, data.Length); Assert.AreEqual(-1, readBytes); Assert.AreEqual(0, adapter.Length()); adapter.Write(10, data, data.Length); Assert.AreEqual(10 + data.Length, adapter.Length()); readBytes = adapter.Read(0, read, read.Length); Assert.AreEqual(10 + data.Length, readBytes); readBytes = adapter.Read(20 + data.Length, read, read.Length); Assert.AreEqual(-1, readBytes); readBytes = adapter.Read(1024 + data.Length, read, read.Length); Assert.AreEqual(-1, readBytes); adapter.Write(1200, data, data.Length); readBytes = adapter.Read(0, read, read.Length); Assert.AreEqual(1200 + data.Length, readBytes); }
/// <seealso cref="IBin.Length()"></seealso> public virtual long Length() { return(_bin.Length()); }
/// <exception cref="System.IO.IOException"></exception> private static void CopyBin(IStorage sourceStorage, IStorage targetStorage, string sourcePath, string targetPath) { IBin origBin = sourceStorage.Open(new BinConfiguration(sourcePath, true, 0, true) ); try { IBin backupBin = targetStorage.Open(new BinConfiguration(targetPath, true, origBin .Length(), false)); try { byte[] buffer = new byte[4096]; int bytesRead = -1; int pos = 0; while ((bytesRead = origBin.Read(pos, buffer, buffer.Length)) >= 0) { backupBin.Write(pos, buffer, bytesRead); pos += bytesRead; } } finally { SyncAndClose(backupBin); } } finally { SyncAndClose(origBin); } }
/// <exception cref="System.Exception"></exception> private void AssertReadWriteAheadFileEnd(IBin adapter, string str) { var data = Runtime.GetBytesForString(str); var read = new byte[2048]; var readBytes = adapter.Read(10, data, data.Length); Assert.AreEqual(-1, readBytes); Assert.AreEqual(0, adapter.Length()); readBytes = adapter.Read(0, data, data.Length); Assert.AreEqual(-1, readBytes); Assert.AreEqual(0, adapter.Length()); adapter.Write(10, data, data.Length); Assert.AreEqual(10 + data.Length, adapter.Length()); readBytes = adapter.Read(0, read, read.Length); Assert.AreEqual(10 + data.Length, readBytes); readBytes = adapter.Read(20 + data.Length, read, read.Length); Assert.AreEqual(-1, readBytes); readBytes = adapter.Read(1024 + data.Length, read, read.Length); Assert.AreEqual(-1, readBytes); adapter.Write(1200, data, data.Length); readBytes = adapter.Read(0, read, read.Length); Assert.AreEqual(1200 + data.Length, readBytes); }