public static long CalcTotalFileSize(FSDirectory dir) { long totalFileSize = 0; foreach (string file in dir.ListAll()) { totalFileSize += dir.FileLength(file); // FileInfo fi = new FileInfo(file); // totalFileSize += fi.Length; } return totalFileSize; }
public virtual void TestDirectInstantiation() { DirectoryInfo path = CreateTempDir("testDirectInstantiation"); byte[] largeBuffer = new byte[Random().Next(256 * 1024)], largeReadBuffer = new byte[largeBuffer.Length]; for (int i = 0; i < largeBuffer.Length; i++) { largeBuffer[i] = (byte)i; // automatically loops with modulo } var dirs = new FSDirectory[] { new SimpleFSDirectory(path, null), new NIOFSDirectory(path, null), new MMapDirectory(path, null) }; for (int i = 0; i < dirs.Length; i++) { FSDirectory dir = dirs[i]; dir.EnsureOpen(); string fname = "foo." + i; string lockname = "foo" + i + ".lck"; IndexOutput @out = dir.CreateOutput(fname, NewIOContext(Random())); @out.WriteByte((byte)(sbyte)i); @out.WriteBytes(largeBuffer, largeBuffer.Length); @out.Dispose(); for (int j = 0; j < dirs.Length; j++) { FSDirectory d2 = dirs[j]; d2.EnsureOpen(); Assert.IsTrue(SlowFileExists(d2, fname)); Assert.AreEqual(1 + largeBuffer.Length, d2.FileLength(fname)); // don't do read tests if unmapping is not supported! if (d2 is MMapDirectory && !((MMapDirectory)d2).UseUnmap) { continue; } IndexInput input = d2.OpenInput(fname, NewIOContext(Random())); Assert.AreEqual((byte)i, input.ReadByte()); // read array with buffering enabled Arrays.Fill(largeReadBuffer, (byte)0); input.ReadBytes(largeReadBuffer, 0, largeReadBuffer.Length, true); Assert.AreEqual(largeBuffer, largeReadBuffer); // read again without using buffer input.Seek(1L); Arrays.Fill(largeReadBuffer, (byte)0); input.ReadBytes(largeReadBuffer, 0, largeReadBuffer.Length, false); Assert.AreEqual(largeBuffer, largeReadBuffer); input.Dispose(); } // delete with a different dir dirs[(i + 1) % dirs.Length].DeleteFile(fname); for (int j = 0; j < dirs.Length; j++) { FSDirectory d2 = dirs[j]; Assert.IsFalse(SlowFileExists(d2, fname)); } Lock @lock = dir.MakeLock(lockname); Assert.IsTrue(@lock.Obtain()); for (int j = 0; j < dirs.Length; j++) { FSDirectory d2 = dirs[j]; Lock lock2 = d2.MakeLock(lockname); try { Assert.IsFalse(lock2.Obtain(1)); } catch (LockObtainFailedException e) { // OK } } @lock.Dispose(); // now lock with different dir @lock = dirs[(i + 1) % dirs.Length].MakeLock(lockname); Assert.IsTrue(@lock.Obtain()); @lock.Dispose(); } for (int i = 0; i < dirs.Length; i++) { FSDirectory dir = dirs[i]; dir.EnsureOpen(); dir.Dispose(); Assert.IsFalse(dir.IsOpen); } }
public override long FileLength(System.String name, IState state) { return(fsDir.FileLength(name, null)); }
public void ShowFiles(FSDirectory dir) { String[] files = dir.ListAll(); listIndexFiles.Items.Clear(); foreach (string file in files) { // FileInfo fi = new FileInfo(file); ListViewItem row = new ListViewItem( new string[] { file, //fi.Name, NormalizeSize(dir.FileLength(file)), NormalizeUnit(dir.FileLength(file)) }); listIndexFiles.Items.Add(row); } long totalFileSize = CalcTotalFileSize(dir); lblFileSize.Text = NormalizeSize(totalFileSize) + NormalizeUnit(totalFileSize); }