/// <summary>Removes an existing file in the directory. </summary> public override void RenameFile(System.String from, System.String to) { RAMFile file = (RAMFile)files[from]; files.Remove(from); files[to] = file; }
/// <summary>Creates a new, empty file in the directory with the given name. /// Returns a stream writing this file. /// </summary> public override IndexOutput CreateOutput(System.String name) { RAMFile file = new RAMFile(); files[name] = file; return(new RAMOutputStream(file)); }
/// <summary>Set the modified time of an existing file to now. </summary> public override void TouchFile(System.String name) { // final boolean MONITOR = false; RAMFile file = (RAMFile)files[name]; long ts2, ts1 = System.DateTime.Now.Ticks; do { try { System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 0 + 100 * 1)); } catch (System.Threading.ThreadInterruptedException) { } ts2 = System.DateTime.Now.Ticks; // if (MONITOR) { // count++; // } }while (ts1 == ts2); file.lastModified = ts2; // if (MONITOR) // System.out.println("SLEEP COUNT: " + count); }
public override IndexInput OpenInput(String name) { lock (this) { RAMFile file = (RAMFile)fileMap[name]; if (file == null) { throw new System.IO.FileNotFoundException(name); } else { if (openFiles.Contains(name)) { int v = (int)openFiles[name]; v = (System.Int32)(v + 1); openFiles[name] = v; } else { openFiles[name] = 1; } } return(new MockRAMInputStream(this, name, file)); } }
public RAMOutputStream(RAMFile f) { file = f; // make sure that we switch to the // first needed buffer lazily currentBufferIndex = -1; currentBuffer = null; }
public /*internal*/ RAMOutputStream(RAMFile f) { file = f; // make sure that we switch to the // first needed buffer lazily currentBufferIndex = - 1; currentBuffer = null; }
public RAMOutputStream(RAMFile f) { File = f; // make sure that we switch to the // first needed buffer lazily CurrentBufferIndex = -1; CurrentBuffer = null; }
/// <summary> /// Returns the length in bytes of a file in the directory. </summary> /// <exception cref="System.IO.IOException"> if the file does not exist </exception> public override sealed long FileLength(string name) { EnsureOpen(); RAMFile file = FileMap[name]; if (file == null) { throw new FileNotFoundException(name); } return(file.Length); }
/// <summary> /// Creates a new, empty file in the directory with the given name. Returns a stream writing this file. </summary> public override IndexOutput CreateOutput(string name, IOContext context) { EnsureOpen(); RAMFile file = NewRAMFile(); if (m_fileMap.TryRemove(name, out RAMFile existing) && existing != null) { m_sizeInBytes.AddAndGet(-existing.m_sizeInBytes); existing.directory = null; } m_fileMap[name] = file; return(new RAMOutputStream(file)); }
public /*internal*/ RAMInputStream(RAMFile f) { file = f; length = file.length; if (length / BUFFER_SIZE >= System.Int32.MaxValue) { throw new System.IO.IOException("Too large RAMFile! " + length); } // make sure that we switch to the // first needed buffer lazily currentBufferIndex = - 1; currentBuffer = null; }
public /*internal*/ RAMInputStream(RAMFile f) { file = f; length = file.length; if (length / BUFFER_SIZE >= System.Int32.MaxValue) { throw new System.IO.IOException("Too large RAMFile! " + length); } // make sure that we switch to the // first needed buffer lazily currentBufferIndex = -1; currentBuffer = null; }
public RAMInputStream(string name, RAMFile f) : base("RAMInputStream(name=" + name + ")") { File = f; Length_Renamed = File.Length_Renamed; if (Length_Renamed / BUFFER_SIZE >= int.MaxValue) { throw new System.IO.IOException("RAMInputStream too large length=" + Length_Renamed + ": " + name); } // make sure that we switch to the // first needed buffer lazily CurrentBufferIndex = -1; CurrentBuffer = null; }
/// <summary> /// Creates a new, empty file in the directory with the given name. Returns a stream writing this file. </summary> public override IndexOutput CreateOutput(string name, IOContext context) { EnsureOpen(); RAMFile file = NewRAMFile(); RAMFile existing; FileMap.TryGetValue(name, out existing); if (existing != null) { sizeInBytes.AddAndGet(-existing.SizeInBytes_Renamed); existing.Directory = null; } FileMap[name] = file; return(new RAMOutputStream(file)); }
public RAMInputStream(string name, RAMFile f) : base("RAMInputStream(name=" + name + ")") { file = f; length = file.length; if (length / BUFFER_SIZE >= int.MaxValue) { throw new IOException("RAMInputStream too large length=" + length + ": " + name); } // make sure that we switch to the // first needed buffer lazily currentBufferIndex = -1; currentBuffer = null; }
/// <summary>Creates a new, empty file in the directory with the given name. Returns a stream writing this file. </summary> public override IndexOutput CreateOutput(System.String name) { RAMFile file = new RAMFile(this); lock (this) { RAMFile existing = (RAMFile)fileMap[name]; if (existing != null) { sizeInBytes -= existing.sizeInBytes; existing.directory = null; } fileMap[name] = file; } return(new RAMOutputStream(file)); }
/// <summary>Removes an existing file in the directory.</summary> /// <throws> IOException if the file does not exist </throws> public override void DeleteFile(System.String name) { lock (this) { RAMFile file = (RAMFile)fileMap[name]; if (file != null) { fileMap.Remove(name); file.directory = null; sizeInBytes -= file.sizeInBytes; // updates to RAMFile.sizeInBytes synchronized on directory } else { throw new System.IO.FileNotFoundException(name); } } }
/// <summary>Creates a new, empty file in the directory with the given name. Returns a stream writing this file. </summary> public override IndexOutput CreateOutput(string name) { EnsureOpen(); RAMFile file = new RAMFile(this); lock (this) { RAMFile existing = fileMap[name]; if (existing != null) { internalSizeInBytes -= existing.sizeInBytes; existing.directory = null; } fileMap[name] = file; } return(new RAMOutputStream(file)); }
/// <summary>Removes an existing file in the directory.</summary> /// <throws> IOException if the file does not exist </throws> public override void DeleteFile(string name) { lock (this) { EnsureOpen(); RAMFile file = fileMap[name]; if (file != null) { fileMap.Remove(name); file.directory = null; internalSizeInBytes -= file.sizeInBytes; } else { throw new System.IO.FileNotFoundException(name); } } }
public override IndexOutput CreateOutput(String name) { lock (this) { if (crashed) { throw new System.IO.IOException("cannot createOutput after crash"); } Init(); if (preventDoubleWrite && createdFiles.Contains(name) && !name.Equals("segments.gen")) { throw new System.IO.IOException("file \"" + name + "\" was already written to"); } if (noDeleteOpenFile && openFiles.Contains(name)) { throw new System.IO.IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot overwrite"); } RAMFile file = new RAMFile(this); if (crashed) { throw new System.IO.IOException("cannot createOutput after crash"); } unSyncedFiles[name] = name; createdFiles[name] = name; RAMFile existing = (RAMFile)fileMap[name]; // Enforce write once: if (existing != null && !name.Equals("segments.gen") && preventDoubleWrite) { throw new System.IO.IOException("file " + name + " already exists"); } else { if (existing != null) { sizeInBytes -= existing.sizeInBytes_ForNUnit; existing.directory_ForNUnit = null; } fileMap[name] = file; } return(new MockRAMOutputStream(this, file, name)); } }
/// <summary>Renames an existing file in the directory.</summary> /// <throws> FileNotFoundException if from does not exist </throws> /// <deprecated> /// </deprecated> public override void RenameFile(System.String from, System.String to) { lock (this) { RAMFile fromFile = (RAMFile)fileMap[from]; if (fromFile == null) { throw new System.IO.FileNotFoundException(from); } RAMFile toFile = (RAMFile)fileMap[to]; if (toFile != null) { sizeInBytes -= toFile.sizeInBytes; // updates to RAMFile.sizeInBytes synchronized on directory toFile.directory = null; } fileMap.Remove(from); fileMap[to] = fromFile; } }
/// <summary>Simulates a crash of OS or machine by overwriting /// unsynced files. /// </summary> public virtual void Crash() { lock (this) { crashed = true; openFiles = new System.Collections.Hashtable(); System.Collections.IEnumerator it = unSyncedFiles.GetEnumerator(); unSyncedFiles = new System.Collections.Hashtable(); int count = 0; while (it.MoveNext()) { System.String name = (System.String)((System.Collections.DictionaryEntry)it.Current).Value; RAMFile file = (RAMFile)fileMap_ForNUnit[name]; if (count % 3 == 0) { DeleteFile(name, true); } else if (count % 3 == 1) { // Zero out file entirely int numBuffers = file.NumBuffers(); for (int i = 0; i < numBuffers; i++) { byte[] buffer = file.GetBuffer(i); for (int j = 0; j < buffer.Length; j++) { buffer[j] = (byte)0; } } } else if (count % 3 == 2) { // Truncate the file: file.SetLength(file.GetLength() / 2); } count++; } } }
/* Simulates a crash of OS or machine by overwriting * unsynced files. */ public virtual void Crash() { lock (this) { crashed = true; openFiles = new Dictionary <string, int>(); openFilesDeleted = Support.Compatibility.SetFactory.CreateHashSet <string>(); var it = unSyncedFiles.GetEnumerator(); unSyncedFiles = Support.Compatibility.SetFactory.CreateHashSet <string>(); int count = 0; while (it.MoveNext()) { string name = it.Current; RAMFile file = fileMap[name]; if (count % 3 == 0) { DeleteFile(name, true); } else if (count % 3 == 1) { // Zero out file entirely int numBuffers = file.NumBuffers(); for (int i = 0; i < numBuffers; i++) { byte[] buffer = file.GetBuffer(i); Array.Clear(buffer, 0, buffer.Length); } } else if (count % 3 == 2) { // Truncate the file: file.Length = file.Length / 2; } count++; } } }
/// <summary>Returns true iff the named file exists in this directory. </summary> public override bool FileExists(System.String name) { RAMFile file = (RAMFile)files[name]; return(file != null); }
/// <summary>Returns the time the named file was last modified. </summary> public override long FileModified(System.String name) { RAMFile file = (RAMFile)files[name]; return(file.lastModified); }
public RAMInputStream(RAMFile f) { file = f; length = file.length; }
public void SetNameForFileMap_Nunit(string name, RAMFile ramFile) { FileMap[name] = ramFile; }
// for testing public static RAMInputStream RAMInputStream_ForNUnitTest(RAMFile f) { return(new RAMInputStream(f)); }
// for testing public static RAMInputStream RAMInputStream_ForNUnitTest(RAMFile f) { return new RAMInputStream(f); }
/// <summary>Returns the length in bytes of a file in the directory. </summary> public override long FileLength(System.String name) { RAMFile file = (RAMFile)files[name]; return(file.length); }
public /*internal*/ RAMOutputStream(RAMFile f) { file = f; }
/// <summary>Construct an empty output buffer. </summary> /// <throws> IOException </throws> public MockRAMInputStream(MockRAMDirectory dir, System.String name, RAMFile f) : base(f) { this.name = name; this.dir = dir; }
/// <summary>Returns a stream reading an existing file. </summary> public override IndexInput OpenInput(System.String name) { RAMFile file = (RAMFile)files[name]; return(new RAMInputStream(file)); }
internal RAMOutputStream(RAMFile f) { file = f; }
/// <summary>Creates a new, empty file in the directory with the given name. /// Returns a stream writing this file. /// </summary> public override IndexOutput CreateOutput(System.String name) { RAMFile file = new RAMFile(); files[name] = file; return new RAMOutputStream(file); }
public override IndexOutput CreateOutput(System.String name) { if (openFiles == null) { openFiles = new System.Collections.Hashtable(); } lock (openFiles.SyncRoot) { if (noDeleteOpenFile && openFiles.Contains(name)) throw new System.IO.IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot overwrite"); } RAMFile file = new RAMFile(this); lock (this) { RAMFile existing = (RAMFile) fileMap_ForNUnitTest[name]; // Enforce write once: if (existing != null && !name.Equals("segments.gen")) throw new System.IO.IOException("file " + name + " already exists"); else { if (existing != null) { sizeInBytes_ForNUnitTest -= existing.sizeInBytes_ForNUnitTest; existing.directory_ForNUnitTest = null; } fileMap_ForNUnitTest[name] = file; } } return new MockRAMOutputStream(this, file); }
/// <summary>Creates a new, empty file in the directory with the given name. Returns a stream writing this file. </summary> public override IndexOutput CreateOutput(System.String name) { EnsureOpen(); RAMFile file = new RAMFile(this); lock (this) { RAMFile existing = (RAMFile) fileMap[name]; if (existing != null) { sizeInBytes -= existing.sizeInBytes; existing.directory = null; } fileMap[name] = file; } return new RAMOutputStream(file); }
/// <summary>Construct an empty output buffer. </summary> /// <throws> IOException </throws> public MockRAMInputStream(MockRAMDirectory dir, System.String name, RAMFile f):base(f) { this.name = name; this.dir = dir; }
public override IndexOutput CreateOutput(string name, IOContext context) { lock (this) { MaybeThrowDeterministicException(); MaybeThrowIOExceptionOnOpen(name); MaybeYield(); if (FailOnCreateOutput_Renamed) { MaybeThrowDeterministicException(); } if (Crashed) { throw new System.IO.IOException("cannot createOutput after crash"); } Init(); lock (this) { if (PreventDoubleWrite_Renamed && CreatedFiles.Contains(name) && !name.Equals("segments.gen")) { throw new System.IO.IOException("file \"" + name + "\" was already written to"); } } if ((NoDeleteOpenFile_Renamed || assertNoDeleteOpenFile) && OpenFiles.ContainsKey(name)) { if (!assertNoDeleteOpenFile) { throw new System.IO.IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite"); } else { throw new InvalidOperationException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite"); } } if (Crashed) { throw new System.IO.IOException("cannot createOutput after crash"); } UnSyncedFiles.Add(name); CreatedFiles.Add(name); if (@in is RAMDirectory) { RAMDirectory ramdir = (RAMDirectory)@in; RAMFile file = new RAMFile(ramdir); RAMFile existing = ramdir.GetNameFromFileMap_Nunit(name); // Enforce write once: if (existing != null && !name.Equals("segments.gen") && PreventDoubleWrite_Renamed) { throw new System.IO.IOException("file " + name + " already exists"); } else { if (existing != null) { ramdir.GetAndAddSizeInBytes_Nunit(-existing.SizeInBytes); existing.SetDirectory_Nunit(null); } ramdir.SetNameForFileMap_Nunit(name, file); } } //System.out.println(Thread.currentThread().getName() + ": MDW: create " + name); IndexOutput delegateOutput = @in.CreateOutput(name, LuceneTestCase.NewIOContext(RandomState, context)); if (RandomState.Next(10) == 0) { // once in a while wrap the IO in a Buffered IO with random buffer sizes delegateOutput = new BufferedIndexOutputWrapper(this, 1 + RandomState.Next(BufferedIndexOutput.DEFAULT_BUFFER_SIZE), delegateOutput); } IndexOutput io = new MockIndexOutputWrapper(this, delegateOutput, name); AddFileHandle(io, name, Handle.Output); OpenFilesForWrite.Add(name); // throttling REALLY slows down tests, so don't do it very often for SOMETIMES. if (throttling == Throttling_e.ALWAYS || (throttling == Throttling_e.SOMETIMES && RandomState.Next(50) == 0) && !(@in is RateLimitedDirectoryWrapper)) { if (LuceneTestCase.VERBOSE) { Console.WriteLine("MockDirectoryWrapper: throttling indexOutput (" + name + ")"); } return ThrottledOutput.NewFromDelegate(io); } else { return io; } } }
public override IndexOutput CreateOutput(System.String name) { lock (this) { if (crashed) throw new System.IO.IOException("cannot createOutput after crash"); Init(); if (preventDoubleWrite && createdFiles.Contains(name) && !name.Equals("segments.gen")) throw new System.IO.IOException("file \"" + name + "\" was already written to"); if (noDeleteOpenFile && openFiles.Contains(name)) throw new System.IO.IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot overwrite"); RAMFile file = new RAMFile(this); if (crashed) throw new System.IO.IOException("cannot createOutput after crash"); SupportClass.CollectionsHelper.AddIfNotContains(unSyncedFiles, name); SupportClass.CollectionsHelper.AddIfNotContains(createdFiles, name); RAMFile existing = (RAMFile) fileMap_ForNUnit[name]; // Enforce write once: if (existing != null && !name.Equals("segments.gen") && preventDoubleWrite) throw new System.IO.IOException("file " + name + " already exists"); else { if (existing != null) { sizeInBytes_ForNUnitTest -= existing.sizeInBytes_ForNUnit; existing.directory_ForNUnit = null; } fileMap_ForNUnit[name] = file; } return new MockRAMOutputStream(this, file, name); } }
internal SortingDocsAndPositionsEnum(int maxDoc, SortingDocsAndPositionsEnum reuse, DocsAndPositionsEnum @in, Sorter.DocMap docMap, bool storeOffsets) : base(@in) { this.maxDoc = maxDoc; this.storeOffsets = storeOffsets; if (reuse != null) { docs = reuse.docs; offsets = reuse.offsets; payload = reuse.payload; file = reuse.file; if (reuse.maxDoc == maxDoc) { sorter = reuse.sorter; } else { sorter = new DocOffsetSorter(maxDoc); } } else { docs = new int[32]; offsets = new long[32]; payload = new BytesRef(32); file = new RAMFile(); sorter = new DocOffsetSorter(maxDoc); } using (IndexOutput @out = new RAMOutputStream(file)) { int doc; int i = 0; while ((doc = @in.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (i == docs.Length) { int newLength = ArrayUtil.Oversize(i + 1, 4); docs = Arrays.CopyOf(docs, newLength); offsets = Arrays.CopyOf(offsets, newLength); } docs[i] = docMap.OldToNew(doc); offsets[i] = @out.FilePointer; AddPositions(@in, @out); i++; } upto = i; sorter.Reset(docs, offsets); sorter.Sort(0, upto); } this.postingInput = new RAMInputStream("", file); }
/// <summary>Construct an empty output buffer. </summary> public MockRAMOutputStream(MockRAMDirectory dir, RAMFile f, System.String name):base(f) { this.dir = dir; this.name = name; }
/// <summary>Construct an empty output buffer. </summary> public MockRAMOutputStream(MockRAMDirectory dir, RAMFile f, System.String name) : base(f) { this.dir = dir; this.name = name; }
/// <summary>Construct an empty output buffer. </summary> public MockRAMOutputStream(MockRAMDirectory dir, RAMFile f) : base(f) { this.dir = dir; }
public override IndexOutput CreateOutput(String name) { lock (this) { if (crashed) throw new System.IO.IOException("cannot createOutput after crash"); Init(); if (preventDoubleWrite && createdFiles.Contains(name) && !name.Equals("segments.gen")) throw new System.IO.IOException("file \"" + name + "\" was already written to"); if (noDeleteOpenFile && openFiles.ContainsKey(name)) throw new System.IO.IOException("MockRAMDirectory: file \"" + name + "\" is still open: cannot overwrite"); RAMFile file = new RAMFile(this); if (crashed) throw new System.IO.IOException("cannot createOutput after crash"); unSyncedFiles.Add(name); createdFiles.Add(name); RAMFile existing = fileMap[name]; // Enforce write once: if (existing != null && !name.Equals("segments.gen") && preventDoubleWrite) throw new System.IO.IOException("file " + name + " already exists"); else { if (existing != null) { internalSizeInBytes -= existing.sizeInBytes; existing.directory = null; } fileMap[name]=file; } return new MockRAMOutputStream(this, file, name); } }