Esempio n. 1
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();
         }
     }
 }
Esempio n. 2
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;
		}
Esempio n. 3
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;
		}
Esempio n. 4
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);
			}
		}
Esempio n. 5
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;
		}