Lucene.Net.Index.SegmentInfos.WriteSegmentsGen C# (CSharp) Method

WriteSegmentsGen() public static method

A utility for writing the IndexFileNames#SEGMENTS_GEN file to a Directory.

NOTE: this is an internal utility which is kept public so that it's accessible by code from other packages. You should avoid calling this method unless you're absolutely sure what you're doing! @lucene.internal

public static WriteSegmentsGen ( Directory dir, long generation ) : void
dir Directory
generation long
return void
        public static void WriteSegmentsGen(Directory dir, long generation)
        {
            try
            {
                IndexOutput genOutput = dir.CreateOutput(IndexFileNames.SEGMENTS_GEN, IOContext.READONCE);
                try
                {
                    genOutput.WriteInt(FORMAT_SEGMENTS_GEN_CURRENT);
                    genOutput.WriteLong(generation);
                    genOutput.WriteLong(generation);
                    CodecUtil.WriteFooter(genOutput);
                }
                finally
                {
                    genOutput.Dispose();
                    dir.Sync(Collections.Singleton(IndexFileNames.SEGMENTS_GEN));
                }
            }
            catch (Exception)
            {
                // It's OK if we fail to write this file since it's
                // used only as one of the retry fallbacks.
                try
                {
                    dir.DeleteFile(IndexFileNames.SEGMENTS_GEN);
                }
                catch (Exception)
                {
                    // Ignore; this file is only used in a retry
                    // fallback on init.
                }
            }
        }