/// <summary>
        /// write the header for this field </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeFieldEntry(index.FieldInfo field, index.FieldInfo.DocValuesType type) throws java.io.IOException
        private void writeFieldEntry(FieldInfo field, FieldInfo.DocValuesType type)
        {
            SimpleTextUtil.write(data, FIELD);
            SimpleTextUtil.write(data, field.name, scratch);
            SimpleTextUtil.WriteNewline(data);

            SimpleTextUtil.write(data, TYPE);
            SimpleTextUtil.write(data, type.ToString(), scratch);
            SimpleTextUtil.WriteNewline(data);
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public index.FieldInfos read(store.Directory directory, String segmentName, String segmentSuffix, store.IOContext iocontext) throws java.io.IOException
        public override FieldInfos read(Directory directory, string segmentName, string segmentSuffix, IOContext iocontext)
        {
//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);
            ChecksumIndexInput input    = directory.openChecksumInput(fileName, iocontext);
            BytesRef           scratch  = new BytesRef();

            bool success = false;

            try
            {
                SimpleTextUtil.ReadLine(input, scratch);
                Debug.Assert(StringHelper.StartsWith(scratch, NUMFIELDS));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int size = Integer.parseInt(readString(NUMFIELDS.length, scratch));
                int         size  = Convert.ToInt32(readString(NUMFIELDS.length, scratch));
                FieldInfo[] infos = new FieldInfo[size];

                for (int i = 0; i < size; i++)
                {
                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, NAME));
                    string name = readString(NAME.length, scratch);

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, NUMBER));
                    int fieldNumber = Convert.ToInt32(readString(NUMBER.length, scratch));

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, ISINDEXED));
                    bool isIndexed = Convert.ToBoolean(readString(ISINDEXED.length, scratch));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final index.FieldInfo.IndexOptions indexOptions;
                    FieldInfo.IndexOptions indexOptions;
                    if (isIndexed)
                    {
                        SimpleTextUtil.ReadLine(input, scratch);
                        Debug.Assert(StringHelper.StartsWith(scratch, INDEXOPTIONS));
                        indexOptions = FieldInfo.IndexOptions.valueOf(readString(INDEXOPTIONS.length, scratch));
                    }
                    else
                    {
                        indexOptions = null;
                    }

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, STORETV));
                    bool storeTermVector = Convert.ToBoolean(readString(STORETV.length, scratch));

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, PAYLOADS));
                    bool storePayloads = Convert.ToBoolean(readString(PAYLOADS.length, scratch));

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, NORMS));
                    bool omitNorms = !Convert.ToBoolean(readString(NORMS.length, scratch));

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, NORMS_TYPE));
                    string nrmType = readString(NORMS_TYPE.length, scratch);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final index.FieldInfo.DocValuesType normsType = docValuesType(nrmType);
                    FieldInfo.DocValuesType normsType = docValuesType(nrmType);

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, DOCVALUES));
                    string dvType = readString(DOCVALUES.length, scratch);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final index.FieldInfo.DocValuesType docValuesType = docValuesType(dvType);
                    FieldInfo.DocValuesType docValuesType = docValuesType(dvType);

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, DOCVALUES_GEN));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long dvGen = Long.parseLong(readString(DOCVALUES_GEN.length, scratch));
                    long dvGen = Convert.ToInt64(readString(DOCVALUES_GEN.length, scratch));

                    SimpleTextUtil.ReadLine(input, scratch);
                    Debug.Assert(StringHelper.StartsWith(scratch, NUM_ATTS));
                    int numAtts = Convert.ToInt32(readString(NUM_ATTS.length, scratch));
                    IDictionary <string, string> atts = new Dictionary <string, string>();

                    for (int j = 0; j < numAtts; j++)
                    {
                        SimpleTextUtil.ReadLine(input, scratch);
                        Debug.Assert(StringHelper.StartsWith(scratch, ATT_KEY));
                        string key = readString(ATT_KEY.length, scratch);

                        SimpleTextUtil.ReadLine(input, scratch);
                        Debug.Assert(StringHelper.StartsWith(scratch, ATT_VALUE));
                        string value = readString(ATT_VALUE.length, scratch);
                        atts[key] = value;
                    }

                    infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, omitNorms, storePayloads, indexOptions, docValuesType, normsType, Collections.unmodifiableMap(atts));
                    infos[i].DocValuesGen = dvGen;
                }

                SimpleTextUtil.CheckFooter(input);

                FieldInfos fieldInfos = new FieldInfos(infos);
                success = true;
                return(fieldInfos);
            }
            finally
            {
                if (success)
                {
                    input.close();
                }
                else
                {
                    IOUtils.closeWhileHandlingException(input);
                }
            }
        }
 private static string getDocValuesType(FieldInfo.DocValuesType type)
 {
     return(type == null ? "false" : type.ToString());
 }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public SimpleTextDocValuesReader(index.SegmentReadState state, String ext) throws java.io.IOException
        public SimpleTextDocValuesReader(SegmentReadState state, string ext)
        {
            // System.out.println("dir=" + state.directory + " seg=" + state.segmentInfo.name + " file=" + IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext));
            data   = state.directory.openInput(IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, ext), state.context);
            maxDoc = state.segmentInfo.DocCount;
            while (true)
            {
                readLine();
                //System.out.println("READ field=" + scratch.utf8ToString());
                if (scratch.Equals(END))
                {
                    break;
                }
                Debug.Assert(startsWith(FIELD), scratch.utf8ToString());
                string fieldName = stripPrefix(FIELD);
                //System.out.println("  field=" + fieldName);

                OneField field = new OneField();
                fields[fieldName] = field;

                readLine();
                Debug.Assert(startsWith(TYPE), scratch.utf8ToString());

                FieldInfo.DocValuesType dvType = FieldInfo.DocValuesType.valueOf(stripPrefix(TYPE));
                Debug.Assert(dvType != null);
                if (dvType == FieldInfo.DocValuesType.NUMERIC)
                {
                    readLine();
                    Debug.Assert(startsWith(MINVALUE), "got " + scratch.utf8ToString() + " field=" + fieldName + " ext=" + ext);
                    field.minValue = Convert.ToInt64(stripPrefix(MINVALUE));
                    readLine();
                    Debug.Assert(startsWith(PATTERN));
                    field.pattern = stripPrefix(PATTERN);
                    field.dataStartFilePointer = data.FilePointer;
                    data.seek(data.FilePointer + (1 + field.pattern.Length + 2) * maxDoc);
                }
                else if (dvType == FieldInfo.DocValuesType.BINARY)
                {
                    readLine();
                    Debug.Assert(startsWith(MAXLENGTH));
                    field.maxLength = Convert.ToInt32(stripPrefix(MAXLENGTH));
                    readLine();
                    Debug.Assert(startsWith(PATTERN));
                    field.pattern = stripPrefix(PATTERN);
                    field.dataStartFilePointer = data.FilePointer;
                    data.seek(data.FilePointer + (9 + field.pattern.Length + field.maxLength + 2) * maxDoc);
                }
                else if (dvType == FieldInfo.DocValuesType.SORTED || dvType == FieldInfo.DocValuesType.SORTED_SET)
                {
                    readLine();
                    Debug.Assert(startsWith(NUMVALUES));
                    field.numValues = Convert.ToInt64(stripPrefix(NUMVALUES));
                    readLine();
                    Debug.Assert(startsWith(MAXLENGTH));
                    field.maxLength = Convert.ToInt32(stripPrefix(MAXLENGTH));
                    readLine();
                    Debug.Assert(startsWith(PATTERN));
                    field.pattern = stripPrefix(PATTERN);
                    readLine();
                    Debug.Assert(startsWith(ORDPATTERN));
                    field.ordPattern           = stripPrefix(ORDPATTERN);
                    field.dataStartFilePointer = data.FilePointer;
                    data.seek(data.FilePointer + (9 + field.pattern.Length + field.maxLength) * field.numValues + (1 + field.ordPattern.Length) * maxDoc);
                }
                else
                {
                    throw new AssertionError();
                }
            }

            // We should only be called from above if at least one
            // field has DVs:
            Debug.Assert(fields.Count > 0);
        }