Пример #1
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();
                    }
                }
            }
        /// <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();
                }
            }
        }