WriteChecksum() публичный статический Метод

public static WriteChecksum ( Store.IndexOutput output, Util.BytesRef scratch ) : void
output Store.IndexOutput
scratch Util.BytesRef
Результат void
Пример #1
0
        protected override void Dispose(bool disposing)
        {
            if (data == null || !disposing)
            {
                return;
            }
            var success = false;

            try
            {
                Debug.Assert(_fieldsSeen.Count > 0);
                // java : sheisty to do this here?
                SimpleTextUtil.Write(data, END);
                SimpleTextUtil.WriteNewline(data);
                SimpleTextUtil.WriteChecksum(data, scratch);
                success = true;
            }
            finally
            {
                if (success)
                {
                    IOUtils.Dispose(data);
                }
                else
                {
                    IOUtils.DisposeWhileHandlingException(data);
                }
                data = null;
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void close() throws java.io.IOException
        public override void close()
        {
            if (data != null)
            {
                bool success = false;
                try
                {
                    Debug.Assert(fieldsSeen.Count > 0);
                    // TODO: sheisty to do this here?
                    SimpleTextUtil.write(data, END);
                    SimpleTextUtil.WriteNewline(data);
                    SimpleTextUtil.WriteChecksum(data, scratch);
                    success = true;
                }
                finally
                {
                    if (success)
                    {
                        IOUtils.close(data);
                    }
                    else
                    {
                        IOUtils.closeWhileHandlingException(data);
                    }
                    data = null;
                }
            }
        }
 public override void Finish(FieldInfos fis, int numDocs)
 {
     if (_numDocsWritten != numDocs)
     {
         throw new Exception("mergeFields produced an invalid result: docCount is " + numDocs + " but only saw " +
                             _numDocsWritten + " file=" + _output +
                             "; now aborting this merge to prevent index corruption");
     }
     Write(END);
     NewLine();
     SimpleTextUtil.WriteChecksum(_output, _scratch);
 }
 public override void Finish(FieldInfos fis, int numDocs)
 {
     if (numDocsWritten != numDocs)
     {
         throw new Exception("mergeVectors produced an invalid result: mergedDocs is " + numDocs +
                             " but vec numDocs is " + numDocsWritten + " file=" + _output.ToString() +
                             "; now aborting this merge to prevent index corruption");
     }
     Write(END);
     NewLine();
     SimpleTextUtil.WriteChecksum(_output, scratch);
 }
Пример #5
0
 public override void Dispose()
 {
     if (_output != null)
     {
         try
         {
             Write(END);
             Newline();
             SimpleTextUtil.WriteChecksum(_output, _scratch);
         }
         finally
         {
             _output.Dispose();
             _output = null;
         }
     }
 }
        public override void WriteLiveDocs(IMutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount,
                                           IOContext context)
        {
            var set     = ((SimpleTextBits)bits).bits;
            var size    = bits.Length;
            var scratch = new BytesRef();

            var         fileName = IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.NextDelGen);
            IndexOutput output   = null;
            var         success  = false;

            try
            {
                output = dir.CreateOutput(fileName, context);
                SimpleTextUtil.Write(output, SIZE);
                SimpleTextUtil.Write(output, Convert.ToString(size, CultureInfo.InvariantCulture), scratch);
                SimpleTextUtil.WriteNewline(output);

                for (int i = set.NextSetBit(0); i >= 0; i = set.NextSetBit(i + 1))
                {
                    SimpleTextUtil.Write(output, DOC);
                    SimpleTextUtil.Write(output, Convert.ToString(i, CultureInfo.InvariantCulture), scratch);
                    SimpleTextUtil.WriteNewline(output);
                }

                SimpleTextUtil.Write(output, END);
                SimpleTextUtil.WriteNewline(output);
                SimpleTextUtil.WriteChecksum(output, scratch);
                success = true;
            }
            finally
            {
                if (success)
                {
                    IOUtils.Dispose(output);
                }
                else
                {
                    IOUtils.DisposeWhileHandlingException(output);
                }
            }
        }
Пример #7
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_output == null)
                {
                    return;
                }

                try
                {
                    Write(END);
                    Newline();
                    SimpleTextUtil.WriteChecksum(_output, _scratch);
                }
                finally
                {
                    _output.Dispose();
                    _output = null;
                }
            }
        }
Пример #8
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();
                }
            }
        }
        public override void Write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos,
                                   IOContext context)
        {
            var fileName = IndexFileNames.SegmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
            var output   = directory.CreateOutput(fileName, context);
            var scratch  = new BytesRef();
            var success  = false;

            try
            {
                SimpleTextUtil.Write(output, NUMFIELDS);
                SimpleTextUtil.Write(output, Convert.ToString(infos.Size()), scratch);
                SimpleTextUtil.WriteNewline(output);

                foreach (FieldInfo fi in infos)
                {
                    SimpleTextUtil.Write(output, NAME);
                    SimpleTextUtil.Write(output, fi.Name, scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, NUMBER);
                    SimpleTextUtil.Write(output, Convert.ToString(fi.Number), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, ISINDEXED);
                    SimpleTextUtil.Write(output, Convert.ToString(fi.Indexed), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    if (fi.Indexed)
                    {
                        Debug.Assert(fi.FieldIndexOptions >= FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !fi.HasPayloads());
                        SimpleTextUtil.Write(output, INDEXOPTIONS);
                        SimpleTextUtil.Write(output, fi.FieldIndexOptions.ToString(), scratch);
                        SimpleTextUtil.WriteNewline(output);
                    }

                    SimpleTextUtil.Write(output, STORETV);
                    SimpleTextUtil.Write(output, Convert.ToString(fi.HasVectors()), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, PAYLOADS);
                    SimpleTextUtil.Write(output, Convert.ToString(fi.HasPayloads()), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, NORMS);
                    SimpleTextUtil.Write(output, Convert.ToString(!fi.OmitsNorms()), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, NORMS_TYPE);
                    SimpleTextUtil.Write(output, GetDocValuesType(fi.NormType), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, DOCVALUES);
                    SimpleTextUtil.Write(output, GetDocValuesType(fi.DocValuesType), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, DOCVALUES_GEN);
                    SimpleTextUtil.Write(output, Convert.ToString(fi.DocValuesGen), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    IDictionary <string, string> atts = fi.Attributes();
                    int numAtts = atts == null ? 0 : atts.Count;
                    SimpleTextUtil.Write(output, NUM_ATTS);
                    SimpleTextUtil.Write(output, Convert.ToString(numAtts), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    if (numAtts <= 0 || atts == null)
                    {
                        continue;
                    }
                    foreach (var entry in atts)
                    {
                        SimpleTextUtil.Write(output, ATT_KEY);
                        SimpleTextUtil.Write(output, entry.Key, scratch);
                        SimpleTextUtil.WriteNewline(output);

                        SimpleTextUtil.Write(output, ATT_VALUE);
                        SimpleTextUtil.Write(output, entry.Value, scratch);
                        SimpleTextUtil.WriteNewline(output);
                    }
                }
                SimpleTextUtil.WriteChecksum(output, scratch);
                success = true;
            }
            finally
            {
                if (success)
                {
                    output.Dispose();
                }
                else
                {
                    IOUtils.CloseWhileHandlingException(output);
                }
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public void write(store.Directory directory, String segmentName, String segmentSuffix, index.FieldInfos infos, store.IOContext context) throws java.io.IOException
        public override void write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos, IOContext context)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String fileName = index.IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
            string      fileName = IndexFileNames.segmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
            IndexOutput @out     = directory.createOutput(fileName, context);
            BytesRef    scratch  = new BytesRef();
            bool        success  = false;

            try
            {
                SimpleTextUtil.write(@out, NUMFIELDS);
                SimpleTextUtil.write(@out, Convert.ToString(infos.size()), scratch);
                SimpleTextUtil.WriteNewline(@out);

                foreach (FieldInfo fi in infos)
                {
                    SimpleTextUtil.write(@out, NAME);
                    SimpleTextUtil.write(@out, fi.name, scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    SimpleTextUtil.write(@out, NUMBER);
                    SimpleTextUtil.write(@out, Convert.ToString(fi.number), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    SimpleTextUtil.write(@out, ISINDEXED);
                    SimpleTextUtil.write(@out, Convert.ToString(fi.Indexed), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    if (fi.Indexed)
                    {
                        Debug.Assert(fi.IndexOptions.compareTo(FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads());
                        SimpleTextUtil.write(@out, INDEXOPTIONS);
                        SimpleTextUtil.write(@out, fi.IndexOptions.ToString(), scratch);
                        SimpleTextUtil.WriteNewline(@out);
                    }

                    SimpleTextUtil.write(@out, STORETV);
                    SimpleTextUtil.write(@out, Convert.ToString(fi.hasVectors()), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    SimpleTextUtil.write(@out, PAYLOADS);
                    SimpleTextUtil.write(@out, Convert.ToString(fi.hasPayloads()), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    SimpleTextUtil.write(@out, NORMS);
                    SimpleTextUtil.write(@out, Convert.ToString(!fi.omitsNorms()), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    SimpleTextUtil.write(@out, NORMS_TYPE);
                    SimpleTextUtil.write(@out, getDocValuesType(fi.NormType), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    SimpleTextUtil.write(@out, DOCVALUES);
                    SimpleTextUtil.write(@out, getDocValuesType(fi.DocValuesType), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    SimpleTextUtil.write(@out, DOCVALUES_GEN);
                    SimpleTextUtil.write(@out, Convert.ToString(fi.DocValuesGen), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    IDictionary <string, string> atts = fi.attributes();
                    int numAtts = atts == null ? 0 : atts.Count;
                    SimpleTextUtil.write(@out, NUM_ATTS);
                    SimpleTextUtil.write(@out, Convert.ToString(numAtts), scratch);
                    SimpleTextUtil.WriteNewline(@out);

                    if (numAtts > 0)
                    {
                        foreach (KeyValuePair <string, string> entry in atts.SetOfKeyValuePairs())
                        {
                            SimpleTextUtil.write(@out, ATT_KEY);
                            SimpleTextUtil.write(@out, entry.Key, scratch);
                            SimpleTextUtil.WriteNewline(@out);

                            SimpleTextUtil.write(@out, ATT_VALUE);
                            SimpleTextUtil.write(@out, entry.Value, scratch);
                            SimpleTextUtil.WriteNewline(@out);
                        }
                    }
                }
                SimpleTextUtil.WriteChecksum(@out, scratch);
                success = true;
            }
            finally
            {
                if (success)
                {
                    @out.close();
                }
                else
                {
                    IOUtils.closeWhileHandlingException(@out);
                }
            }
        }
Пример #11
0
        public override void Write(Directory dir, SegmentInfo si, FieldInfos fis, IOContext ioContext)
        {
            var segFileName = IndexFileNames.SegmentFileName(si.Name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);

            si.AddFile(segFileName);

            var success = false;
            var output  = dir.CreateOutput(segFileName, ioContext);

            try
            {
                var 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, CultureInfo.InvariantCulture), scratch);
                SimpleTextUtil.WriteNewline(output);

                SimpleTextUtil.Write(output, SI_USECOMPOUND);
                SimpleTextUtil.Write(output, Convert.ToString(si.UseCompoundFile, CultureInfo.InvariantCulture).ToLowerInvariant(), scratch);
                SimpleTextUtil.WriteNewline(output);

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

                if (numDiagnostics > 0)
                {
                    foreach (var diagEntry in diagnostics)
                    {
                        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);
                    }
                }

                var files    = si.GetFiles();
                var numFiles = files is null ? 0 : files.Count;
                SimpleTextUtil.Write(output, SI_NUM_FILES);
                SimpleTextUtil.Write(output, Convert.ToString(numFiles, CultureInfo.InvariantCulture), scratch);
                SimpleTextUtil.WriteNewline(output);

                if (numFiles > 0)
                {
                    foreach (var 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.DisposeWhileHandlingException(output);
                    try
                    {
                        dir.DeleteFile(segFileName);
                    }
                    catch (Exception t) when(t.IsThrowable())
                    {
                        //Esnure we throw original exeception
                    }
                }
                else
                {
                    output.Dispose();
                }
            }
        }
Пример #12
0
        public override void Write(Directory directory, string segmentName, string segmentSuffix, FieldInfos infos,
                                   IOContext context)
        {
            var fileName = IndexFileNames.SegmentFileName(segmentName, segmentSuffix, FIELD_INFOS_EXTENSION);
            var output   = directory.CreateOutput(fileName, context);
            var scratch  = new BytesRef();
            var success  = false;

            try
            {
                SimpleTextUtil.Write(output, NUMFIELDS);
                SimpleTextUtil.Write(output, infos.Count.ToString(CultureInfo.InvariantCulture), scratch);
                SimpleTextUtil.WriteNewline(output);

                foreach (FieldInfo fi in infos)
                {
                    SimpleTextUtil.Write(output, NAME);
                    SimpleTextUtil.Write(output, fi.Name, scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, NUMBER);
                    SimpleTextUtil.Write(output, fi.Number.ToString(CultureInfo.InvariantCulture), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, ISINDEXED);
                    SimpleTextUtil.Write(output, CultureInfo.InvariantCulture.TextInfo.ToLower(fi.IsIndexed.ToString()), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    if (fi.IsIndexed)
                    {
                        // LUCENENET specific - to avoid boxing, changed from CompareTo() to IndexOptionsComparer.Compare()
                        if (Debugging.AssertsEnabled)
                        {
                            Debugging.Assert(IndexOptionsComparer.Default.Compare(fi.IndexOptions, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.HasPayloads);
                        }
                        SimpleTextUtil.Write(output, INDEXOPTIONS);
                        SimpleTextUtil.Write(output,
                                             fi.IndexOptions != IndexOptions.NONE ? fi.IndexOptions.ToString() : string.Empty,
                                             scratch);
                        SimpleTextUtil.WriteNewline(output);
                    }

                    SimpleTextUtil.Write(output, STORETV);
                    SimpleTextUtil.Write(output, CultureInfo.InvariantCulture.TextInfo.ToLower(fi.HasVectors.ToString()), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, PAYLOADS);
                    SimpleTextUtil.Write(output, CultureInfo.InvariantCulture.TextInfo.ToLower(fi.HasPayloads.ToString()), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, NORMS);
                    SimpleTextUtil.Write(output, CultureInfo.InvariantCulture.TextInfo.ToLower((!fi.OmitsNorms).ToString()), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, NORMS_TYPE);
                    SimpleTextUtil.Write(output, GetDocValuesType(fi.NormType), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, DOCVALUES);
                    SimpleTextUtil.Write(output, GetDocValuesType(fi.DocValuesType), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    SimpleTextUtil.Write(output, DOCVALUES_GEN);
                    SimpleTextUtil.Write(output, fi.DocValuesGen.ToString(CultureInfo.InvariantCulture), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    IDictionary <string, string> atts = fi.Attributes;
                    int numAtts = atts == null ? 0 : atts.Count;
                    SimpleTextUtil.Write(output, NUM_ATTS);
                    SimpleTextUtil.Write(output, numAtts.ToString(CultureInfo.InvariantCulture), scratch);
                    SimpleTextUtil.WriteNewline(output);

                    if (numAtts <= 0 || atts == null)
                    {
                        continue;
                    }
                    foreach (var entry in atts)
                    {
                        SimpleTextUtil.Write(output, ATT_KEY);
                        SimpleTextUtil.Write(output, entry.Key, scratch);
                        SimpleTextUtil.WriteNewline(output);

                        SimpleTextUtil.Write(output, ATT_VALUE);
                        SimpleTextUtil.Write(output, entry.Value, scratch);
                        SimpleTextUtil.WriteNewline(output);
                    }
                }
                SimpleTextUtil.WriteChecksum(output, scratch);
                success = true;
            }
            finally
            {
                if (success)
                {
                    output.Dispose();
                }
                else
                {
                    IOUtils.DisposeWhileHandlingException(output);
                }
            }
        }