19 using Lucene.Net.Support;
21 namespace Lucene.Net.Store
32 private const long serialVersionUID = 1L;
34 internal protected HashMap<string, RAMFile> fileMap =
new HashMap<string, RAMFile>();
35 internal protected long internalSizeInBytes = 0;
74 [System.Runtime.Serialization.OnDeserialized]
75 void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
77 if (interalLockFactory == null)
79 SetLockFactory(
new SingleInstanceLockFactory());
83 public override System.String[] ListAll()
89 System.Collections.Generic.ISet<
string> fileNames = Support.Compatibility.SetFactory.CreateHashSet(fileMap.Keys);
90 System.String[] result =
new System.String[fileNames.Count];
92 foreach(
string filename
in fileNames)
94 result[i++] = filename;
101 public override bool FileExists(System.String name)
107 file = fileMap[name];
114 public override long FileModified(System.String name)
120 file = fileMap[name];
123 throw new System.IO.FileNotFoundException(name);
127 return new DateTime(file.LastModified*TimeSpan.TicksPerMillisecond, DateTimeKind.Utc).ToLocalTime().Ticks/
128 TimeSpan.TicksPerMillisecond;
133 public override void TouchFile(System.String name)
139 file = fileMap[name];
142 throw new System.IO.FileNotFoundException(name);
144 long ts2, ts1 = System.DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;
149 System.Threading.Thread.Sleep(
new System.TimeSpan((System.Int64) 10000 * 0 + 100 * 1));
151 catch (System.Threading.ThreadInterruptedException ie)
156 throw new System.SystemException(ie.Message, ie);
158 ts2 = System.DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;
162 file.LastModified = ts2;
167 public override long FileLength(System.String name)
173 file = fileMap[name];
176 throw new System.IO.FileNotFoundException(name);
184 public long SizeInBytes()
189 return internalSizeInBytes;
195 public override void DeleteFile(System.String name)
203 fileMap.Remove(name);
204 file.directory = null;
205 internalSizeInBytes -= file.sizeInBytes;
208 throw new System.IO.FileNotFoundException(name);
219 RAMFile existing = fileMap[name];
220 if (existing != null)
222 internalSizeInBytes -= existing.sizeInBytes;
223 existing.directory = null;
225 fileMap[name] = file;
237 file = fileMap[name];
240 throw new System.IO.FileNotFoundException(name);
245 protected override void Dispose(
bool disposing)