コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void write(store.Directory dir, index.SegmentInfo si, index.FieldInfos fis, store.IOContext ioContext) throws java.io.IOException
        public override void write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext)
        {
            string segFileName = IndexFileNames.segmentFileName(si.name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);

            si.addFile(segFileName);

            bool        success = false;
            IndexOutput output  = dir.createOutput(segFileName, ioContext);

            try
            {
                BytesRef scratch = new BytesRef();

                SimpleTextUtil.write(output, SI_VERSION);
                SimpleTextUtil.write(output, si.Version, scratch);
                SimpleTextUtil.WriteNewline(output);

                SimpleTextUtil.write(output, SI_DOCCOUNT);
                SimpleTextUtil.write(output, Convert.ToString(si.DocCount), scratch);
                SimpleTextUtil.WriteNewline(output);

                SimpleTextUtil.write(output, SI_USECOMPOUND);
                SimpleTextUtil.write(output, Convert.ToString(si.UseCompoundFile), scratch);
                SimpleTextUtil.WriteNewline(output);

                IDictionary <string, string> diagnostics = si.Diagnostics;
                int numDiagnostics = diagnostics == null ? 0 : diagnostics.Count;
                SimpleTextUtil.write(output, SI_NUM_DIAG);
                SimpleTextUtil.write(output, Convert.ToString(numDiagnostics), scratch);
                SimpleTextUtil.WriteNewline(output);

                if (numDiagnostics > 0)
                {
                    foreach (KeyValuePair <string, string> diagEntry in diagnostics.SetOfKeyValuePairs())
                    {
                        SimpleTextUtil.write(output, SI_DIAG_KEY);
                        SimpleTextUtil.write(output, diagEntry.Key, scratch);
                        SimpleTextUtil.WriteNewline(output);

                        SimpleTextUtil.write(output, SI_DIAG_VALUE);
                        SimpleTextUtil.write(output, diagEntry.Value, scratch);
                        SimpleTextUtil.WriteNewline(output);
                    }
                }

                HashSet <string> files = si.files();
                int numFiles           = files == null ? 0 : files.Count;
                SimpleTextUtil.write(output, SI_NUM_FILES);
                SimpleTextUtil.write(output, Convert.ToString(numFiles), scratch);
                SimpleTextUtil.WriteNewline(output);

                if (numFiles > 0)
                {
                    foreach (string fileName in files)
                    {
                        SimpleTextUtil.write(output, SI_FILE);
                        SimpleTextUtil.write(output, fileName, scratch);
                        SimpleTextUtil.WriteNewline(output);
                    }
                }

                SimpleTextUtil.WriteChecksum(output, scratch);
                success = true;
            }
            finally
            {
                if (!success)
                {
                    IOUtils.closeWhileHandlingException(output);
                    try
                    {
                        dir.deleteFile(segFileName);
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    output.close();
                }
            }
        }