Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
 public virtual int Read(long position, byte[] bytes, int bytesToRead)
 {
     lock (this)
     {
         return(_bin.Read(position, bytes, bytesToRead));
     }
 }
Exemplo n.º 3
0
 /// <exception cref="System.Exception"></exception>
 private void AssertReadWriteString(IBin adapter, string str)
 {
     byte[] data = Sharpen.Runtime.GetBytesForString(str);
     byte[] read = new byte[2048];
     adapter.Write(0, data, data.Length);
     adapter.Read(0, read, read.Length);
     Assert.AreEqual(str, Sharpen.Runtime.GetStringForBytes(read, 0, data.Length));
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
 public virtual void Replay(IBin bin)
 {
     bin.Read(_pos, PrepareBuffer(), _length);
 }
 private void Read(IBin storage, ByteArrayBuffer buffer)
 {
     storage.Read(0, buffer._buffer, buffer.Length());
 }
Exemplo n.º 8
0
		public virtual void Replay(IBin bin)
		{
			bin.Read(_pos, PrepareBuffer(), _length);
		}
		private void Read(IBin storage, ByteArrayBuffer buffer)
		{
			storage.Read(0, buffer._buffer, buffer.Length());
		}
Exemplo n.º 10
0
 /// <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);
 }
Exemplo n.º 11
0
 /// <exception cref="System.Exception"></exception>
 private void AssertReadWriteString(IBin adapter, string str)
 {
     var data = Runtime.GetBytesForString(str);
     var read = new byte[2048];
     adapter.Write(0, data, data.Length);
     adapter.Read(0, read, read.Length);
     Assert.AreEqual(str, Runtime.GetStringForBytes(read, 0, data.Length));
 }
Exemplo n.º 12
0
		/// <seealso cref="IBin.Read(long, byte[], int)">IBin.Read(long, byte[], int)</seealso>
		public virtual int Read(long position, byte[] bytes, int bytesToRead)
		{
			return _bin.Read(position, bytes, bytesToRead);
		}