/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		protected RandomAccessFileAdapter(string path, bool lockFile, long initialLength, 
			bool readOnly)
		{
			bool ok = false;
			try
			{
				_path = new Sharpen.IO.File(path).GetCanonicalPath();
				_delegate = RandomAccessFileFactory.NewRandomAccessFile(_path, readOnly, lockFile
					);
				if (initialLength > 0)
				{
					_delegate.Seek(initialLength - 1);
					_delegate.Write(new byte[] { 0 });
				}
				ok = true;
			}
			catch (IOException e)
			{
				throw new Db4oIOException(e);
			}
			finally
			{
				if (!ok)
				{
					Close();
				}
			}
		}
예제 #2
0
			/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
			public FileBin(BinConfiguration config)
			{
				bool ok = false;
				try
				{
					_path = new Sharpen.IO.File(config.Uri()).GetCanonicalPath();
					_file = RandomAccessFileFactory.NewRandomAccessFile(_path, config.ReadOnly(), config
						.LockFile());
					if (config.InitialLength() > 0)
					{
						Write(config.InitialLength() - 1, new byte[] { 0 }, 1);
					}
					ok = true;
				}
				catch (IOException e)
				{
					throw new Db4oIOException(e);
				}
				finally
				{
					if (!ok)
					{
						Close();
					}
				}
			}
예제 #3
0
 public static RandomAccessFile NewRandomAccessFile(String path, bool readOnly, bool lockFile)
 {
     RandomAccessFile raf = null;
     bool ok = false;
     try
     {
         raf = new RandomAccessFile(path, readOnly, lockFile);
         if (lockFile)
         {
             Platform4.LockFile(path, raf);
         }
         ok = true;
         return raf;
     }
     catch (IOException x)
     {
         if (new File(path).Exists())
         {
             throw new DatabaseFileLockedException(path, x);
         }
         throw new Db4oIOException(x);
     } 
     finally
     {
         if(!ok && raf != null)
         {
             raf.Close();
         }
     }
 }
예제 #4
0
		/// <exception cref="System.IO.IOException"></exception>
		private byte[] ReadAllBytes(string fileName)
		{
			int length = (int)new Sharpen.IO.File(fileName).Length();
			RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
			byte[] buffer = new byte[length];
			raf.Read(buffer);
			raf.Close();
			return buffer;
		}
예제 #5
0
		/// <exception cref="System.IO.IOException"></exception>
		public static byte FileHeaderVersion(string testFile)
		{
			RandomAccessFile raf = new RandomAccessFile(testFile, "r");
			byte[] bytes = new byte[1];
			raf.Read(bytes);
			// readByte() doesn't convert to .NET.
			byte db4oHeaderVersion = bytes[0];
			raf.Close();
			return db4oHeaderVersion;
		}
예제 #6
0
		/// <exception cref="System.IO.IOException"></exception>
		public virtual void Write(string path, RandomAccessFile raf, bool writeTrash)
		{
			if (_offset == 0)
			{
				writeTrash = false;
			}
			raf.Seek(_offset);
			raf.Write(BytesToWrite(_data, writeTrash), 0, _length);
			Write(FileBasedTransactionLogHandler.LockFileName(path), _lockFileData, writeTrash
				);
			Write(FileBasedTransactionLogHandler.LogFileName(path), _logFileData, writeTrash);
		}
예제 #7
0
		private void Write(string fileName, byte[] bytes, bool writeTrash)
		{
			if (bytes == null)
			{
				return;
			}
			try
			{
				RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
				raf.Write(BytesToWrite(bytes, writeTrash));
				raf.Close();
			}
			catch (IOException e)
			{
				throw new Db4oException(e);
			}
		}
예제 #8
0
		/// <exception cref="System.IO.IOException"></exception>
		public virtual int WriteVersions(string file, bool writeTrash)
		{
			int count = 0;
			int rcount = 0;
			string lastFileName = file + "0";
			string rightFileName = file + "R";
			File4.Copy(lastFileName, rightFileName);
			IEnumerator syncIter = _writes.GetEnumerator();
			while (syncIter.MoveNext())
			{
				rcount++;
				Collection4 writesBetweenSync = (Collection4)syncIter.Current;
				RandomAccessFile rightRaf = new RandomAccessFile(rightFileName, "rw");
				IEnumerator singleForwardIter = writesBetweenSync.GetEnumerator();
				while (singleForwardIter.MoveNext())
				{
					CrashSimulatingWrite csw = (CrashSimulatingWrite)singleForwardIter.Current;
					csw.Write(rightFileName, rightRaf, false);
				}
				rightRaf.Close();
				IEnumerator singleBackwardIter = writesBetweenSync.GetEnumerator();
				while (singleBackwardIter.MoveNext())
				{
					count++;
					CrashSimulatingWrite csw = (CrashSimulatingWrite)singleBackwardIter.Current;
					string currentFileName = file + "W" + count;
					File4.Copy(lastFileName, currentFileName);
					RandomAccessFile raf = new RandomAccessFile(currentFileName, "rw");
					csw.Write(currentFileName, raf, writeTrash);
					raf.Close();
					lastFileName = currentFileName;
				}
				File4.Copy(rightFileName, rightFileName + rcount);
				lastFileName = rightFileName;
			}
			return count;
		}
			public _ICodeBlock_43(RandomAccessFile raf, byte[] bytes)
			{
				this.raf = raf;
				this.bytes = bytes;
			}
예제 #10
0
		private static void LogToFile(string msg)
		{
			if (enabled)
			{
				if (!writeToLogFile)
				{
					return;
				}
				lock (Lock)
				{
					if (_logFile == null)
					{
						try
						{
							_logFile = new RandomAccessFile(LogFile(), "rw");
							LogToFile("\r\n\r\n ********** BEGIN LOG ********** \r\n\r\n ");
						}
						catch (IOException e)
						{
							Sharpen.Runtime.PrintStackTrace(e);
						}
					}
					msg = DateHandlerBase.Now() + "\r\n" + msg + "\r\n";
					byte[] bytes = stringIO.Write(msg);
					try
					{
						_logFile.Write(bytes);
					}
					catch (IOException e)
					{
						Sharpen.Runtime.PrintStackTrace(e);
					}
				}
			}
		}
예제 #11
0
			/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
			public virtual void Close()
			{
				Platform4.UnlockFile(_path, _file);
				try
				{
					if (!IsClosed())
					{
						_file.Close();
					}
				}
				catch (IOException e)
				{
					throw new Db4oIOException(e);
				}
				finally
				{
					_file = null;
				}
			}