DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
LocalFileSystem.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.IO;
19 
20 namespace Deveel.Data.Store {
21  public sealed class LocalFileSystem : IFileSystem {
22  public bool FileExists(string path) {
23  return File.Exists(path);
24  }
25 
26  IFile IFileSystem.OpenFile(string path, bool readOnly) {
27  return OpenFile(path, readOnly);
28  }
29 
30  public LocalFile OpenFile(string fileName, bool readOnly) {
31  if (!FileExists(fileName))
32  throw new IOException(string.Format("The file '{0}' does not exist: cannot be opened", fileName));
33 
34  return new LocalFile(fileName, readOnly);
35  }
36 
37  IFile IFileSystem.CreateFile(string path) {
38  return CreateFile(path);
39  }
40 
41  public LocalFile CreateFile(string fileName) {
42  if (String.IsNullOrEmpty(fileName))
43  throw new ArgumentNullException("fileName");
44 
45  if (FileExists(fileName))
46  throw new IOException(string.Format("The file '{0}' already exists: cannot create.", fileName));
47 
48  return new LocalFile(fileName, false);
49  }
50 
51  public bool DeleteFile(string path) {
52  File.Delete(path);
53  return FileExists(path);
54  }
55 
56  public string CombinePath(string path1, string path2) {
57  return Path.Combine(path1, path2);
58  }
59 
60  public bool RenameFile(string sourcePath, string destPath) {
61  File.Move(sourcePath, destPath);
62  return File.Exists(destPath);
63  }
64 
65  public bool DirectoryExists(string path) {
66  return Directory.Exists(path);
67  }
68 
69  public void CreateDirectory(string path) {
70  Directory.CreateDirectory(path);
71  }
72 
73  public long GetFileSize(string path) {
74  return new FileInfo(path).Length;
75  }
76  }
77 }
string CombinePath(string path1, string path2)
LocalFile CreateFile(string fileName)
LocalFile OpenFile(string fileName, bool readOnly)
bool RenameFile(string sourcePath, string destPath)
IFile CreateFile(string path)
IFile OpenFile(string path, bool readOnly)