private void SetByte(long index, byte value) { byte[] buffer = new byte[] { value }; _bitmap.Position = index; _bitmap.Write(buffer, 0, 1); _bitmap.Flush(); }
public void FailWrite() { MemoryStream ms = CreateSequencedMemStream(100, false); BlockCacheSettings settings = new BlockCacheSettings() { BlockSize = 10, OptimumReadSize = 20, ReadCacheSize = 100, LargeReadSize = 30 }; BlockCacheStream cacheStream = new BlockCacheStream(SparseStream.FromStream(ms, Ownership.Dispose), Ownership.Dispose, settings); byte[] buffer = new byte[25]; cacheStream.Position = 0; cacheStream.Read(buffer, 0, buffer.Length); AssertSequenced(buffer, 0); int freeBefore = cacheStream.Statistics.FreeReadBlocks; cacheStream.Position = 11; try { cacheStream.Write(new byte[10], 0, 10); } catch (NotSupportedException) { Assert.Equal(freeBefore + 2, cacheStream.Statistics.FreeReadBlocks); } }
public void Write() { MemoryStream ms = CreateSequencedMemStream(100, true); BlockCacheSettings settings = new BlockCacheSettings() { BlockSize = 10, OptimumReadSize = 20, ReadCacheSize = 100, LargeReadSize = 30 }; BlockCacheStream cacheStream = new BlockCacheStream(SparseStream.FromStream(ms, Ownership.Dispose), Ownership.Dispose, settings); byte[] buffer = new byte[20]; cacheStream.Position = 10; cacheStream.Read(buffer, 0, buffer.Length); AssertSequenced(buffer, 10); cacheStream.Position = 20; cacheStream.Write(new byte[10], 0, 10); Assert.Equal(30, cacheStream.Position); cacheStream.Position = 10; buffer = new byte[30]; cacheStream.Read(buffer, 0, buffer.Length); AssertSequenced(buffer, 0, 10, 10); AssertSequenced(buffer, 20, 10, 30); Assert.Equal(0, buffer[10]); Assert.Equal(0, buffer[19]); }
public void Bug5203_IncreaseSize() { MemoryStream ms = new MemoryStream(); BlockCacheSettings settings = new BlockCacheSettings { BlockSize = 64, LargeReadSize = 128, OptimumReadSize = 64, ReadCacheSize = 1024 }; BlockCacheStream bcs = new BlockCacheStream(SparseStream.FromStream(ms, Ownership.Dispose), Ownership.Dispose, settings); // Pre-load read cache with a 'short' block bcs.Write(new byte[11], 0, 11); bcs.Position = 0; bcs.Read(new byte[11], 0, 11); // Extend stream for (int i = 0; i < 20; ++i) { bcs.Write(new byte[11], 0, 11); } // Try to read from first block beyond length of original cached short length // Bug was throwing exception here bcs.Position = 60; bcs.Read(new byte[20], 0, 20); }