Lucene.Net.Store.CompoundFileDirectory.OpenInput C# (CSharp) Method

OpenInput() public method

public OpenInput ( string name, IOContext context ) : IndexInput
name string
context IOContext
return IndexInput
        public override IndexInput OpenInput(string name, IOContext context)
        {
            lock (this)
            {
                EnsureOpen();
                Debug.Assert(!OpenForWrite);
                string id = IndexFileNames.StripSegmentName(name);
                FileEntry entry;
                if (!Entries.TryGetValue(id, out entry))
                {
                    throw new Exception("No sub-file with id " + id + " found (fileName=" + name + " files: " + Arrays.ToString(Entries.Keys) + ")");
                }
                return Handle.OpenSlice(name, entry.Offset, entry.Length);
            }
        }

Usage Example

        public virtual void TestManySubFiles()
        {
            Directory d = NewFSDirectory(CreateTempDir("CFSManySubFiles"));
            int FILE_COUNT = AtLeast(500);

            for (int fileIdx = 0; fileIdx < FILE_COUNT; fileIdx++)
            {
                IndexOutput @out = d.CreateOutput("file." + fileIdx, NewIOContext(Random()));
                @out.WriteByte((byte)(sbyte)fileIdx);
                @out.Dispose();
            }

            CompoundFileDirectory cfd = new CompoundFileDirectory(d, "c.cfs", NewIOContext(Random()), true);
            for (int fileIdx = 0; fileIdx < FILE_COUNT; fileIdx++)
            {
                string fileName = "file." + fileIdx;
                d.Copy(cfd, fileName, fileName, NewIOContext(Random()));
            }
            cfd.Dispose();

            IndexInput[] ins = new IndexInput[FILE_COUNT];
            CompoundFileDirectory cfr = new CompoundFileDirectory(d, "c.cfs", NewIOContext(Random()), false);
            for (int fileIdx = 0; fileIdx < FILE_COUNT; fileIdx++)
            {
                ins[fileIdx] = cfr.OpenInput("file." + fileIdx, NewIOContext(Random()));
            }

            for (int fileIdx = 0; fileIdx < FILE_COUNT; fileIdx++)
            {
                Assert.AreEqual((byte)fileIdx, ins[fileIdx].ReadByte());
            }

            for (int fileIdx = 0; fileIdx < FILE_COUNT; fileIdx++)
            {
                ins[fileIdx].Dispose();
            }
            cfr.Dispose();
            d.Dispose();
        }
All Usage Examples Of Lucene.Net.Store.CompoundFileDirectory::OpenInput