Lucene.Net.Store.MockDirectoryWrapper.SizeInBytes C# (CSharp) Method

SizeInBytes() public method

public SizeInBytes ( ) : long
return long
        public long SizeInBytes()
        {
            lock (this)
            {
                if (@in is RAMDirectory)
                {
                    return ((RAMDirectory)@in).SizeInBytes();
                }
                else
                {
                    // hack
                    long size = 0;
                    foreach (string file in @in.ListAll())
                    {
                        size += @in.FileLength(file);
                    }
                    return size;
                }
            }
        }

Usage Example

        public virtual void TestRAMDirectoryMem()
        {
            Directory dir = NewFSDirectory(IndexDir);
            MockDirectoryWrapper ramDir = new MockDirectoryWrapper(Random(), new RAMDirectory(dir, NewIOContext(Random())));

            // close the underlaying directory
            dir.Dispose();

            // Check size
            Assert.AreEqual(ramDir.SizeInBytes(), ramDir.RecomputedSizeInBytes);

            // open reader to test document count
            IndexReader reader = DirectoryReader.Open(ramDir);
            Assert.AreEqual(DocsToAdd, reader.NumDocs);

            // open search zo check if all doc's are there
            IndexSearcher searcher = NewSearcher(reader);

            // search for all documents
            for (int i = 0; i < DocsToAdd; i++)
            {
                Document doc = searcher.Doc(i);
                Assert.IsTrue(doc.GetField("content") != null);
            }

            // cleanup
            reader.Dispose();
        }
All Usage Examples Of Lucene.Net.Store.MockDirectoryWrapper::SizeInBytes