lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnas...@apache.org
Subject [4/7] Cleanup of codes, mostly SimpleText in this commit
Date Sun, 21 Sep 2014 16:53:30 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
index b9be9f1..d7db938 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextFieldsWriter.cs
@@ -1,6 +1,4 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -17,175 +15,200 @@ package org.apache.lucene.codecs.simpletext;
  * limitations under the License.
  */
 
-import java.io.IOException;
-import java.util.Comparator;
-
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.PostingsConsumer;
-import org.apache.lucene.codecs.TermStats;
-import org.apache.lucene.codecs.TermsConsumer;
-import org.apache.lucene.index.FieldInfo.IndexOptions;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.BytesRef;
-
-class SimpleTextFieldsWriter extends FieldsConsumer {
-  
-  private IndexOutput out;
-  private final BytesRef scratch = new BytesRef(10);
-
-  final static BytesRef END          = new BytesRef("END");
-  final static BytesRef FIELD        = new BytesRef("field ");
-  final static BytesRef TERM         = new BytesRef("  term ");
-  final static BytesRef DOC          = new BytesRef("    doc ");
-  final static BytesRef FREQ         = new BytesRef("      freq ");
-  final static BytesRef POS          = new BytesRef("      pos ");
-  final static BytesRef START_OFFSET = new BytesRef("      startOffset ");
-  final static BytesRef END_OFFSET   = new BytesRef("      endOffset ");
-  final static BytesRef PAYLOAD      = new BytesRef("        payload ");
-
-  public SimpleTextFieldsWriter(SegmentWriteState state)  {
-    final String fileName = SimpleTextPostingsFormat.getPostingsFileName(state.segmentInfo.name, state.segmentSuffix);
-    out = state.directory.createOutput(fileName, state.context);
-  }
-
-  private void write(String s)  {
-    SimpleTextUtil.write(out, s, scratch);
-  }
-
-  private void write(BytesRef b)  {
-    SimpleTextUtil.write(out, b);
-  }
-
-  private void newline()  {
-    SimpleTextUtil.writeNewline(out);
-  }
-
-  @Override
-  public TermsConsumer addField(FieldInfo field)  {
-    write(FIELD);
-    write(field.name);
-    newline();
-    return new SimpleTextTermsWriter(field);
-  }
-
-  private class SimpleTextTermsWriter extends TermsConsumer {
-    private final SimpleTextPostingsWriter postingsWriter;
-    
-    public SimpleTextTermsWriter(FieldInfo field) {
-      postingsWriter = new SimpleTextPostingsWriter(field);
-    }
-
-    @Override
-    public PostingsConsumer startTerm(BytesRef term)  {
-      return postingsWriter.reset(term);
-    }
-
-    @Override
-    public void finishTerm(BytesRef term, TermStats stats)  {
-    }
-
-    @Override
-    public void finish(long sumTotalTermFreq, long sumDocFreq, int docCount)  {
-    }
-
-    @Override
-    public Comparator<BytesRef> getComparator() {
-      return BytesRef.getUTF8SortedAsUnicodeComparator();
-    }
-  }
-
-  private class SimpleTextPostingsWriter extends PostingsConsumer {
-    private BytesRef term;
-    private bool wroteTerm;
-    private final IndexOptions indexOptions;
-    private final bool writePositions;
-    private final bool writeOffsets;
-
-    // for Debug.Assert(:
-    private int lastStartOffset = 0;
-
-    public SimpleTextPostingsWriter(FieldInfo field) {
-      this.indexOptions = field.getIndexOptions();
-      writePositions = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
-      writeOffsets = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
-      //System.out.println("writeOffsets=" + writeOffsets);
-      //System.out.println("writePos=" + writePositions);
-    }
-
-    @Override
-    public void startDoc(int docID, int termDocFreq)  {
-      if (!wroteTerm) {
-        // we lazily do this, in case the term had zero docs
-        write(TERM);
-        write(term);
-        newline();
-        wroteTerm = true;
-      }
-
-      write(DOC);
-      write(Integer.toString(docID));
-      newline();
-      if (indexOptions != IndexOptions.DOCS_ONLY) {
-        write(FREQ);
-        write(Integer.toString(termDocFreq));
-        newline();
-      }
-
-      lastStartOffset = 0;
-    }
-    
-    public PostingsConsumer reset(BytesRef term) {
-      this.term = term;
-      wroteTerm = false;
-      return this;
-    }
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+    using IndexOptions = Index.FieldInfo.IndexOptions;
+    using FieldInfo = Index.FieldInfo;
+    using SegmentWriteState = Index.SegmentWriteState;
+    using IndexOutput = Store.IndexOutput;
+    using BytesRef = Util.BytesRef;
+
+    internal class SimpleTextFieldsWriter : FieldsConsumer
+    {
+
+        private IndexOutput _output;
+        private readonly BytesRef _scratch = new BytesRef(10);
+
+        internal static readonly BytesRef END = new BytesRef("END");
+        internal static readonly BytesRef FIELD = new BytesRef("field ");
+        internal static readonly BytesRef TERM = new BytesRef("  term ");
+        internal static readonly BytesRef DOC = new BytesRef("    doc ");
+        internal static readonly BytesRef FREQ = new BytesRef("      freq ");
+        internal static readonly BytesRef POS = new BytesRef("      pos ");
+        internal static readonly BytesRef START_OFFSET = new BytesRef("      startOffset ");
+        internal static readonly BytesRef END_OFFSET = new BytesRef("      endOffset ");
+        internal static readonly BytesRef PAYLOAD = new BytesRef("        payload ");
+
+        public SimpleTextFieldsWriter(SegmentWriteState state)
+        {
+            var fileName = SimpleTextPostingsFormat.GetPostingsFileName(state.SegmentInfo.Name, state.SegmentSuffix);
+            _output = state.Directory.CreateOutput(fileName, state.Context);
+        }
+
+        private void Write(string s)
+        {
+            SimpleTextUtil.Write(_output, s, _scratch);
+        }
+
+        private void Write(BytesRef b)
+        {
+            SimpleTextUtil.Write(_output, b);
+        }
+
+        private void Newline()
+        {
+            SimpleTextUtil.WriteNewline(_output);
+        }
+
+        public override TermsConsumer AddField(FieldInfo field)
+        {
+            Write(FIELD);
+            Write(field.Name);
+            Newline();
+            return new SimpleTextTermsWriter(this, field);
+        }
+
+        public override void Dispose()
+        {
+            if (_output != null)
+            {
+                try
+                {
+                    Write(END);
+                    Newline();
+                    SimpleTextUtil.WriteChecksum(_output, _scratch);
+                }
+                finally
+                {
+                    _output.Dispose();
+                    _output = null;
+                }
+            }
+        }
+
+        private class SimpleTextTermsWriter : TermsConsumer
+        {
+            private readonly SimpleTextFieldsWriter _outerInstance;
+            private readonly SimpleTextPostingsWriter _postingsWriter;
+
+            public SimpleTextTermsWriter(SimpleTextFieldsWriter outerInstance, FieldInfo field)
+            {
+                this._outerInstance = outerInstance;
+                _postingsWriter = new SimpleTextPostingsWriter(outerInstance, field);
+            }
+
+            public override PostingsConsumer StartTerm(BytesRef term)
+            {
+                return _postingsWriter.Reset(term);
+            }
+
+            public override void FinishTerm(BytesRef term, TermStats stats)
+            {
+            }
+
+            public override void Finish(long sumTotalTermFreq, long sumDocFreq, int docCount)
+            {
+            }
+
+            public override IComparer<BytesRef> Comparator
+            {
+                get { return BytesRef.UTF8SortedAsUnicodeComparer; }
+            }
+        }
+
+        private sealed class SimpleTextPostingsWriter : PostingsConsumer
+        {
+            private readonly SimpleTextFieldsWriter _outerInstance;
+
+            private BytesRef _term;
+            private bool _wroteTerm;
+            private readonly IndexOptions _indexOptions;
+            private readonly bool _writePositions;
+            private readonly bool _writeOffsets;
+
+            // for assert:
+            private int _lastStartOffset = 0;
+
+            public SimpleTextPostingsWriter(SimpleTextFieldsWriter outerInstance, FieldInfo field)
+            {
+                _outerInstance = outerInstance;
+                _indexOptions = field.FieldIndexOptions.Value;
+                _writePositions = _indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
+                _writeOffsets = _indexOptions >= IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
+            }
+
+            public override void StartDoc(int docID, int termDocFreq)
+            {
+                if (!_wroteTerm)
+                {
+                    // we lazily do this, in case the term had zero docs
+                    _outerInstance.Write(TERM);
+                    _outerInstance.Write(_term);
+                    _outerInstance.Newline();
+                    _wroteTerm = true;
+                }
+
+                _outerInstance.Write(DOC);
+                _outerInstance.Write(Convert.ToString(docID));
+                _outerInstance.Newline();
+                if (_indexOptions != IndexOptions.DOCS_ONLY)
+                {
+                    _outerInstance.Write(FREQ);
+                    _outerInstance.Write(Convert.ToString(termDocFreq));
+                    _outerInstance.Newline();
+                }
+
+                _lastStartOffset = 0;
+            }
+
+            public PostingsConsumer Reset(BytesRef term)
+            {
+                this._term = term;
+                _wroteTerm = false;
+                return this;
+            }
+
+            public override void AddPosition(int position, BytesRef payload, int startOffset, int endOffset)
+            {
+                if (_writePositions)
+                {
+                    _outerInstance.Write(POS);
+                    _outerInstance.Write(Convert.ToString(position));
+                    _outerInstance.Newline();
+                }
+
+                if (_writeOffsets)
+                {
+                    Debug.Assert(endOffset >= startOffset);
+                    Debug.Assert(startOffset >= _lastStartOffset,
+                        "startOffset=" + startOffset + " lastStartOffset=" + _lastStartOffset);
+                    _lastStartOffset = startOffset;
+                    _outerInstance.Write(START_OFFSET);
+                    _outerInstance.Write(Convert.ToString(startOffset));
+                    _outerInstance.Newline();
+                    _outerInstance.Write(END_OFFSET);
+                    _outerInstance.Write(Convert.ToString(endOffset));
+                    _outerInstance.Newline();
+                }
+
+                if (payload != null && payload.Length > 0)
+                {
+                    Debug.Assert(payload.Length != 0);
+                    _outerInstance.Write(PAYLOAD);
+                    _outerInstance.Write(payload);
+                    _outerInstance.Newline();
+                }
+            }
+
+            public override void FinishDoc()
+            {
+            }
+        }
 
-    @Override
-    public void addPosition(int position, BytesRef payload, int startOffset, int endOffset)  {
-      if (writePositions) {
-        write(POS);
-        write(Integer.toString(position));
-        newline();
-      }
-
-      if (writeOffsets) {
-        Debug.Assert( endOffset >= startOffset;
-        Debug.Assert( startOffset >= lastStartOffset: "startOffset=" + startOffset + " lastStartOffset=" + lastStartOffset;
-        lastStartOffset = startOffset;
-        write(START_OFFSET);
-        write(Integer.toString(startOffset));
-        newline();
-        write(END_OFFSET);
-        write(Integer.toString(endOffset));
-        newline();
-      }
-
-      if (payload != null && payload.length > 0) {
-        Debug.Assert( payload.length != 0;
-        write(PAYLOAD);
-        write(payload);
-        newline();
-      }
     }
 
-    @Override
-    public void finishDoc() {
-    }
-  }
-
-  @Override
-  public void close()  {
-    if (out != null) {
-      try {
-        write(END);
-        newline();
-        SimpleTextUtil.writeChecksum(out, scratch);
-      } finally {
-        out.close();
-        out = null;
-      }
-    }
-  }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
index 55cbbe1..d5ec0b3 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextLiveDocsFormat.cs
@@ -1,188 +1,215 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
-import java.util.BitSet;
-import java.util.Collection;
-
-import org.apache.lucene.codecs.LiveDocsFormat;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentCommitInfo;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.MutableBits;
-import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.util.UnicodeUtil;
-
-/**
- * reads/writes plaintext live docs
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextLiveDocsFormat extends LiveDocsFormat {
-
-  static final String LIVEDOCS_EXTENSION = "liv";
-  
-  final static BytesRef SIZE             = new BytesRef("size ");
-  final static BytesRef DOC              = new BytesRef("  doc ");
-  final static BytesRef END              = new BytesRef("END");
-  
-  @Override
-  public MutableBits newLiveDocs(int size)  {
-    return new SimpleTextMutableBits(size);
-  }
-
-  @Override
-  public MutableBits newLiveDocs(Bits existing)  {
-    final SimpleTextBits bits = (SimpleTextBits) existing;
-    return new SimpleTextMutableBits((BitSet)bits.bits.clone(), bits.size);
-  }
-
-  @Override
-  public Bits readLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context)  {
-    Debug.Assert( info.hasDeletions();
-    BytesRef scratch = new BytesRef();
-    CharsRef scratchUTF16 = new CharsRef();
-    
-    String fileName = IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getDelGen());
-    ChecksumIndexInput in = null;
-    bool success = false;
-    try {
-      in = dir.openChecksumInput(fileName, context);
-      
-      SimpleTextUtil.readLine(in, scratch);
-      Debug.Assert( StringHelper.startsWith(scratch, SIZE);
-      int size = parseIntAt(scratch, SIZE.length, scratchUTF16);
-      
-      BitSet bits = new BitSet(size);
-      
-      SimpleTextUtil.readLine(in, scratch);
-      while (!scratch.equals(END)) {
-        Debug.Assert( StringHelper.startsWith(scratch, DOC);
-        int docid = parseIntAt(scratch, DOC.length, scratchUTF16);
-        bits.set(docid);
-        SimpleTextUtil.readLine(in, scratch);
-      }
-      
-      SimpleTextUtil.checkFooter(in);
-      
-      success = true;
-      return new SimpleTextBits(bits, size);
-    } finally {
-      if (success) {
-        IOUtils.close(in);
-      } else {
-        IOUtils.closeWhileHandlingException(in);
-      }
-    }
-  }
-  
-  private int parseIntAt(BytesRef bytes, int offset, CharsRef scratch) {
-    UnicodeUtil.UTF8toUTF16(bytes.bytes, bytes.offset+offset, bytes.length-offset, scratch);
-    return ArrayUtil.parseInt(scratch.chars, 0, scratch.length);
-  }
-
-  @Override
-  public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context)  {
-    BitSet set = ((SimpleTextBits) bits).bits;
-    int size = bits.length();
-    BytesRef scratch = new BytesRef();
-    
-    String fileName = IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getNextDelGen());
-    IndexOutput out = null;
-    bool success = false;
-    try {
-      out = dir.createOutput(fileName, context);
-      SimpleTextUtil.write(out, SIZE);
-      SimpleTextUtil.write(out, Integer.toString(size), scratch);
-      SimpleTextUtil.writeNewline(out);
-      
-      for (int i = set.nextSetBit(0); i >= 0; i=set.nextSetBit(i + 1)) { 
-        SimpleTextUtil.write(out, DOC);
-        SimpleTextUtil.write(out, Integer.toString(i), scratch);
-        SimpleTextUtil.writeNewline(out);
-      }
-      
-      SimpleTextUtil.write(out, END);
-      SimpleTextUtil.writeNewline(out);
-      SimpleTextUtil.writeChecksum(out, scratch);
-      success = true;
-    } finally {
-      if (success) {
-        IOUtils.close(out);
-      } else {
-        IOUtils.closeWhileHandlingException(out);
-      }
-    }
-  }
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
-  @Override
-  public void files(SegmentCommitInfo info, Collection<String> files)  {
-    if (info.hasDeletions()) {
-      files.add(IndexFileNames.fileNameFromGeneration(info.info.name, LIVEDOCS_EXTENSION, info.getDelGen()));
-    }
-  }
-  
-  // read-only
-  static class SimpleTextBits implements Bits {
-    final BitSet bits;
-    final int size;
-    
-    SimpleTextBits(BitSet bits, int size) {
-      this.bits = bits;
-      this.size = size;
-    }
-    
-    @Override
-    public bool get(int index) {
-      return bits.get(index);
-    }
+namespace Lucene.Net.Codecs.SimpleText
+{
 
-    @Override
-    public int length() {
-      return size;
-    }
-  }
-  
-  // read-write
-  static class SimpleTextMutableBits extends SimpleTextBits implements MutableBits {
-
-    SimpleTextMutableBits(int size) {
-      this(new BitSet(size), size);
-      bits.set(0, size);
-    }
-    
-    SimpleTextMutableBits(BitSet bits, int size) {
-      super(bits, size);
-    }
-    
-    @Override
-    public void clear(int bit) {
-      bits.clear(bit);
+    using System;
+    using System.Diagnostics;
+    using System.Collections;
+    using System.Collections.Generic;
+    using Support;
+
+	using IndexFileNames = Index.IndexFileNames;
+	using SegmentCommitInfo = Index.SegmentCommitInfo;
+	using ChecksumIndexInput = Store.ChecksumIndexInput;
+	using Directory = Store.Directory;
+	using IOContext = Store.IOContext;
+	using IndexOutput = Store.IndexOutput;
+	using ArrayUtil = Util.ArrayUtil;
+	using Bits = Util.Bits;
+	using BytesRef = Util.BytesRef;
+	using CharsRef = Util.CharsRef;
+	using IOUtils = Util.IOUtils;
+	using MutableBits = Util.MutableBits;
+	using StringHelper = Util.StringHelper;
+	using UnicodeUtil = Util.UnicodeUtil;
+
+    /// <summary>
+    /// reads/writes plaintext live docs
+    /// <para>
+    /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+    /// @lucene.experimental
+    /// </para>
+    /// </summary>
+    public class SimpleTextLiveDocsFormat : LiveDocsFormat
+    {
+
+        internal const string LIVEDOCS_EXTENSION = "liv";
+
+        internal static readonly BytesRef SIZE = new BytesRef("size ");
+        internal static readonly BytesRef DOC = new BytesRef("  doc ");
+        internal static readonly BytesRef END = new BytesRef("END");
+
+        public override MutableBits NewLiveDocs(int size)
+        {
+            return new SimpleTextMutableBits(size);
+        }
+
+        public override MutableBits NewLiveDocs(Bits existing)
+        {
+            var bits = (SimpleTextBits) existing;
+            return new SimpleTextMutableBits((BitArray) bits.BITS.Clone(), bits.SIZE);
+        }
+
+        public override Bits ReadLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context)
+        {
+            Debug.Assert(info.HasDeletions());
+            var scratch = new BytesRef();
+            var scratchUtf16 = new CharsRef();
+
+            var fileName = IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.DelGen);
+            ChecksumIndexInput input = null;
+            var success = false;
+
+            try
+            {
+                input = dir.OpenChecksumInput(fileName, context);
+
+                SimpleTextUtil.ReadLine(input, scratch);
+                Debug.Assert(StringHelper.StartsWith(scratch, SIZE));
+                var size = ParseIntAt(scratch, SIZE.Length, scratchUtf16);
+
+                var bits = new BitArray(size);
+
+                SimpleTextUtil.ReadLine(input, scratch);
+                while (!scratch.Equals(END))
+                {
+                    Debug.Assert(StringHelper.StartsWith(scratch, DOC));
+                    var docid = ParseIntAt(scratch, DOC.Length, scratchUtf16);
+                    bits.Set(docid, true);
+                    SimpleTextUtil.ReadLine(input, scratch);
+                }
+
+                SimpleTextUtil.CheckFooter(input);
+
+                success = true;
+                return new SimpleTextBits(bits, size);
+            }
+            finally
+            {
+                if (success)
+                {
+                    IOUtils.Close(input);
+                }
+                else
+                {
+                    IOUtils.CloseWhileHandlingException(input);
+                }
+            }
+        }
+
+        private static int ParseIntAt(BytesRef bytes, int offset, CharsRef scratch)
+        {
+            UnicodeUtil.UTF8toUTF16(bytes.Bytes, bytes.Offset + offset, bytes.Length - offset, scratch);
+            return ArrayUtil.ParseInt(scratch.Chars, 0, scratch.length);
+        }
+
+        public override void WriteLiveDocs(MutableBits 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), 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), scratch);
+                    SimpleTextUtil.WriteNewline(output);
+                }
+
+                SimpleTextUtil.Write(output, END);
+                SimpleTextUtil.WriteNewline(output);
+                SimpleTextUtil.WriteChecksum(output, scratch);
+                success = true;
+            }
+            finally
+            {
+                if (success)
+                {
+                    IOUtils.Close(output);
+                }
+                else
+                {
+                    IOUtils.CloseWhileHandlingException(output);
+                }
+            }
+        }
+
+        public override void Files(SegmentCommitInfo info, ICollection<string> files)
+        {
+            if (info.HasDeletions())
+            {
+                files.Add(IndexFileNames.FileNameFromGeneration(info.Info.Name, LIVEDOCS_EXTENSION, info.DelGen));
+            }
+        }
+
+        // read-only
+        internal class SimpleTextBits : Bits
+        {
+            internal readonly BitArray BITS;
+            internal readonly int SIZE;
+
+            internal SimpleTextBits(BitArray bits, int size)
+            {
+                BITS = bits;
+                SIZE = size;
+            }
+
+            public bool Get(int index)
+            {
+                return BITS.Get(index);
+            }
+
+            public int Length()
+            {
+                return SIZE;
+            }
+        }
+
+        // read-write
+        internal class SimpleTextMutableBits : SimpleTextBits, MutableBits
+        {
+
+            internal SimpleTextMutableBits(int size) : this(new BitArray(size), size)
+            {
+                BITS.Set(0, size);
+            }
+
+            internal SimpleTextMutableBits(BitArray bits, int size) : base(bits, size)
+            {
+            }
+
+            public void Clear(int bit)
+            {
+                BITS.Set(bit, false);
+            }
+        }
     }
-  }
-}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
index 0f7c3a3..75a0ccc 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextNormsFormat.cs
@@ -1,6 +1,4 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -17,61 +15,67 @@ package org.apache.lucene.codecs.simpletext;
  * limitations under the License.
  */
 
-import java.io.IOException;
+namespace Lucene.Net.Codecs.SimpleText
+{
 
-import org.apache.lucene.codecs.DocValuesConsumer;
-import org.apache.lucene.codecs.DocValuesProducer;
-import org.apache.lucene.codecs.NormsFormat;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.SegmentWriteState;
+    using SegmentReadState = Index.SegmentReadState;
+    using SegmentWriteState = Index.SegmentWriteState;
 
-/**
- * plain-text norms format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * 
- * @lucene.experimental
- */
-public class SimpleTextNormsFormat extends NormsFormat {
-  private static final String NORMS_SEG_EXTENSION = "len";
-  
-  @Override
-  public DocValuesConsumer normsConsumer(SegmentWriteState state)  {
-    return new SimpleTextNormsConsumer(state);
-  }
-  
-  @Override
-  public DocValuesProducer normsProducer(SegmentReadState state)  {
-    return new SimpleTextNormsProducer(state);
-  }
-  
-  /**
-   * Reads plain-text norms.
-   * <p>
-   * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
-   * 
-   * @lucene.experimental
-   */
-  public static class SimpleTextNormsProducer extends SimpleTextDocValuesReader {
-    public SimpleTextNormsProducer(SegmentReadState state)  {
-      // All we do is change the extension from .dat -> .len;
-      // otherwise this is a normal simple doc values file:
-      super(state, NORMS_SEG_EXTENSION);
-    }
-  }
-  
-  /**
-   * Writes plain-text norms.
-   * <p>
-   * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
-   * 
-   * @lucene.experimental
-   */
-  public static class SimpleTextNormsConsumer extends SimpleTextDocValuesWriter {
-    public SimpleTextNormsConsumer(SegmentWriteState state)  {
-      // All we do is change the extension from .dat -> .len;
-      // otherwise this is a normal simple doc values file:
-      super(state, NORMS_SEG_EXTENSION);
+    /// <summary>
+    /// plain-text norms format.
+    /// <para>
+    /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+    /// 
+    /// @lucene.experimental
+    /// </para>
+    /// </summary>
+    public class SimpleTextNormsFormat : NormsFormat
+    {
+        private const string NORMS_SEG_EXTENSION = "len";
+
+        public override DocValuesConsumer NormsConsumer(SegmentWriteState state)
+        {
+            return new SimpleTextNormsConsumer(state);
+        }
+
+        public override DocValuesProducer NormsProducer(SegmentReadState state)
+        {
+            return new SimpleTextNormsProducer(state);
+        }
+
+        /// <summary>
+        /// Reads plain-text norms.
+        /// <para>
+        /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+        /// 
+        /// @lucene.experimental
+        /// </para>
+        /// </summary>
+        public class SimpleTextNormsProducer : SimpleTextDocValuesReader
+        {
+            public SimpleTextNormsProducer(SegmentReadState state) : base(state, NORMS_SEG_EXTENSION)
+            {
+                // All we do is change the extension from .dat -> .len;
+                // otherwise this is a normal simple doc values file:
+            }
+        }
+
+        /// <summary>
+        /// Writes plain-text norms.
+        /// <para>
+        /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+        /// 
+        /// @lucene.experimental
+        /// </para>
+        /// </summary>
+        public class SimpleTextNormsConsumer : SimpleTextDocValuesWriter
+        {
+            public SimpleTextNormsConsumer(SegmentWriteState state) : base(state, NORMS_SEG_EXTENSION)
+            {
+                // All we do is change the extension from .dat -> .len;
+                // otherwise this is a normal simple doc values file:
+            }
+        }
     }
-  }
-}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
index 5e2c782..0027065 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextPostingsFormat.cs
@@ -1,6 +1,4 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -17,43 +15,49 @@ package org.apache.lucene.codecs.simpletext;
  * limitations under the License.
  */
 
-import java.io.IOException;
-
-import org.apache.lucene.codecs.FieldsConsumer;
-import org.apache.lucene.codecs.FieldsProducer;
-import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.index.SegmentReadState;
-import org.apache.lucene.index.IndexFileNames;
-
-/** For debugging, curiosity, transparency only!!  Do not
- *  use this codec in production.
- *
- *  <p>This codec stores all postings data in a single
- *  human-readable text file (_N.pst).  You can view this in
- *  any text editor, and even edit it to alter your index.
- *
- *  @lucene.experimental */
-public final class SimpleTextPostingsFormat extends PostingsFormat {
-  
-  public SimpleTextPostingsFormat() {
-    super("SimpleText");
-  }
-
-  @Override
-  public FieldsConsumer fieldsConsumer(SegmentWriteState state)  {
-    return new SimpleTextFieldsWriter(state);
-  }
-
-  @Override
-  public FieldsProducer fieldsProducer(SegmentReadState state)  {
-    return new SimpleTextFieldsReader(state);
-  }
-
-  /** Extension of freq postings file */
-  static final String POSTINGS_EXTENSION = "pst";
-
-  static String getPostingsFileName(String segment, String segmentSuffix) {
-    return IndexFileNames.segmentFileName(segment, segmentSuffix, POSTINGS_EXTENSION);
-  }
-}
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+	using SegmentWriteState = Index.SegmentWriteState;
+	using SegmentReadState = Index.SegmentReadState;
+	using IndexFileNames = Index.IndexFileNames;
+
+    /// <summary>
+    /// For debugging, curiosity, transparency only!!  Do not
+    ///  use this codec in production.
+    /// 
+    ///  <para>This codec stores all postings data in a single
+    ///  human-readable text file (_N.pst).  You can view this in
+    ///  any text editor, and even edit it to alter your index.
+    /// 
+    ///  @lucene.experimental 
+    /// </para>
+    /// </summary>
+    public sealed class SimpleTextPostingsFormat : PostingsFormat
+    {
+
+        /// <summary>
+        /// Extension of freq postings file </summary>
+        internal const string POSTINGS_EXTENSION = "pst";
+
+        public SimpleTextPostingsFormat() : base("SimpleText")
+        {
+        }
+
+        public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
+        {
+            return new SimpleTextFieldsWriter(state);
+        }
+
+        public override FieldsProducer FieldsProducer(SegmentReadState state)
+        {
+            return new SimpleTextFieldsReader(state);
+        }
+
+        internal static string GetPostingsFileName(string segment, string segmentSuffix)
+        {
+            return IndexFileNames.SegmentFileName(segment, segmentSuffix, POSTINGS_EXTENSION);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
index 53440e7..11c4940 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoFormat.cs
@@ -1,6 +1,4 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -17,29 +15,33 @@ package org.apache.lucene.codecs.simpletext;
  * limitations under the License.
  */
 
-import org.apache.lucene.codecs.SegmentInfoFormat;
-import org.apache.lucene.codecs.SegmentInfoReader;
-import org.apache.lucene.codecs.SegmentInfoWriter;
+namespace Lucene.Net.Codecs.SimpleText
+{
 
-/**
- * plain text segments file format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {
-  private final SegmentInfoReader reader = new SimpleTextSegmentInfoReader();
-  private final SegmentInfoWriter writer = new SimpleTextSegmentInfoWriter();
+	/// <summary>
+	/// plain text segments file format.
+	/// <para>
+	/// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+	/// @lucene.experimental
+	/// </para>
+	/// </summary>
+	public class SimpleTextSegmentInfoFormat : SegmentInfoFormat
+	{
+	  private readonly SegmentInfoReader _reader = new SimpleTextSegmentInfoReader();
+	  private readonly SegmentInfoWriter _writer = new SimpleTextSegmentInfoWriter();
+
+	  public const string SI_EXTENSION = "si";
+
+	  public override SegmentInfoReader SegmentInfoReader
+	  {
+	      get { return _reader; }
+	  }
+
+	  public override SegmentInfoWriter SegmentInfoWriter
+	  {
+	      get { return _writer; }
+	  }
 
-  public static final String SI_EXTENSION = "si";
-  
-  @Override
-  public SegmentInfoReader getSegmentInfoReader() {
-    return reader;
-  }
+	}
 
-  @Override
-  public SegmentInfoWriter getSegmentInfoWriter() {
-    return writer;
-  }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
index cd87509..f67b9b2 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoReader.cs
@@ -1,6 +1,4 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -17,104 +15,125 @@ package org.apache.lucene.codecs.simpletext;
  * limitations under the License.
  */
 
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DIAG_KEY;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DIAG_VALUE;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_DOCCOUNT;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_FILE;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_NUM_DIAG;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_NUM_FILES;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_USECOMPOUND;
-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_VERSION;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.lucene.codecs.SegmentInfoReader;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.StringHelper;
-
-/**
- * reads plaintext segments files
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextSegmentInfoReader extends SegmentInfoReader {
-
-  @Override
-  public SegmentInfo read(Directory directory, String segmentName, IOContext context)  {
-    BytesRef scratch = new BytesRef();
-    String segFileName = IndexFileNames.segmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);
-    ChecksumIndexInput input = directory.openChecksumInput(segFileName, context);
-    bool success = false;
-    try {
-      SimpleTextUtil.readLine(input, scratch);
-      Debug.Assert( StringHelper.startsWith(scratch, SI_VERSION);
-      final String version = readString(SI_VERSION.length, scratch);
-    
-      SimpleTextUtil.readLine(input, scratch);
-      Debug.Assert( StringHelper.startsWith(scratch, SI_DOCCOUNT);
-      final int docCount = Integer.parseInt(readString(SI_DOCCOUNT.length, scratch));
-    
-      SimpleTextUtil.readLine(input, scratch);
-      Debug.Assert( StringHelper.startsWith(scratch, SI_USECOMPOUND);
-      final bool isCompoundFile = bool.parsebool(readString(SI_USECOMPOUND.length, scratch));
-    
-      SimpleTextUtil.readLine(input, scratch);
-      Debug.Assert( StringHelper.startsWith(scratch, SI_NUM_DIAG);
-      int numDiag = Integer.parseInt(readString(SI_NUM_DIAG.length, scratch));
-      Map<String,String> diagnostics = new HashMap<>();
-
-      for (int i = 0; i < numDiag; i++) {
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, SI_DIAG_KEY);
-        String key = readString(SI_DIAG_KEY.length, scratch);
-      
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, SI_DIAG_VALUE);
-        String value = readString(SI_DIAG_VALUE.length, scratch);
-        diagnostics.put(key, value);
-      }
-      
-      SimpleTextUtil.readLine(input, scratch);
-      Debug.Assert( StringHelper.startsWith(scratch, SI_NUM_FILES);
-      int numFiles = Integer.parseInt(readString(SI_NUM_FILES.length, scratch));
-      Set<String> files = new HashSet<>();
-
-      for (int i = 0; i < numFiles; i++) {
-        SimpleTextUtil.readLine(input, scratch);
-        Debug.Assert( StringHelper.startsWith(scratch, SI_FILE);
-        String fileName = readString(SI_FILE.length, scratch);
-        files.add(fileName);
-      }
-      
-      SimpleTextUtil.checkFooter(input);
-
-      SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount, 
-                                         isCompoundFile, null, diagnostics);
-      info.setFiles(files);
-      success = true;
-      return info;
-    } finally {
-      if (!success) {
-        IOUtils.closeWhileHandlingException(input);
-      } else {
-        input.close();
-      }
-    }
-  }
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_DIAG_KEY;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_DIAG_VALUE;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_DOCCOUNT;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_FILE;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_NUM_DIAG;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_NUM_FILES;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_USECOMPOUND;
+////JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+//    import static Lucene.Net.Codecs.SimpleText.SimpleTextSegmentInfoWriter.SI_VERSION;
+
+
+    using System;
+    using System.Diagnostics;
+    using System.Collections.Generic;
+
+    using IndexFileNames = Index.IndexFileNames;
+    using SegmentInfo = Index.SegmentInfo;
+    using ChecksumIndexInput = Store.ChecksumIndexInput;
+    using Directory = Store.Directory;
+    using IOContext = Store.IOContext;
+    using BytesRef = Util.BytesRef;
+    using IOUtils = Util.IOUtils;
+    using StringHelper = Util.StringHelper;
+
+    /// <summary>
+    /// reads plaintext segments files
+    /// <para>
+    /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+    /// @lucene.experimental
+    /// </para>
+    /// </summary>
+    public class SimpleTextSegmentInfoReader : SegmentInfoReader
+    {
+
+        public override SegmentInfo Read(Directory directory, string segmentName, IOContext context)
+        {
+            BytesRef scratch = new BytesRef();
+            string segFileName = IndexFileNames.SegmentFileName(segmentName, "",
+                SimpleTextSegmentInfoFormat.SI_EXTENSION);
+            ChecksumIndexInput input = directory.OpenChecksumInput(segFileName, context);
+            bool success = false;
+            try
+            {
+                SimpleTextUtil.ReadLine(input, scratch);
+                Debug.Assert(StringHelper.StartsWith(scratch, SI_VERSION));
+                string version = ReadString(SI_VERSION.length, scratch);
+
+                SimpleTextUtil.ReadLine(input, scratch);
+                Debug.Assert(StringHelper.StartsWith(scratch, SI_DOCCOUNT));
+                int docCount = Convert.ToInt32(ReadString(SI_DOCCOUNT.length, scratch));
 
-  private String readString(int offset, BytesRef scratch) {
-    return new String(scratch.bytes, scratch.offset+offset, scratch.length-offset, StandardCharsets.UTF_8);
-  }
-}
+                SimpleTextUtil.ReadLine(input, scratch);
+                Debug.Assert(StringHelper.StartsWith(scratch, SI_USECOMPOUND));
+                bool isCompoundFile = Convert.ToBoolean(ReadString(SI_USECOMPOUND.length, scratch));
+
+                SimpleTextUtil.ReadLine(input, scratch);
+                Debug.Assert(StringHelper.StartsWith(scratch, SI_NUM_DIAG));
+                int numDiag = Convert.ToInt32(ReadString(SI_NUM_DIAG.length, scratch));
+                IDictionary<string, string> diagnostics = new Dictionary<string, string>();
+
+                for (int i = 0; i < numDiag; i++)
+                {
+                    SimpleTextUtil.ReadLine(input, scratch);
+                    Debug.Assert(StringHelper.StartsWith(scratch, SI_DIAG_KEY));
+                    string key = ReadString(SI_DIAG_KEY.length, scratch);
+
+                    SimpleTextUtil.ReadLine(input, scratch);
+                    Debug.Assert(StringHelper.StartsWith(scratch, SI_DIAG_VALUE));
+                    string value = ReadString(SI_DIAG_VALUE.length, scratch);
+                    diagnostics[key] = value;
+                }
+
+                SimpleTextUtil.ReadLine(input, scratch);
+                Debug.Assert(StringHelper.StartsWith(scratch, SI_NUM_FILES));
+                int numFiles = Convert.ToInt32(ReadString(SI_NUM_FILES.length, scratch));
+                HashSet<string> files = new HashSet<string>();
+
+                for (int i = 0; i < numFiles; i++)
+                {
+                    SimpleTextUtil.ReadLine(input, scratch);
+                    Debug.Assert(StringHelper.StartsWith(scratch, SI_FILE));
+                    string fileName = ReadString(SI_FILE.length, scratch);
+                    files.Add(fileName);
+                }
+
+                SimpleTextUtil.CheckFooter(input);
+
+                SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount, isCompoundFile, null,
+                    diagnostics);
+                info.Files = files;
+                success = true;
+                return info;
+            }
+            finally
+            {
+                if (!success)
+                {
+                    IOUtils.CloseWhileHandlingException(input);
+                }
+                else
+                {
+                    input.Close();
+                }
+            }
+        }
+
+        private string ReadString(int offset, BytesRef scratch)
+        {
+            return new string(scratch.Bytes, scratch.Offset + offset, scratch.Length - offset, StandardCharsets.UTF_8);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
index e32f001..808c9c3 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextSegmentInfoWriter.cs
@@ -1,121 +1,140 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.lucene.codecs.SegmentInfoWriter;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.IOUtils;
-
-/**
- * writes plaintext segments files
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextSegmentInfoWriter extends SegmentInfoWriter {
-
-  final static BytesRef SI_VERSION          = new BytesRef("    version ");
-  final static BytesRef SI_DOCCOUNT         = new BytesRef("    number of documents ");
-  final static BytesRef SI_USECOMPOUND      = new BytesRef("    uses compound file ");
-  final static BytesRef SI_NUM_DIAG         = new BytesRef("    diagnostics ");
-  final static BytesRef SI_DIAG_KEY         = new BytesRef("      key ");
-  final static BytesRef SI_DIAG_VALUE       = new BytesRef("      value ");
-  final static BytesRef SI_NUM_FILES        = new BytesRef("    files ");
-  final static BytesRef SI_FILE             = new BytesRef("      file ");
-  
-  @Override
-  public 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.getVersion(), scratch);
-      SimpleTextUtil.writeNewline(output);
-    
-      SimpleTextUtil.write(output, SI_DOCCOUNT);
-      SimpleTextUtil.write(output, Integer.toString(si.getDocCount()), scratch);
-      SimpleTextUtil.writeNewline(output);
-    
-      SimpleTextUtil.write(output, SI_USECOMPOUND);
-      SimpleTextUtil.write(output, bool.toString(si.getUseCompoundFile()), scratch);
-      SimpleTextUtil.writeNewline(output);
-    
-      Map<String,String> diagnostics = si.getDiagnostics();
-      int numDiagnostics = diagnostics == null ? 0 : diagnostics.size();
-      SimpleTextUtil.write(output, SI_NUM_DIAG);
-      SimpleTextUtil.write(output, Integer.toString(numDiagnostics), scratch);
-      SimpleTextUtil.writeNewline(output);
-    
-      if (numDiagnostics > 0) {
-        for (Map.Entry<String,String> diagEntry : diagnostics.entrySet()) {
-          SimpleTextUtil.write(output, SI_DIAG_KEY);
-          SimpleTextUtil.write(output, diagEntry.getKey(), scratch);
-          SimpleTextUtil.writeNewline(output);
-        
-          SimpleTextUtil.write(output, SI_DIAG_VALUE);
-          SimpleTextUtil.write(output, diagEntry.getValue(), scratch);
-          SimpleTextUtil.writeNewline(output);
-        }
-      }
-      
-      Set<String> files = si.files();
-      int numFiles = files == null ? 0 : files.size();
-      SimpleTextUtil.write(output, SI_NUM_FILES);
-      SimpleTextUtil.write(output, Integer.toString(numFiles), scratch);
-      SimpleTextUtil.writeNewline(output);
-
-      if (numFiles > 0) {
-        for(String fileName : 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 (Throwable t) {
-        }
-      } else {
-        output.close();
-      }
-    }
-  }
-}
+using System;
+using System.Collections.Generic;
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+	/*
+	 * Licensed to the Apache Software Foundation (ASF) under one or more
+	 * contributor license agreements.  See the NOTICE file distributed with
+	 * this work for additional information regarding copyright ownership.
+	 * The ASF licenses this file to You under the Apache License, Version 2.0
+	 * (the "License"); you may not use this file except in compliance with
+	 * the License.  You may obtain a copy of the License at
+	 *
+	 *     http://www.apache.org/licenses/LICENSE-2.0
+	 *
+	 * Unless required by applicable law or agreed to in writing, software
+	 * distributed under the License is distributed on an "AS IS" BASIS,
+	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	 * See the License for the specific language governing permissions and
+	 * limitations under the License.
+	 */
+
+
+	using FieldInfos = index.FieldInfos;
+	using IndexFileNames = index.IndexFileNames;
+	using SegmentInfo = index.SegmentInfo;
+	using Directory = store.Directory;
+	using IOContext = store.IOContext;
+	using IndexOutput = store.IndexOutput;
+	using BytesRef = util.BytesRef;
+	using IOUtils = util.IOUtils;
+
+	/// <summary>
+	/// writes plaintext segments files
+	/// <para>
+	/// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+	/// @lucene.experimental
+	/// </para>
+	/// </summary>
+	public class SimpleTextSegmentInfoWriter : SegmentInfoWriter
+	{
+
+	  internal static readonly BytesRef SI_VERSION = new BytesRef("    version ");
+	  internal static readonly BytesRef SI_DOCCOUNT = new BytesRef("    number of documents ");
+	  internal static readonly BytesRef SI_USECOMPOUND = new BytesRef("    uses compound file ");
+	  internal static readonly BytesRef SI_NUM_DIAG = new BytesRef("    diagnostics ");
+	  internal static readonly BytesRef SI_DIAG_KEY = new BytesRef("      key ");
+	  internal static readonly BytesRef SI_DIAG_VALUE = new BytesRef("      value ");
+	  internal static readonly BytesRef SI_NUM_FILES = new BytesRef("    files ");
+	  internal static readonly BytesRef SI_FILE = new BytesRef("      file ");
+
+//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();
+		  }
+		}
+	  }
+	}
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
index 2af7ad9..ffe698f 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsFormat.cs
@@ -1,6 +1,4 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -17,31 +15,33 @@ package org.apache.lucene.codecs.simpletext;
  * limitations under the License.
  */
 
-import java.io.IOException;
+namespace Lucene.Net.Codecs.SimpleText
+{
 
-import org.apache.lucene.codecs.StoredFieldsFormat;
-import org.apache.lucene.codecs.StoredFieldsReader;
-import org.apache.lucene.codecs.StoredFieldsWriter;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
+    using FieldInfos = Index.FieldInfos;
+    using SegmentInfo = Index.SegmentInfo;
+    using Directory = Store.Directory;
+    using IOContext = Store.IOContext;
 
-/**
- * plain text stored fields format.
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextStoredFieldsFormat extends StoredFieldsFormat {
+    /// <summary>
+    /// plain text stored fields format.
+    /// <para>
+    /// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+    /// @lucene.experimental
+    /// </para>
+    /// </summary>
+    public class SimpleTextStoredFieldsFormat : StoredFieldsFormat
+    {
 
-  @Override
-  public StoredFieldsReader fieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context)  {;
-    return new SimpleTextStoredFieldsReader(directory, si, fn, context);
-  }
+        public override StoredFieldsReader FieldsReader(Directory directory, SegmentInfo si, FieldInfos fn,
+            IOContext context)
+        {
+            return new SimpleTextStoredFieldsReader(directory, si, fn, context);
+        }
 
-  @Override
-  public StoredFieldsWriter fieldsWriter(Directory directory, SegmentInfo si, IOContext context)  {
-    return new SimpleTextStoredFieldsWriter(directory, si.name, context);
-  }
-}
+        public override StoredFieldsWriter FieldsWriter(Directory directory, SegmentInfo si, IOContext context)
+        {
+            return new SimpleTextStoredFieldsWriter(directory, si.Name, context);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/cf1df6be/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
index 7405838..6f2c9ea 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextStoredFieldsReader.cs
@@ -1,208 +1,277 @@
-package org.apache.lucene.codecs.simpletext;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import org.apache.lucene.codecs.StoredFieldsReader;
-import org.apache.lucene.index.FieldInfo;
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.IndexFileNames;
-import org.apache.lucene.index.SegmentInfo;
-import org.apache.lucene.index.StoredFieldVisitor;
-import org.apache.lucene.store.AlreadyClosedException;
-import org.apache.lucene.store.BufferedChecksumIndexInput;
-import org.apache.lucene.store.ChecksumIndexInput;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.util.UnicodeUtil;
-
-import static org.apache.lucene.codecs.simpletext.SimpleTextStoredFieldsWriter.*;
-
-/**
- * reads plaintext stored fields
- * <p>
- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
- * @lucene.experimental
- */
-public class SimpleTextStoredFieldsReader extends StoredFieldsReader {
-  private long offsets[]; /* docid -> offset in .fld file */
-  private IndexInput in;
-  private BytesRef scratch = new BytesRef();
-  private CharsRef scratchUTF16 = new CharsRef();
-  private final FieldInfos fieldInfos;
-
-  public SimpleTextStoredFieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context)  {
-    this.fieldInfos = fn;
-    bool success = false;
-    try {
-      in = directory.openInput(IndexFileNames.segmentFileName(si.name, "", SimpleTextStoredFieldsWriter.FIELDS_EXTENSION), context);
-      success = true;
-    } finally {
-      if (!success) {
-        try {
-          close();
-        } catch (Throwable t) {} // ensure we throw our original exception
-      }
-    }
-    readIndex(si.getDocCount());
-  }
-  
-  // used by clone
-  SimpleTextStoredFieldsReader(long offsets[], IndexInput in, FieldInfos fieldInfos) {
-    this.offsets = offsets;
-    this.in = in;
-    this.fieldInfos = fieldInfos;
-  }
-  
-  // we don't actually write a .fdx-like index, instead we read the 
-  // stored fields file in entirety up-front and save the offsets 
-  // so we can seek to the documents later.
-  private void readIndex(int size)  {
-    ChecksumIndexInput input = new BufferedChecksumIndexInput(in);
-    offsets = new long[size];
-    int upto = 0;
-    while (!scratch.equals(END)) {
-      SimpleTextUtil.readLine(input, scratch);
-      if (StringHelper.startsWith(scratch, DOC)) {
-        offsets[upto] = input.getFilePointer();
-        upto++;
-      }
-    }
-    SimpleTextUtil.checkFooter(input);
-    Debug.Assert( upto == offsets.length;
-  }
-  
-  @Override
-  public void visitDocument(int n, StoredFieldVisitor visitor)  {
-    in.seek(offsets[n]);
-    readLine();
-    Debug.Assert( StringHelper.startsWith(scratch, NUM);
-    int numFields = parseIntAt(NUM.length);
-    
-    for (int i = 0; i < numFields; i++) {
-      readLine();
-      Debug.Assert( StringHelper.startsWith(scratch, FIELD);
-      int fieldNumber = parseIntAt(FIELD.length);
-      FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldNumber);
-      readLine();
-      Debug.Assert( StringHelper.startsWith(scratch, NAME);
-      readLine();
-      Debug.Assert( StringHelper.startsWith(scratch, TYPE);
-      
-      final BytesRef type;
-      if (equalsAt(TYPE_STRING, scratch, TYPE.length)) {
-        type = TYPE_STRING;
-      } else if (equalsAt(TYPE_BINARY, scratch, TYPE.length)) {
-        type = TYPE_BINARY;
-      } else if (equalsAt(TYPE_INT, scratch, TYPE.length)) {
-        type = TYPE_INT;
-      } else if (equalsAt(TYPE_LONG, scratch, TYPE.length)) {
-        type = TYPE_LONG;
-      } else if (equalsAt(TYPE_FLOAT, scratch, TYPE.length)) {
-        type = TYPE_FLOAT;
-      } else if (equalsAt(TYPE_DOUBLE, scratch, TYPE.length)) {
-        type = TYPE_DOUBLE;
-      } else {
-        throw new RuntimeException("unknown field type");
-      }
-      
-      switch (visitor.needsField(fieldInfo)) {
-        case YES:  
-          readField(type, fieldInfo, visitor);
-          break;
-        case NO:   
-          readLine();
-          Debug.Assert( StringHelper.startsWith(scratch, VALUE);
-          break;
-        case STOP: return;
-      }
-    }
-  }
-  
-  private void readField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor)  {
-    readLine();
-    Debug.Assert( StringHelper.startsWith(scratch, VALUE);
-    if (type == TYPE_STRING) {
-      visitor.stringField(fieldInfo, new String(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, StandardCharsets.UTF_8));
-    } else if (type == TYPE_BINARY) {
-      byte[] copy = new byte[scratch.length-VALUE.length];
-      System.arraycopy(scratch.bytes, scratch.offset+VALUE.length, copy, 0, copy.length);
-      visitor.binaryField(fieldInfo, copy);
-    } else if (type == TYPE_INT) {
-      UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
-      visitor.intField(fieldInfo, Integer.parseInt(scratchUTF16.toString()));
-    } else if (type == TYPE_LONG) {
-      UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
-      visitor.longField(fieldInfo, Long.parseLong(scratchUTF16.toString()));
-    } else if (type == TYPE_FLOAT) {
-      UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
-      visitor.floatField(fieldInfo, Float.parseFloat(scratchUTF16.toString()));
-    } else if (type == TYPE_DOUBLE) {
-      UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+VALUE.length, scratch.length-VALUE.length, scratchUTF16);
-      visitor.doubleField(fieldInfo, Double.parseDouble(scratchUTF16.toString()));
-    }
-  }
-
-  @Override
-  public StoredFieldsReader clone() {
-    if (in == null) {
-      throw new AlreadyClosedException("this FieldsReader is closed");
-    }
-    return new SimpleTextStoredFieldsReader(offsets, in.clone(), fieldInfos);
-  }
-  
-  @Override
-  public void close()  {
-    try {
-      IOUtils.close(in); 
-    } finally {
-      in = null;
-      offsets = null;
-    }
-  }
-  
-  private void readLine()  {
-    SimpleTextUtil.readLine(in, scratch);
-  }
-  
-  private int parseIntAt(int offset) {
-    UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset+offset, scratch.length-offset, scratchUTF16);
-    return ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
-  }
-  
-  private bool equalsAt(BytesRef a, BytesRef b, int bOffset) {
-    return a.length == b.length - bOffset && 
-        ArrayUtil.equals(a.bytes, a.offset, b.bytes, b.offset + bOffset, b.length - bOffset);
-  }
-
-  @Override
-  public long ramBytesUsed() {
-    return 0;
-  }
-
-  @Override
-  public void checkIntegrity()  {}
-}
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+namespace Lucene.Net.Codecs.SimpleText
+{
+
+    using System;
+    using System.Diagnostics;
+
+	using FieldInfo = Index.FieldInfo;
+	using FieldInfos = Index.FieldInfos;
+	using IndexFileNames = Index.IndexFileNames;
+	using SegmentInfo = Index.SegmentInfo;
+	using StoredFieldVisitor = Index.StoredFieldVisitor;
+	using AlreadyClosedException = Store.AlreadyClosedException;
+	using BufferedChecksumIndexInput = Store.BufferedChecksumIndexInput;
+	using ChecksumIndexInput = Store.ChecksumIndexInput;
+	using Directory = Store.Directory;
+	using IOContext = Store.IOContext;
+	using IndexInput = Store.IndexInput;
+	using ArrayUtil = Util.ArrayUtil;
+	using BytesRef = Util.BytesRef;
+	using CharsRef = Util.CharsRef;
+	using IOUtils = Util.IOUtils;
+	using StringHelper = Util.StringHelper;
+	using UnicodeUtil = Util.UnicodeUtil;
+
+//JAVA TO C# CONVERTER TODO TASK: This Java 'import static' statement cannot be converted to .NET:
+	import static Lucene.Net.Codecs.SimpleText.SimpleTextStoredFieldsWriter.*;
+
+	/// <summary>
+	/// reads plaintext stored fields
+	/// <para>
+	/// <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>
+	/// @lucene.experimental
+	/// </para>
+	/// </summary>
+	public class SimpleTextStoredFieldsReader : StoredFieldsReader
+	{
+	  private long[] offsets; // docid -> offset in .fld file
+	  private IndexInput @in;
+	  private BytesRef scratch = new BytesRef();
+	  private CharsRef scratchUTF16 = new CharsRef();
+	  private readonly FieldInfos fieldInfos;
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: public SimpleTextStoredFieldsReader(store.Directory directory, index.SegmentInfo si, index.FieldInfos fn, store.IOContext context) throws java.io.IOException
+	  public SimpleTextStoredFieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context)
+	  {
+		this.fieldInfos = fn;
+		bool success = false;
+		try
+		{
+		  @in = directory.openInput(IndexFileNames.segmentFileName(si.name, "", SimpleTextStoredFieldsWriter.FIELDS_EXTENSION), context);
+		  success = true;
+		}
+		finally
+		{
+		  if (!success)
+		  {
+			try
+			{
+			  close();
+			} // ensure we throw our original exception
+			catch (Exception)
+			{
+			}
+		  }
+		}
+		readIndex(si.DocCount);
+	  }
+
+	  // used by clone
+	  internal SimpleTextStoredFieldsReader(long[] offsets, IndexInput @in, FieldInfos fieldInfos)
+	  {
+		this.offsets = offsets;
+		this.@in = @in;
+		this.fieldInfos = fieldInfos;
+	  }
+
+	  // we don't actually write a .fdx-like index, instead we read the 
+	  // stored fields file in entirety up-front and save the offsets 
+	  // so we can seek to the documents later.
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readIndex(int size) throws java.io.IOException
+	  private void readIndex(int size)
+	  {
+		ChecksumIndexInput input = new BufferedChecksumIndexInput(@in);
+		offsets = new long[size];
+		int upto = 0;
+		while (!scratch.Equals(END))
+		{
+		  SimpleTextUtil.ReadLine(input, scratch);
+		  if (StringHelper.StartsWith(scratch, DOC))
+		  {
+			offsets[upto] = input.FilePointer;
+			upto++;
+		  }
+		}
+		SimpleTextUtil.CheckFooter(input);
+		Debug.Assert(upto == offsets.Length);
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void visitDocument(int n, index.StoredFieldVisitor visitor) throws java.io.IOException
+	  public override void visitDocument(int n, StoredFieldVisitor visitor)
+	  {
+		@in.seek(offsets[n]);
+		readLine();
+		Debug.Assert(StringHelper.StartsWith(scratch, NUM));
+		int numFields = parseIntAt(NUM.length);
+
+		for (int i = 0; i < numFields; i++)
+		{
+		  readLine();
+		  Debug.Assert(StringHelper.StartsWith(scratch, FIELD));
+		  int fieldNumber = parseIntAt(FIELD.length);
+		  FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldNumber);
+		  readLine();
+		  Debug.Assert(StringHelper.StartsWith(scratch, NAME));
+		  readLine();
+		  Debug.Assert(StringHelper.StartsWith(scratch, TYPE));
+
+//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+//ORIGINAL LINE: final util.BytesRef type;
+		  BytesRef type;
+		  if (equalsAt(TYPE_STRING, scratch, TYPE.length))
+		  {
+			type = TYPE_STRING;
+		  }
+		  else if (equalsAt(TYPE_BINARY, scratch, TYPE.length))
+		  {
+			type = TYPE_BINARY;
+		  }
+		  else if (equalsAt(TYPE_INT, scratch, TYPE.length))
+		  {
+			type = TYPE_INT;
+		  }
+		  else if (equalsAt(TYPE_LONG, scratch, TYPE.length))
+		  {
+			type = TYPE_LONG;
+		  }
+		  else if (equalsAt(TYPE_FLOAT, scratch, TYPE.length))
+		  {
+			type = TYPE_FLOAT;
+		  }
+		  else if (equalsAt(TYPE_DOUBLE, scratch, TYPE.length))
+		  {
+			type = TYPE_DOUBLE;
+		  }
+		  else
+		  {
+			throw new Exception("unknown field type");
+		  }
+
+		  switch (visitor.needsField(fieldInfo))
+		  {
+			case YES:
+			  readField(type, fieldInfo, visitor);
+			  break;
+			case NO:
+			  readLine();
+			  Debug.Assert(StringHelper.StartsWith(scratch, VALUE));
+			  break;
+			case STOP:
+				return;
+		  }
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readField(util.BytesRef type, index.FieldInfo fieldInfo, index.StoredFieldVisitor visitor) throws java.io.IOException
+	  private void readField(BytesRef type, FieldInfo fieldInfo, StoredFieldVisitor visitor)
+	  {
+		readLine();
+		Debug.Assert(StringHelper.StartsWith(scratch, VALUE));
+		if (type == TYPE_STRING)
+		{
+		  visitor.stringField(fieldInfo, new string(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, StandardCharsets.UTF_8));
+		}
+		else if (type == TYPE_BINARY)
+		{
+		  sbyte[] copy = new sbyte[scratch.length - VALUE.length];
+		  Array.Copy(scratch.bytes, scratch.offset + VALUE.length, copy, 0, copy.Length);
+		  visitor.binaryField(fieldInfo, copy);
+		}
+		else if (type == TYPE_INT)
+		{
+		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+		  visitor.intField(fieldInfo, Convert.ToInt32(scratchUTF16.ToString()));
+		}
+		else if (type == TYPE_LONG)
+		{
+		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+		  visitor.longField(fieldInfo, Convert.ToInt64(scratchUTF16.ToString()));
+		}
+		else if (type == TYPE_FLOAT)
+		{
+		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+		  visitor.floatField(fieldInfo, Convert.ToSingle(scratchUTF16.ToString()));
+		}
+		else if (type == TYPE_DOUBLE)
+		{
+		  UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + VALUE.length, scratch.length - VALUE.length, scratchUTF16);
+		  visitor.doubleField(fieldInfo, Convert.ToDouble(scratchUTF16.ToString()));
+		}
+	  }
+
+	  public override StoredFieldsReader clone()
+	  {
+		if (@in == null)
+		{
+		  throw new AlreadyClosedException("this FieldsReader is closed");
+		}
+		return new SimpleTextStoredFieldsReader(offsets, @in.clone(), fieldInfos);
+	  }
+
+//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()
+	  {
+		try
+		{
+		  IOUtils.close(@in);
+		}
+		finally
+		{
+		  @in = null;
+		  offsets = null;
+		}
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: private void readLine() throws java.io.IOException
+	  private void readLine()
+	  {
+		SimpleTextUtil.ReadLine(@in, scratch);
+	  }
+
+	  private int parseIntAt(int offset)
+	  {
+		UnicodeUtil.UTF8toUTF16(scratch.bytes, scratch.offset + offset, scratch.length - offset, scratchUTF16);
+		return ArrayUtil.parseInt(scratchUTF16.chars, 0, scratchUTF16.length);
+	  }
+
+	  private bool equalsAt(BytesRef a, BytesRef b, int bOffset)
+	  {
+		return a.length == b.length - bOffset && ArrayUtil.Equals(a.bytes, a.offset, b.bytes, b.offset + bOffset, b.length - bOffset);
+	  }
+
+	  public override long ramBytesUsed()
+	  {
+		return 0;
+	  }
+
+//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+//ORIGINAL LINE: @Override public void checkIntegrity() throws java.io.IOException
+	  public override void checkIntegrity()
+	  {
+	  }
+	}
+
+}
\ No newline at end of file


Mime
View raw message