public override SegmentInfo Read(Directory dir, string segment, IOContext context)
        {
            string fileName = IndexFileNames.SegmentFileName(segment, "", Lucene46SegmentInfoFormat.SI_EXTENSION);
            ChecksumIndexInput input = dir.OpenChecksumInput(fileName, context);
            bool success = false;
            try
            {
                int codecVersion = CodecUtil.CheckHeader(input, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_START, Lucene46SegmentInfoFormat.VERSION_CURRENT);
                string version = input.ReadString();
                int docCount = input.ReadInt();
                if (docCount < 0)
                {
                    throw new CorruptIndexException("invalid docCount: " + docCount + " (resource=" + input + ")");
                }
                bool isCompoundFile = input.ReadByte() == SegmentInfo.YES;
                IDictionary<string, string> diagnostics = input.ReadStringStringMap();
                ISet<string> files = input.ReadStringSet();

                if (codecVersion >= Lucene46SegmentInfoFormat.VERSION_CHECKSUM)
                {
                    CodecUtil.CheckFooter(input);
                }
                else
                {
                    CodecUtil.CheckEOF(input);
                }

                SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics);
                si.Files = files;

                success = true;

                return si;
            }
            finally
            {
                if (!success)
                {
                    IOUtils.CloseWhileHandlingException(input);
                }
                else
                {
                    input.Dispose();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Constructs a bit vector from the file <code>name</code> in Directory
        ///  <code>d</code>, as written by the <seealso cref="#write"/> method.
        /// </summary>
        public BitVector(Directory d, string name, IOContext context)
        {
            ChecksumIndexInput input = d.OpenChecksumInput(name, context);

            try
            {
                int firstInt = input.ReadInt();

                if (firstInt == -2)
                {
                    // New format, with full header & version:
                    Version_Renamed = CodecUtil.CheckHeader(input, CODEC, VERSION_START, VERSION_CURRENT);
                    Size_Renamed = input.ReadInt();
                }
                else
                {
                    Version_Renamed = VERSION_PRE;
                    Size_Renamed = firstInt;
                }
                if (Size_Renamed == -1)
                {
                    if (Version_Renamed >= VERSION_DGAPS_CLEARED)
                    {
                        ReadClearedDgaps(input);
                    }
                    else
                    {
                        ReadSetDgaps(input);
                    }
                }
                else
                {
                    ReadBits(input);
                }

                if (Version_Renamed < VERSION_DGAPS_CLEARED)
                {
                    InvertAll();
                }

                if (Version_Renamed >= VERSION_CHECKSUM)
                {
                    CodecUtil.CheckFooter(input);
                }
                else
                {
                    CodecUtil.CheckEOF(input);
                }
                Debug.Assert(VerifyCount());
            }
            finally
            {
                input.Dispose();
            }
        }