Apache Lucene open-source search software
LUCENE-5998: Remove unnecessary infos abstractions
Robert Muirf82e41df81a1
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 913800b7fcc..8f064ed4d38 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -153,6 +153,9 @@ API Changes* LUCENE-5992: Remove FieldInfos from SegmentInfosWriter.write API. (Robert Muir, Mike McCandless)+* LUCENE-5998: Simplify Field/SegmentInfoFormat to read+write methods.+ (Robert Muir)+Bug Fixes* LUCENE-5650: Enforce read-only access to any path outside the temporarydiff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesFormat.javaindex 34609b3a614..3af4395b63e 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesFormat.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesFormat.java@@ -51,7 +51,7 @@ public class Lucene40DocValuesFormat extends DocValuesFormat {String filename = IndexFileNames.segmentFileName(state.segmentInfo.name,"dv",Lucene40CompoundFormat.COMPOUND_FILE_EXTENSION);- return new Lucene40DocValuesReader(state, filename, Lucene40FieldInfosReader.LEGACY_DV_TYPE_KEY);+ return new Lucene40DocValuesReader(state, filename, Lucene40FieldInfosFormat.LEGACY_DV_TYPE_KEY);}// constants for VAR_INTSdiff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesReader.javaindex 2073ed8454f..25841572cf5 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesReader.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40DocValuesReader.java@@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicLong;import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.DocValuesProducer;-import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosReader.LegacyDocValuesType;+import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosFormat.LegacyDocValuesType;import org.apache.lucene.index.BinaryDocValues;import org.apache.lucene.index.CorruptIndexException;import org.apache.lucene.index.FieldInfo;diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.javaindex 93360bb9f87..f4a1e326469 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java@@ -18,10 +18,22 @@ package org.apache.lucene.codecs.lucene40;*/import java.io.IOException;+import java.util.Collections;+import java.util.Map;+import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.codecs.FieldInfosWriter;+import org.apache.lucene.index.CorruptIndexException;+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.FieldInfo.DocValuesType;+import org.apache.lucene.index.FieldInfo.IndexOptions;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.IndexInput;+import org.apache.lucene.util.IOUtils;/*** Lucene 4.0 Field Infos format.@@ -29,22 +41,119 @@ import org.apache.lucene.codecs.FieldInfosWriter;*/@Deprecatedpublic class Lucene40FieldInfosFormat extends FieldInfosFormat {- private final FieldInfosReader reader = new Lucene40FieldInfosReader();/** Sole constructor. */public Lucene40FieldInfosFormat() {}@Override- public final FieldInfosReader getFieldInfosReader() throws IOException {- return reader;- }+ public final FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, "", Lucene40FieldInfosFormat.FIELD_INFOS_EXTENSION);+ IndexInput input = directory.openInput(fileName, iocontext);++ boolean success = false;+ try {+ CodecUtil.checkHeader(input, Lucene40FieldInfosFormat.CODEC_NAME,+ Lucene40FieldInfosFormat.FORMAT_START,+ Lucene40FieldInfosFormat.FORMAT_CURRENT);++ final int size = input.readVInt(); //read in the size+ FieldInfo infos[] = new FieldInfo[size];++ for (int i = 0; i < size; i++) {+ String name = input.readString();+ final int fieldNumber = input.readVInt();+ byte bits = input.readByte();+ boolean isIndexed = (bits & Lucene40FieldInfosFormat.IS_INDEXED) != 0;+ boolean storeTermVector = (bits & Lucene40FieldInfosFormat.STORE_TERMVECTOR) != 0;+ boolean omitNorms = (bits & Lucene40FieldInfosFormat.OMIT_NORMS) != 0;+ boolean storePayloads = (bits & Lucene40FieldInfosFormat.STORE_PAYLOADS) != 0;+ final IndexOptions indexOptions;+ if (!isIndexed) {+ indexOptions = null;+ } else if ((bits & Lucene40FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_ONLY;+ } else if ((bits & Lucene40FieldInfosFormat.OMIT_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS;+ } else if ((bits & Lucene40FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;+ } else {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;+ }++ // LUCENE-3027: past indices were able to write+ // storePayloads=true when omitTFAP is also true,+ // which is invalid. We correct that, here:+ if (isIndexed && indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {+ storePayloads = false;+ }+ // DV Types are packed in one byte+ byte val = input.readByte();+ final LegacyDocValuesType oldValuesType = getDocValuesType((byte) (val & 0x0F));+ final LegacyDocValuesType oldNormsType = getDocValuesType((byte) ((val >>> 4) & 0x0F));+ final Map<String,String> attributes = input.readStringStringMap();;+ if (oldValuesType.mapping != null) {+ attributes.put(LEGACY_DV_TYPE_KEY, oldValuesType.name());+ }+ if (oldNormsType.mapping != null) {+ if (oldNormsType.mapping != DocValuesType.NUMERIC) {+ throw new CorruptIndexException("invalid norm type: " + oldNormsType, input);+ }+ attributes.put(LEGACY_NORM_TYPE_KEY, oldNormsType.name());+ }+ infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,+ omitNorms, storePayloads, indexOptions, oldValuesType.mapping, oldNormsType.mapping, -1, Collections.unmodifiableMap(attributes));+ }+ CodecUtil.checkEOF(input);+ FieldInfos fieldInfos = new FieldInfos(infos);+ success = true;+ return fieldInfos;+ } finally {+ if (success) {+ input.close();+ } else {+ IOUtils.closeWhileHandlingException(input);+ }+ }+ }++ static final String LEGACY_DV_TYPE_KEY = Lucene40FieldInfosFormat.class.getSimpleName() + ".dvtype";+ static final String LEGACY_NORM_TYPE_KEY = Lucene40FieldInfosFormat.class.getSimpleName() + ".normtype";++ // mapping of 4.0 types -> 4.2 types+ static enum LegacyDocValuesType {+ NONE(null),+ VAR_INTS(DocValuesType.NUMERIC),+ FLOAT_32(DocValuesType.NUMERIC),+ FLOAT_64(DocValuesType.NUMERIC),+ BYTES_FIXED_STRAIGHT(DocValuesType.BINARY),+ BYTES_FIXED_DEREF(DocValuesType.BINARY),+ BYTES_VAR_STRAIGHT(DocValuesType.BINARY),+ BYTES_VAR_DEREF(DocValuesType.BINARY),+ FIXED_INTS_16(DocValuesType.NUMERIC),+ FIXED_INTS_32(DocValuesType.NUMERIC),+ FIXED_INTS_64(DocValuesType.NUMERIC),+ FIXED_INTS_8(DocValuesType.NUMERIC),+ BYTES_FIXED_SORTED(DocValuesType.SORTED),+ BYTES_VAR_SORTED(DocValuesType.SORTED);++ final DocValuesType mapping;+ LegacyDocValuesType(DocValuesType mapping) {+ this.mapping = mapping;+ }+ }++ // decodes a 4.0 type+ private static LegacyDocValuesType getDocValuesType(byte b) {+ return LegacyDocValuesType.values()[b];+ }+@Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {+ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {throw new UnsupportedOperationException("this codec can only be used for reading");}-+/** Extension of field infos */static final String FIELD_INFOS_EXTENSION = "fnm";diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.javadeleted file mode 100644index 6aefdb59404..00000000000--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java+++ /dev/null@@ -1,151 +0,0 @@-package org.apache.lucene.codecs.lucene40;--/*- * 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.Collections;-import java.util.Map;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.index.CorruptIndexException;-import org.apache.lucene.index.FieldInfo;-import org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.IndexFileNames;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfo.IndexOptions;-import org.apache.lucene.index.SegmentInfo;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;-import org.apache.lucene.store.IndexInput;-import org.apache.lucene.util.IOUtils;--/**- * Lucene 4.0 FieldInfos reader.- * @deprecated Only for reading old 4.0 and 4.1 segments- */-@Deprecated-final class Lucene40FieldInfosReader extends FieldInfosReader {-- /** Sole constructor. */- public Lucene40FieldInfosReader() {- }-- @Override- public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, "", Lucene40FieldInfosFormat.FIELD_INFOS_EXTENSION);- IndexInput input = directory.openInput(fileName, iocontext);-- boolean success = false;- try {- CodecUtil.checkHeader(input, Lucene40FieldInfosFormat.CODEC_NAME,- Lucene40FieldInfosFormat.FORMAT_START,- Lucene40FieldInfosFormat.FORMAT_CURRENT);-- final int size = input.readVInt(); //read in the size- FieldInfo infos[] = new FieldInfo[size];-- for (int i = 0; i < size; i++) {- String name = input.readString();- final int fieldNumber = input.readVInt();- byte bits = input.readByte();- boolean isIndexed = (bits & Lucene40FieldInfosFormat.IS_INDEXED) != 0;- boolean storeTermVector = (bits & Lucene40FieldInfosFormat.STORE_TERMVECTOR) != 0;- boolean omitNorms = (bits & Lucene40FieldInfosFormat.OMIT_NORMS) != 0;- boolean storePayloads = (bits & Lucene40FieldInfosFormat.STORE_PAYLOADS) != 0;- final IndexOptions indexOptions;- if (!isIndexed) {- indexOptions = null;- } else if ((bits & Lucene40FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_ONLY;- } else if ((bits & Lucene40FieldInfosFormat.OMIT_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS;- } else if ((bits & Lucene40FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;- } else {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;- }-- // LUCENE-3027: past indices were able to write- // storePayloads=true when omitTFAP is also true,- // which is invalid. We correct that, here:- if (isIndexed && indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {- storePayloads = false;- }- // DV Types are packed in one byte- byte val = input.readByte();- final LegacyDocValuesType oldValuesType = getDocValuesType((byte) (val & 0x0F));- final LegacyDocValuesType oldNormsType = getDocValuesType((byte) ((val >>> 4) & 0x0F));- final Map<String,String> attributes = input.readStringStringMap();;- if (oldValuesType.mapping != null) {- attributes.put(LEGACY_DV_TYPE_KEY, oldValuesType.name());- }- if (oldNormsType.mapping != null) {- if (oldNormsType.mapping != DocValuesType.NUMERIC) {- throw new CorruptIndexException("invalid norm type: " + oldNormsType, input);- }- attributes.put(LEGACY_NORM_TYPE_KEY, oldNormsType.name());- }- infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,- omitNorms, storePayloads, indexOptions, oldValuesType.mapping, oldNormsType.mapping, -1, Collections.unmodifiableMap(attributes));- }-- CodecUtil.checkEOF(input);- FieldInfos fieldInfos = new FieldInfos(infos);- success = true;- return fieldInfos;- } finally {- if (success) {- input.close();- } else {- IOUtils.closeWhileHandlingException(input);- }- }- }-- static final String LEGACY_DV_TYPE_KEY = Lucene40FieldInfosReader.class.getSimpleName() + ".dvtype";- static final String LEGACY_NORM_TYPE_KEY = Lucene40FieldInfosReader.class.getSimpleName() + ".normtype";-- // mapping of 4.0 types -> 4.2 types- static enum LegacyDocValuesType {- NONE(null),- VAR_INTS(DocValuesType.NUMERIC),- FLOAT_32(DocValuesType.NUMERIC),- FLOAT_64(DocValuesType.NUMERIC),- BYTES_FIXED_STRAIGHT(DocValuesType.BINARY),- BYTES_FIXED_DEREF(DocValuesType.BINARY),- BYTES_VAR_STRAIGHT(DocValuesType.BINARY),- BYTES_VAR_DEREF(DocValuesType.BINARY),- FIXED_INTS_16(DocValuesType.NUMERIC),- FIXED_INTS_32(DocValuesType.NUMERIC),- FIXED_INTS_64(DocValuesType.NUMERIC),- FIXED_INTS_8(DocValuesType.NUMERIC),- BYTES_FIXED_SORTED(DocValuesType.SORTED),- BYTES_VAR_SORTED(DocValuesType.SORTED);-- final DocValuesType mapping;- LegacyDocValuesType(DocValuesType mapping) {- this.mapping = mapping;- }- }-- // decodes a 4.0 type- private static LegacyDocValuesType getDocValuesType(byte b) {- return LegacyDocValuesType.values()[b];- }-}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40NormsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40NormsReader.javaindex 7ce16655715..e52491204d7 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40NormsReader.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40NormsReader.java@@ -40,7 +40,7 @@ final class Lucene40NormsReader extends NormsProducer {}Lucene40NormsReader(SegmentReadState state, String filename) throws IOException {- impl = new Lucene40DocValuesReader(state, filename, Lucene40FieldInfosReader.LEGACY_NORM_TYPE_KEY);+ impl = new Lucene40DocValuesReader(state, filename, Lucene40FieldInfosFormat.LEGACY_NORM_TYPE_KEY);}@Overridediff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.javaindex 134dce2672e..ee3a20b9e1e 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoFormat.java@@ -17,10 +17,21 @@ package org.apache.lucene.codecs.lucene40;* limitations under the License.*/+import java.io.IOException;+import java.text.ParseException;+import java.util.Map;+import java.util.Set;++import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.SegmentInfoFormat;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.codecs.SegmentInfoWriter;+import org.apache.lucene.index.CorruptIndexException;+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.IndexInput;+import org.apache.lucene.util.IOUtils;+import org.apache.lucene.util.Version;/*** Lucene 4.0 Segment info format.@@ -28,19 +39,55 @@ import org.apache.lucene.index.SegmentInfo;*/@Deprecatedpublic class Lucene40SegmentInfoFormat extends SegmentInfoFormat {- private final SegmentInfoReader reader = new Lucene40SegmentInfoReader();/** Sole constructor. */public Lucene40SegmentInfoFormat() {}@Override- public final SegmentInfoReader getSegmentInfoReader() {- return reader;+ public final SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene40SegmentInfoFormat.SI_EXTENSION);+ final IndexInput input = dir.openInput(fileName, context);+ boolean success = false;+ try {+ CodecUtil.checkHeader(input, Lucene40SegmentInfoFormat.CODEC_NAME,+ Lucene40SegmentInfoFormat.VERSION_START,+ Lucene40SegmentInfoFormat.VERSION_CURRENT);+ final Version version;+ try {+ version = Version.parse(input.readString());+ } catch (ParseException pe) {+ throw new CorruptIndexException("unable to parse version string: " + pe.getMessage(), input, pe);+ }+ final int docCount = input.readInt();+ if (docCount < 0) {+ throw new CorruptIndexException("invalid docCount: " + docCount, input);+ }+ final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;+ final Map<String,String> diagnostics = input.readStringStringMap();+ input.readStringStringMap(); // read deprecated attributes+ final Set<String> files = input.readStringSet();++ CodecUtil.checkEOF(input);++ final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, null);+ si.setFiles(files);++ success = true;++ return si;++ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(input);+ } else {+ input.close();+ }+ }}@Override- public SegmentInfoWriter getSegmentInfoWriter() {+ public void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException {throw new UnsupportedOperationException("this codec can only be used for reading");}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.javadeleted file mode 100644index fe1e5c6ddda..00000000000--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoReader.java+++ /dev/null@@ -1,88 +0,0 @@-package org.apache.lucene.codecs.lucene40;--/*- * 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.text.ParseException;-import java.util.Map;-import java.util.Set;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.index.CorruptIndexException;-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.IndexInput;-import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.Version;--/**- * Lucene 4.0 SI reader- * @deprecated Only for reading old 4.0-4.5 segments- */-@Deprecated-final class Lucene40SegmentInfoReader extends SegmentInfoReader {-- /** Sole constructor. */- public Lucene40SegmentInfoReader() {- }-- @Override- public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene40SegmentInfoFormat.SI_EXTENSION);- final IndexInput input = dir.openInput(fileName, context);- boolean success = false;- try {- CodecUtil.checkHeader(input, Lucene40SegmentInfoFormat.CODEC_NAME,- Lucene40SegmentInfoFormat.VERSION_START,- Lucene40SegmentInfoFormat.VERSION_CURRENT);- final Version version;- try {- version = Version.parse(input.readString());- } catch (ParseException pe) {- throw new CorruptIndexException("unable to parse version string: " + pe.getMessage(), input, pe);- }- final int docCount = input.readInt();- if (docCount < 0) {- throw new CorruptIndexException("invalid docCount: " + docCount, input);- }- final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;- final Map<String,String> diagnostics = input.readStringStringMap();- input.readStringStringMap(); // read deprecated attributes- final Set<String> files = input.readStringSet();-- CodecUtil.checkEOF(input);-- final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, null);- si.setFiles(files);-- success = true;-- return si;-- } finally {- if (!success) {- IOUtils.closeWhileHandlingException(input);- } else {- input.close();- }- }- }-}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.javaindex 588acecd1aa..6ebfd86ac20 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosFormat.java@@ -18,10 +18,22 @@ package org.apache.lucene.codecs.lucene42;*/import java.io.IOException;+import java.util.Collections;+import java.util.Map;+import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.codecs.FieldInfosWriter;+import org.apache.lucene.index.CorruptIndexException;+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.FieldInfo.DocValuesType;+import org.apache.lucene.index.FieldInfo.IndexOptions;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.IndexInput;+import org.apache.lucene.util.IOUtils;/*** Lucene 4.2 Field Infos format.@@ -29,22 +41,89 @@ import org.apache.lucene.codecs.FieldInfosWriter;*/@Deprecatedpublic class Lucene42FieldInfosFormat extends FieldInfosFormat {- private final FieldInfosReader reader = new Lucene42FieldInfosReader();/** Sole constructor. */public Lucene42FieldInfosFormat() {}@Override- public final FieldInfosReader getFieldInfosReader() throws IOException {- return reader;- }+ public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, "", Lucene42FieldInfosFormat.EXTENSION);+ IndexInput input = directory.openInput(fileName, iocontext);++ boolean success = false;+ try {+ CodecUtil.checkHeader(input, Lucene42FieldInfosFormat.CODEC_NAME,+ Lucene42FieldInfosFormat.FORMAT_START,+ Lucene42FieldInfosFormat.FORMAT_CURRENT);++ final int size = input.readVInt(); //read in the size+ FieldInfo infos[] = new FieldInfo[size];++ for (int i = 0; i < size; i++) {+ String name = input.readString();+ final int fieldNumber = input.readVInt();+ byte bits = input.readByte();+ boolean isIndexed = (bits & Lucene42FieldInfosFormat.IS_INDEXED) != 0;+ boolean storeTermVector = (bits & Lucene42FieldInfosFormat.STORE_TERMVECTOR) != 0;+ boolean omitNorms = (bits & Lucene42FieldInfosFormat.OMIT_NORMS) != 0;+ boolean storePayloads = (bits & Lucene42FieldInfosFormat.STORE_PAYLOADS) != 0;+ final IndexOptions indexOptions;+ if (!isIndexed) {+ indexOptions = null;+ } else if ((bits & Lucene42FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_ONLY;+ } else if ((bits & Lucene42FieldInfosFormat.OMIT_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS;+ } else if ((bits & Lucene42FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;+ } else {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;+ }+ // DV Types are packed in one byte+ byte val = input.readByte();+ final DocValuesType docValuesType = getDocValuesType(input, (byte) (val & 0x0F));+ final DocValuesType normsType = getDocValuesType(input, (byte) ((val >>> 4) & 0x0F));+ final Map<String,String> attributes = input.readStringStringMap();+ infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,+ omitNorms, storePayloads, indexOptions, docValuesType, normsType, -1, Collections.unmodifiableMap(attributes));+ }++ CodecUtil.checkEOF(input);+ FieldInfos fieldInfos = new FieldInfos(infos);+ success = true;+ return fieldInfos;+ } finally {+ if (success) {+ input.close();+ } else {+ IOUtils.closeWhileHandlingException(input);+ }+ }+ }++ private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {+ if (b == 0) {+ return null;+ } else if (b == 1) {+ return DocValuesType.NUMERIC;+ } else if (b == 2) {+ return DocValuesType.BINARY;+ } else if (b == 3) {+ return DocValuesType.SORTED;+ } else if (b == 4) {+ return DocValuesType.SORTED_SET;+ } else {+ throw new CorruptIndexException("invalid docvalues byte: " + b, input);+ }+ }+@Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {+ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {throw new UnsupportedOperationException("this codec can only be used for reading");}-+/** Extension of field infos */static final String EXTENSION = "fnm";diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.javadeleted file mode 100644index 140c30ddd43..00000000000--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosReader.java+++ /dev/null@@ -1,122 +0,0 @@-package org.apache.lucene.codecs.lucene42;--/*- * 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.Collections;-import java.util.Map;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.index.CorruptIndexException;-import org.apache.lucene.index.FieldInfo;-import org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.IndexFileNames;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfo.IndexOptions;-import org.apache.lucene.index.SegmentInfo;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;-import org.apache.lucene.store.IndexInput;-import org.apache.lucene.util.IOUtils;--/**- * Lucene 4.2 FieldInfos reader.- *- * @deprecated Only for reading old 4.2-4.5 segments- */-@Deprecated-final class Lucene42FieldInfosReader extends FieldInfosReader {-- /** Sole constructor. */- public Lucene42FieldInfosReader() {- }-- @Override- public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, "", Lucene42FieldInfosFormat.EXTENSION);- IndexInput input = directory.openInput(fileName, iocontext);-- boolean success = false;- try {- CodecUtil.checkHeader(input, Lucene42FieldInfosFormat.CODEC_NAME,- Lucene42FieldInfosFormat.FORMAT_START,- Lucene42FieldInfosFormat.FORMAT_CURRENT);-- final int size = input.readVInt(); //read in the size- FieldInfo infos[] = new FieldInfo[size];-- for (int i = 0; i < size; i++) {- String name = input.readString();- final int fieldNumber = input.readVInt();- byte bits = input.readByte();- boolean isIndexed = (bits & Lucene42FieldInfosFormat.IS_INDEXED) != 0;- boolean storeTermVector = (bits & Lucene42FieldInfosFormat.STORE_TERMVECTOR) != 0;- boolean omitNorms = (bits & Lucene42FieldInfosFormat.OMIT_NORMS) != 0;- boolean storePayloads = (bits & Lucene42FieldInfosFormat.STORE_PAYLOADS) != 0;- final IndexOptions indexOptions;- if (!isIndexed) {- indexOptions = null;- } else if ((bits & Lucene42FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_ONLY;- } else if ((bits & Lucene42FieldInfosFormat.OMIT_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS;- } else if ((bits & Lucene42FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;- } else {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;- }-- // DV Types are packed in one byte- byte val = input.readByte();- final DocValuesType docValuesType = getDocValuesType(input, (byte) (val & 0x0F));- final DocValuesType normsType = getDocValuesType(input, (byte) ((val >>> 4) & 0x0F));- final Map<String,String> attributes = input.readStringStringMap();- infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,- omitNorms, storePayloads, indexOptions, docValuesType, normsType, -1, Collections.unmodifiableMap(attributes));- }-- CodecUtil.checkEOF(input);- FieldInfos fieldInfos = new FieldInfos(infos);- success = true;- return fieldInfos;- } finally {- if (success) {- input.close();- } else {- IOUtils.closeWhileHandlingException(input);- }- }- }-- private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {- if (b == 0) {- return null;- } else if (b == 1) {- return DocValuesType.NUMERIC;- } else if (b == 2) {- return DocValuesType.BINARY;- } else if (b == 3) {- return DocValuesType.SORTED;- } else if (b == 4) {- return DocValuesType.SORTED_SET;- } else {- throw new CorruptIndexException("invalid docvalues byte: " + b, input);- }- }-}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.javaindex 0f78c7d70e2..9318d6d4212 100755--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosFormat.java@@ -18,10 +18,23 @@ package org.apache.lucene.codecs.lucene46;*/import java.io.IOException;+import java.util.Collections;+import java.util.Map;+import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.codecs.FieldInfosWriter;+import org.apache.lucene.index.CorruptIndexException;+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.FieldInfo.DocValuesType;+import org.apache.lucene.index.FieldInfo.IndexOptions;+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.store.IndexOutput;/*** Lucene 4.6 Field Infos format.@@ -29,21 +42,139 @@ import org.apache.lucene.codecs.FieldInfosWriter;*/@Deprecatedpublic final class Lucene46FieldInfosFormat extends FieldInfosFormat {- private final FieldInfosReader reader = new Lucene46FieldInfosReader();- private final FieldInfosWriter writer = new Lucene46FieldInfosWriter();/** Sole constructor. */public Lucene46FieldInfosFormat() {}@Override- public final FieldInfosReader getFieldInfosReader() throws IOException {- return reader;+ public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION);+ try (ChecksumIndexInput input = directory.openChecksumInput(fileName, context)) {+ int codecVersion = CodecUtil.checkHeader(input, Lucene46FieldInfosFormat.CODEC_NAME,+ Lucene46FieldInfosFormat.FORMAT_START,+ Lucene46FieldInfosFormat.FORMAT_CURRENT);++ final int size = input.readVInt(); //read in the size+ FieldInfo infos[] = new FieldInfo[size];++ for (int i = 0; i < size; i++) {+ String name = input.readString();+ final int fieldNumber = input.readVInt();+ if (fieldNumber < 0) {+ throw new CorruptIndexException("invalid field number for field: " + name + ", fieldNumber=" + fieldNumber, input);+ }+ byte bits = input.readByte();+ boolean isIndexed = (bits & Lucene46FieldInfosFormat.IS_INDEXED) != 0;+ boolean storeTermVector = (bits & Lucene46FieldInfosFormat.STORE_TERMVECTOR) != 0;+ boolean omitNorms = (bits & Lucene46FieldInfosFormat.OMIT_NORMS) != 0;+ boolean storePayloads = (bits & Lucene46FieldInfosFormat.STORE_PAYLOADS) != 0;+ final IndexOptions indexOptions;+ if (!isIndexed) {+ indexOptions = null;+ } else if ((bits & Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_ONLY;+ } else if ((bits & Lucene46FieldInfosFormat.OMIT_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS;+ } else if ((bits & Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;+ } else {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;+ }++ // DV Types are packed in one byte+ byte val = input.readByte();+ final DocValuesType docValuesType = getDocValuesType(input, (byte) (val & 0x0F));+ final DocValuesType normsType = getDocValuesType(input, (byte) ((val >>> 4) & 0x0F));+ final long dvGen = input.readLong();+ final Map<String,String> attributes = input.readStringStringMap();+ infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,+ omitNorms, storePayloads, indexOptions, docValuesType, normsType, dvGen, Collections.unmodifiableMap(attributes));+ }++ if (codecVersion >= Lucene46FieldInfosFormat.FORMAT_CHECKSUM) {+ CodecUtil.checkFooter(input);+ } else {+ CodecUtil.checkEOF(input);+ }+ return new FieldInfos(infos);+ }+ }++ private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {+ if (b == 0) {+ return null;+ } else if (b == 1) {+ return DocValuesType.NUMERIC;+ } else if (b == 2) {+ return DocValuesType.BINARY;+ } else if (b == 3) {+ return DocValuesType.SORTED;+ } else if (b == 4) {+ return DocValuesType.SORTED_SET;+ } else if (b == 5) {+ return DocValuesType.SORTED_NUMERIC;+ } else {+ throw new CorruptIndexException("invalid docvalues byte: " + b, input);+ }}@Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {- return writer;+ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION);+ try (IndexOutput output = directory.createOutput(fileName, context)) {+ CodecUtil.writeHeader(output, Lucene46FieldInfosFormat.CODEC_NAME, Lucene46FieldInfosFormat.FORMAT_CURRENT);+ output.writeVInt(infos.size());+ for (FieldInfo fi : infos) {+ IndexOptions indexOptions = fi.getIndexOptions();+ byte bits = 0x0;+ if (fi.hasVectors()) bits |= Lucene46FieldInfosFormat.STORE_TERMVECTOR;+ if (fi.omitsNorms()) bits |= Lucene46FieldInfosFormat.OMIT_NORMS;+ if (fi.hasPayloads()) bits |= Lucene46FieldInfosFormat.STORE_PAYLOADS;+ if (fi.isIndexed()) {+ bits |= Lucene46FieldInfosFormat.IS_INDEXED;+ assert indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();+ if (indexOptions == IndexOptions.DOCS_ONLY) {+ bits |= Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;+ } else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {+ bits |= Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;+ } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) {+ bits |= Lucene46FieldInfosFormat.OMIT_POSITIONS;+ }+ }+ output.writeString(fi.name);+ output.writeVInt(fi.number);+ output.writeByte(bits);++ // pack the DV types in one byte+ final byte dv = docValuesByte(fi.getDocValuesType());+ final byte nrm = docValuesByte(fi.getNormType());+ assert (dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0;+ byte val = (byte) (0xff & ((nrm << 4) | dv));+ output.writeByte(val);+ output.writeLong(fi.getDocValuesGen());+ output.writeStringStringMap(fi.attributes());+ }+ CodecUtil.writeFooter(output);+ }+ }++ private static byte docValuesByte(DocValuesType type) {+ if (type == null) {+ return 0;+ } else if (type == DocValuesType.NUMERIC) {+ return 1;+ } else if (type == DocValuesType.BINARY) {+ return 2;+ } else if (type == DocValuesType.SORTED) {+ return 3;+ } else if (type == DocValuesType.SORTED_SET) {+ return 4;+ } else if (type == DocValuesType.SORTED_NUMERIC) {+ return 5;+ } else {+ throw new AssertionError();+ }}/** Extension of field infos */diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.javadeleted file mode 100755index 8f1827019eb..00000000000--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosReader.java+++ /dev/null@@ -1,121 +0,0 @@-package org.apache.lucene.codecs.lucene46;--/*- * 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.Collections;-import java.util.Map;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.index.CorruptIndexException;-import org.apache.lucene.index.FieldInfo;-import org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.IndexFileNames;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfo.IndexOptions;-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.store.IndexInput;--/**- * Lucene 4.6 FieldInfos reader.- *- * @deprecated only for old 4.x segments- */-@Deprecated-final class Lucene46FieldInfosReader extends FieldInfosReader {-- /** Sole constructor. */- public Lucene46FieldInfosReader() {- }-- @Override- public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION);- try (ChecksumIndexInput input = directory.openChecksumInput(fileName, context)) {- int codecVersion = CodecUtil.checkHeader(input, Lucene46FieldInfosFormat.CODEC_NAME,- Lucene46FieldInfosFormat.FORMAT_START,- Lucene46FieldInfosFormat.FORMAT_CURRENT);-- final int size = input.readVInt(); //read in the size- FieldInfo infos[] = new FieldInfo[size];-- for (int i = 0; i < size; i++) {- String name = input.readString();- final int fieldNumber = input.readVInt();- if (fieldNumber < 0) {- throw new CorruptIndexException("invalid field number for field: " + name + ", fieldNumber=" + fieldNumber, input);- }- byte bits = input.readByte();- boolean isIndexed = (bits & Lucene46FieldInfosFormat.IS_INDEXED) != 0;- boolean storeTermVector = (bits & Lucene46FieldInfosFormat.STORE_TERMVECTOR) != 0;- boolean omitNorms = (bits & Lucene46FieldInfosFormat.OMIT_NORMS) != 0;- boolean storePayloads = (bits & Lucene46FieldInfosFormat.STORE_PAYLOADS) != 0;- final IndexOptions indexOptions;- if (!isIndexed) {- indexOptions = null;- } else if ((bits & Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_ONLY;- } else if ((bits & Lucene46FieldInfosFormat.OMIT_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS;- } else if ((bits & Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;- } else {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;- }-- // DV Types are packed in one byte- byte val = input.readByte();- final DocValuesType docValuesType = getDocValuesType(input, (byte) (val & 0x0F));- final DocValuesType normsType = getDocValuesType(input, (byte) ((val >>> 4) & 0x0F));- final long dvGen = input.readLong();- final Map<String,String> attributes = input.readStringStringMap();- infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,- omitNorms, storePayloads, indexOptions, docValuesType, normsType, dvGen, Collections.unmodifiableMap(attributes));- }-- if (codecVersion >= Lucene46FieldInfosFormat.FORMAT_CHECKSUM) {- CodecUtil.checkFooter(input);- } else {- CodecUtil.checkEOF(input);- }- return new FieldInfos(infos);- }- }-- private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {- if (b == 0) {- return null;- } else if (b == 1) {- return DocValuesType.NUMERIC;- } else if (b == 2) {- return DocValuesType.BINARY;- } else if (b == 3) {- return DocValuesType.SORTED;- } else if (b == 4) {- return DocValuesType.SORTED_SET;- } else if (b == 5) {- return DocValuesType.SORTED_NUMERIC;- } else {- throw new CorruptIndexException("invalid docvalues byte: " + b, input);- }- }-}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.javadeleted file mode 100755index e511da4543b..00000000000--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46FieldInfosWriter.java+++ /dev/null@@ -1,103 +0,0 @@-package org.apache.lucene.codecs.lucene46;--/*- * 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 org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosWriter;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfo.IndexOptions;-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.store.IndexOutput;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;--/**- * Lucene 4.6 FieldInfos writer.- *- * @deprecated only for old 4.x segments- */-@Deprecated-final class Lucene46FieldInfosWriter extends FieldInfosWriter {-- /** Sole constructor. */- public Lucene46FieldInfosWriter() {- }-- @Override- public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene46FieldInfosFormat.EXTENSION);- try (IndexOutput output = directory.createOutput(fileName, context)) {- CodecUtil.writeHeader(output, Lucene46FieldInfosFormat.CODEC_NAME, Lucene46FieldInfosFormat.FORMAT_CURRENT);- output.writeVInt(infos.size());- for (FieldInfo fi : infos) {- IndexOptions indexOptions = fi.getIndexOptions();- byte bits = 0x0;- if (fi.hasVectors()) bits |= Lucene46FieldInfosFormat.STORE_TERMVECTOR;- if (fi.omitsNorms()) bits |= Lucene46FieldInfosFormat.OMIT_NORMS;- if (fi.hasPayloads()) bits |= Lucene46FieldInfosFormat.STORE_PAYLOADS;- if (fi.isIndexed()) {- bits |= Lucene46FieldInfosFormat.IS_INDEXED;- assert indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();- if (indexOptions == IndexOptions.DOCS_ONLY) {- bits |= Lucene46FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;- } else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {- bits |= Lucene46FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;- } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) {- bits |= Lucene46FieldInfosFormat.OMIT_POSITIONS;- }- }- output.writeString(fi.name);- output.writeVInt(fi.number);- output.writeByte(bits);-- // pack the DV types in one byte- final byte dv = docValuesByte(fi.getDocValuesType());- final byte nrm = docValuesByte(fi.getNormType());- assert (dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0;- byte val = (byte) (0xff & ((nrm << 4) | dv));- output.writeByte(val);- output.writeLong(fi.getDocValuesGen());- output.writeStringStringMap(fi.attributes());- }- CodecUtil.writeFooter(output);- }- }-- private static byte docValuesByte(DocValuesType type) {- if (type == null) {- return 0;- } else if (type == DocValuesType.NUMERIC) {- return 1;- } else if (type == DocValuesType.BINARY) {- return 2;- } else if (type == DocValuesType.SORTED) {- return 3;- } else if (type == DocValuesType.SORTED_SET) {- return 4;- } else if (type == DocValuesType.SORTED_NUMERIC) {- return 5;- } else {- throw new AssertionError();- }- }-}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.javaindex 6a553c053f1..361aa5accef 100755--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoFormat.java@@ -17,10 +17,20 @@ package org.apache.lucene.codecs.lucene46;* limitations under the License.*/+import java.io.IOException;+import java.text.ParseException;+import java.util.Map;+import java.util.Set;++import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.SegmentInfoFormat;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.codecs.SegmentInfoWriter;+import org.apache.lucene.index.CorruptIndexException;+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.Version;/*** Lucene 4.6 Segment info format.@@ -28,19 +38,48 @@ import org.apache.lucene.index.SegmentInfo;*/@Deprecatedpublic class Lucene46SegmentInfoFormat extends SegmentInfoFormat {- private final SegmentInfoReader reader = new Lucene46SegmentInfoReader();/** Sole constructor. */public Lucene46SegmentInfoFormat() {}@Override- public final SegmentInfoReader getSegmentInfoReader() {- return reader;+ public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene46SegmentInfoFormat.SI_EXTENSION);+ try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {+ int codecVersion = CodecUtil.checkHeader(input, Lucene46SegmentInfoFormat.CODEC_NAME,+ Lucene46SegmentInfoFormat.VERSION_START,+ Lucene46SegmentInfoFormat.VERSION_CURRENT);+ final Version version;+ try {+ version = Version.parse(input.readString());+ } catch (ParseException pe) {+ throw new CorruptIndexException("unable to parse version string: " + pe.getMessage(), input, pe);+ }++ final int docCount = input.readInt();+ if (docCount < 0) {+ throw new CorruptIndexException("invalid docCount: " + docCount, input);+ }+ final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;+ final Map<String,String> diagnostics = input.readStringStringMap();+ final Set<String> files = input.readStringSet();++ if (codecVersion >= Lucene46SegmentInfoFormat.VERSION_CHECKSUM) {+ CodecUtil.checkFooter(input);+ } else {+ CodecUtil.checkEOF(input);+ }++ final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, null);+ si.setFiles(files);++ return si;+ }}@Override- public SegmentInfoWriter getSegmentInfoWriter() {+ public void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException {throw new UnsupportedOperationException("this codec can only be used for reading");}diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoReader.javadeleted file mode 100755index 9faeb8a5af7..00000000000--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoReader.java+++ /dev/null@@ -1,80 +0,0 @@-package org.apache.lucene.codecs.lucene46;--/*- * 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.text.ParseException;-import java.util.Map;-import java.util.Set;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.index.CorruptIndexException;-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.Version;--/**- * Lucene 4.6 segment infos reader- * @deprecated only for old 4.x segments- */-@Deprecated-final class Lucene46SegmentInfoReader extends SegmentInfoReader {-- /** Sole constructor. */- public Lucene46SegmentInfoReader() {- }-- @Override- public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene46SegmentInfoFormat.SI_EXTENSION);- try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {- int codecVersion = CodecUtil.checkHeader(input, Lucene46SegmentInfoFormat.CODEC_NAME,- Lucene46SegmentInfoFormat.VERSION_START,- Lucene46SegmentInfoFormat.VERSION_CURRENT);- final Version version;- try {- version = Version.parse(input.readString());- } catch (ParseException pe) {- throw new CorruptIndexException("unable to parse version string: " + pe.getMessage(), input, pe);- }-- final int docCount = input.readInt();- if (docCount < 0) {- throw new CorruptIndexException("invalid docCount: " + docCount, input);- }- final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;- final Map<String,String> diagnostics = input.readStringStringMap();- final Set<String> files = input.readStringSet();-- if (codecVersion >= Lucene46SegmentInfoFormat.VERSION_CHECKSUM) {- CodecUtil.checkFooter(input);- } else {- CodecUtil.checkEOF(input);- }-- final SegmentInfo si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, null);- si.setFiles(files);-- return si;- }- }-}diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40DocValuesWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40DocValuesWriter.javaindex 9ceb9ee02e1..5d33f52074f 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40DocValuesWriter.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40DocValuesWriter.java@@ -25,7 +25,7 @@ import java.util.TreeSet;import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.DocValuesConsumer;import org.apache.lucene.codecs.MissingOrdRemapper;-import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosReader.LegacyDocValuesType;+import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosFormat.LegacyDocValuesType;import org.apache.lucene.index.FieldInfo;import org.apache.lucene.index.IndexFileNames;import org.apache.lucene.index.SegmentWriteState;diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWCodec.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWCodec.javaindex 6e4dff11403..56f2d396443 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWCodec.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWCodec.java@@ -4,7 +4,6 @@ import java.io.IOException;import org.apache.lucene.codecs.DocValuesFormat;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.codecs.NormsFormat;import org.apache.lucene.codecs.PostingsFormat;import org.apache.lucene.codecs.SegmentInfoFormat;@@ -35,13 +34,7 @@ import org.apache.lucene.codecs.TermVectorsFormat;@Deprecatedpublic final class Lucene40RWCodec extends Lucene40Codec {- private final FieldInfosFormat fieldInfos = new Lucene40FieldInfosFormat() {- @Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {- return new Lucene40FieldInfosWriter();- }- };-+ private final FieldInfosFormat fieldInfos = new Lucene40RWFieldInfosFormat();private final DocValuesFormat docValues = new Lucene40RWDocValuesFormat();private final NormsFormat norms = new Lucene40RWNormsFormat();private final StoredFieldsFormat stored = new Lucene40RWStoredFieldsFormat();diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWDocValuesFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWDocValuesFormat.javaindex 7e658968c47..f6062e5da22 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWDocValuesFormat.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWDocValuesFormat.java@@ -35,6 +35,6 @@ public final class Lucene40RWDocValuesFormat extends Lucene40DocValuesFormat {String filename = IndexFileNames.segmentFileName(state.segmentInfo.name,"dv",Lucene40CompoundFormat.COMPOUND_FILE_EXTENSION);- return new Lucene40DocValuesWriter(state, filename, Lucene40FieldInfosReader.LEGACY_DV_TYPE_KEY);+ return new Lucene40DocValuesWriter(state, filename, Lucene40FieldInfosFormat.LEGACY_DV_TYPE_KEY);}}diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWFieldInfosFormat.javasimilarity index 91%rename from lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.javarename to lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWFieldInfosFormat.javaindex 26190c72f1a..e9fd7cdfb49 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWFieldInfosFormat.java@@ -19,8 +19,6 @@ package org.apache.lucene.codecs.lucene40;import java.io.IOException;import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosWriter;-import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosReader.LegacyDocValuesType;import org.apache.lucene.index.FieldInfo.DocValuesType;import org.apache.lucene.index.FieldInfo.IndexOptions;import org.apache.lucene.index.FieldInfo;@@ -37,10 +35,10 @@ import org.apache.lucene.util.IOUtils;* @deprecated for test purposes only*/@Deprecated-public final class Lucene40FieldInfosWriter extends FieldInfosWriter {+public final class Lucene40RWFieldInfosFormat extends Lucene40FieldInfosFormat {/** Sole constructor. */- public Lucene40FieldInfosWriter() {+ public Lucene40RWFieldInfosFormat() {}@Override@@ -76,8 +74,8 @@ public final class Lucene40FieldInfosWriter extends FieldInfosWriter {output.writeByte(bits);// pack the DV types in one byte- final byte dv = docValuesByte(fi.getDocValuesType(), fi.getAttribute(Lucene40FieldInfosReader.LEGACY_DV_TYPE_KEY));- final byte nrm = docValuesByte(fi.getNormType(), fi.getAttribute(Lucene40FieldInfosReader.LEGACY_NORM_TYPE_KEY));+ final byte dv = docValuesByte(fi.getDocValuesType(), fi.getAttribute(LEGACY_DV_TYPE_KEY));+ final byte nrm = docValuesByte(fi.getNormType(), fi.getAttribute(LEGACY_NORM_TYPE_KEY));assert (dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0;byte val = (byte) (0xff & ((nrm << 4) | dv));output.writeByte(val);diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWNormsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWNormsFormat.javaindex 8de09383817..49468a27842 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWNormsFormat.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWNormsFormat.java@@ -36,7 +36,7 @@ public final class Lucene40RWNormsFormat extends Lucene40NormsFormat {String filename = IndexFileNames.segmentFileName(state.segmentInfo.name,"nrm",Lucene40CompoundFormat.COMPOUND_FILE_EXTENSION);- final Lucene40DocValuesWriter impl = new Lucene40DocValuesWriter(state, filename, Lucene40FieldInfosReader.LEGACY_NORM_TYPE_KEY);+ final Lucene40DocValuesWriter impl = new Lucene40DocValuesWriter(state, filename, Lucene40FieldInfosFormat.LEGACY_NORM_TYPE_KEY);return new NormsConsumer() {@Overridepublic void addNormsField(FieldInfo field, Iterable<Number> values) throws IOException {diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWSegmentInfoFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWSegmentInfoFormat.javaindex 492d419bc2a..732e94799f3 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWSegmentInfoFormat.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40RWSegmentInfoFormat.java@@ -17,7 +17,16 @@ package org.apache.lucene.codecs.lucene40;* limitations under the License.*/-import org.apache.lucene.codecs.SegmentInfoWriter;+import java.io.IOException;+import java.util.Collections;++import org.apache.lucene.codecs.CodecUtil;+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.IOUtils;/*** Read-write version of 4.0 segmentinfo format for testing@@ -27,7 +36,33 @@ import org.apache.lucene.codecs.SegmentInfoWriter;public final class Lucene40RWSegmentInfoFormat extends Lucene40SegmentInfoFormat {@Override- public SegmentInfoWriter getSegmentInfoWriter() {- return new Lucene40SegmentInfoWriter();+ public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene40SegmentInfoFormat.SI_EXTENSION);+ si.addFile(fileName);++ final IndexOutput output = dir.createOutput(fileName, ioContext);++ boolean success = false;+ try {+ CodecUtil.writeHeader(output, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_CURRENT);+ // Write the Lucene version that created this segment, since 3.1+ output.writeString(si.getVersion().toString());+ output.writeInt(si.getDocCount());++ output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));+ output.writeStringStringMap(si.getDiagnostics());+ output.writeStringStringMap(Collections.<String,String>emptyMap());+ output.writeStringSet(si.files());++ success = true;+ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(output);+ // TODO: why must we do this? do we not get tracking dir wrapper?+ IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);+ } else {+ output.close();+ }+ }}}diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.javadeleted file mode 100644index b0d91f509a3..00000000000--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene40/Lucene40SegmentInfoWriter.java+++ /dev/null@@ -1,74 +0,0 @@-package org.apache.lucene.codecs.lucene40;--/*- * 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.Collections;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.SegmentInfoWriter;-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.IOUtils;--/**- * writer for 4.0 segmentinfos for testing- * @deprecated for test purposes only- */-@Deprecated-public final class Lucene40SegmentInfoWriter extends SegmentInfoWriter {-- /** Sole constructor. */- public Lucene40SegmentInfoWriter() {- }-- /** Save a single segment's info. */- @Override- public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {- final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene40SegmentInfoFormat.SI_EXTENSION);- si.addFile(fileName);-- final IndexOutput output = dir.createOutput(fileName, ioContext);-- boolean success = false;- try {- CodecUtil.writeHeader(output, Lucene40SegmentInfoFormat.CODEC_NAME, Lucene40SegmentInfoFormat.VERSION_CURRENT);- // Write the Lucene version that created this segment, since 3.1- output.writeString(si.getVersion().toString());- output.writeInt(si.getDocCount());-- output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));- output.writeStringStringMap(si.getDiagnostics());- output.writeStringStringMap(Collections.<String,String>emptyMap());- output.writeStringSet(si.files());-- success = true;- } finally {- if (!success) {- IOUtils.closeWhileHandlingException(output);- // TODO: why must we do this? do we not get tracking dir wrapper?- IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);- } else {- output.close();- }- }- }-}diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.javaindex 79268d75eae..d07e370ad57 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java@@ -1,17 +1,13 @@package org.apache.lucene.codecs.lucene41;-import java.io.IOException;-import org.apache.lucene.codecs.DocValuesFormat;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.codecs.NormsFormat;import org.apache.lucene.codecs.SegmentInfoFormat;import org.apache.lucene.codecs.StoredFieldsFormat;import org.apache.lucene.codecs.TermVectorsFormat;-import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosFormat;-import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosWriter;import org.apache.lucene.codecs.lucene40.Lucene40RWDocValuesFormat;+import org.apache.lucene.codecs.lucene40.Lucene40RWFieldInfosFormat;import org.apache.lucene.codecs.lucene40.Lucene40RWNormsFormat;import org.apache.lucene.codecs.lucene40.Lucene40RWSegmentInfoFormat;import org.apache.lucene.codecs.lucene40.Lucene40RWTermVectorsFormat;@@ -40,13 +36,7 @@ import org.apache.lucene.codecs.lucene40.Lucene40RWTermVectorsFormat;@Deprecatedpublic final class Lucene41RWCodec extends Lucene41Codec {private final StoredFieldsFormat fieldsFormat = new Lucene41RWStoredFieldsFormat();- private final FieldInfosFormat fieldInfos = new Lucene40FieldInfosFormat() {- @Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {- return new Lucene40FieldInfosWriter();- }- };-+ private final FieldInfosFormat fieldInfos = new Lucene40RWFieldInfosFormat();private final DocValuesFormat docValues = new Lucene40RWDocValuesFormat();private final NormsFormat norms = new Lucene40RWNormsFormat();private final TermVectorsFormat vectors = new Lucene40RWTermVectorsFormat();diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.javaindex aa1cf385eca..c708d114a21 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.java@@ -17,11 +17,8 @@ package org.apache.lucene.codecs.lucene42;* limitations under the License.*/-import java.io.IOException;-import org.apache.lucene.codecs.DocValuesFormat;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.codecs.NormsFormat;import org.apache.lucene.codecs.SegmentInfoFormat;import org.apache.lucene.codecs.StoredFieldsFormat;@@ -39,13 +36,7 @@ public final class Lucene42RWCodec extends Lucene42Codec {private static final DocValuesFormat dv = new Lucene42RWDocValuesFormat();private static final NormsFormat norms = new Lucene42RWNormsFormat();private static final StoredFieldsFormat storedFields = new Lucene41RWStoredFieldsFormat();-- private final FieldInfosFormat fieldInfosFormat = new Lucene42FieldInfosFormat() {- @Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {- return new Lucene42FieldInfosWriter();- }- };+ private static final FieldInfosFormat fieldInfosFormat = new Lucene42RWFieldInfosFormat();@Overridepublic DocValuesFormat getDocValuesFormatForField(String field) {diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42RWFieldInfosFormat.javasimilarity index 96%rename from lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosWriter.javarename to lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42RWFieldInfosFormat.javaindex ab9862725e3..147330b0ca7 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42FieldInfosWriter.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene42/Lucene42RWFieldInfosFormat.java@@ -20,7 +20,6 @@ package org.apache.lucene.codecs.lucene42;import java.io.IOException;import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.index.FieldInfo.DocValuesType;import org.apache.lucene.index.FieldInfo.IndexOptions;import org.apache.lucene.index.FieldInfo;@@ -37,10 +36,10 @@ import org.apache.lucene.util.IOUtils;* @deprecated for test purposes only*/@Deprecated-public final class Lucene42FieldInfosWriter extends FieldInfosWriter {+public final class Lucene42RWFieldInfosFormat extends Lucene42FieldInfosFormat {/** Sole constructor. */- public Lucene42FieldInfosWriter() {+ public Lucene42RWFieldInfosFormat() {}@Overridediff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.javaindex 43bf33f3bcd..a2b2ef45964 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java@@ -17,19 +17,15 @@ package org.apache.lucene.codecs.lucene45;* limitations under the License.*/-import java.io.IOException;-import org.apache.lucene.codecs.DocValuesFormat;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.codecs.NormsFormat;import org.apache.lucene.codecs.SegmentInfoFormat;import org.apache.lucene.codecs.StoredFieldsFormat;import org.apache.lucene.codecs.TermVectorsFormat;import org.apache.lucene.codecs.lucene40.Lucene40RWSegmentInfoFormat;import org.apache.lucene.codecs.lucene41.Lucene41RWStoredFieldsFormat;-import org.apache.lucene.codecs.lucene42.Lucene42FieldInfosFormat;-import org.apache.lucene.codecs.lucene42.Lucene42FieldInfosWriter;+import org.apache.lucene.codecs.lucene42.Lucene42RWFieldInfosFormat;import org.apache.lucene.codecs.lucene42.Lucene42RWNormsFormat;import org.apache.lucene.codecs.lucene42.Lucene42RWTermVectorsFormat;@@ -39,12 +35,7 @@ import org.apache.lucene.codecs.lucene42.Lucene42RWTermVectorsFormat;@SuppressWarnings("deprecation")public final class Lucene45RWCodec extends Lucene45Codec {- private final FieldInfosFormat fieldInfosFormat = new Lucene42FieldInfosFormat() {- @Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {- return new Lucene42FieldInfosWriter();- }- };+ private static final FieldInfosFormat fieldInfosFormat = new Lucene42RWFieldInfosFormat();@Overridepublic FieldInfosFormat fieldInfosFormat() {diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene46/Lucene46RWSegmentInfoFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene46/Lucene46RWSegmentInfoFormat.javaindex b57f30c5ba2..b5788de3361 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene46/Lucene46RWSegmentInfoFormat.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene46/Lucene46RWSegmentInfoFormat.java@@ -17,7 +17,16 @@ package org.apache.lucene.codecs.lucene46;* limitations under the License.*/-import org.apache.lucene.codecs.SegmentInfoWriter;+import java.io.IOException;++import org.apache.lucene.codecs.CodecUtil;+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.IOUtils;+import org.apache.lucene.util.Version;/*** Read-Write version of 4.6 segmentinfo format for testing@@ -26,7 +35,36 @@ import org.apache.lucene.codecs.SegmentInfoWriter;@Deprecatedpublic final class Lucene46RWSegmentInfoFormat extends Lucene46SegmentInfoFormat {@Override- public SegmentInfoWriter getSegmentInfoWriter() {- return new Lucene46SegmentInfoWriter();+ public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene46SegmentInfoFormat.SI_EXTENSION);+ si.addFile(fileName);++ final IndexOutput output = dir.createOutput(fileName, ioContext);++ boolean success = false;+ try {+ CodecUtil.writeHeader(output, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_CURRENT);+ Version version = si.getVersion();+ if (version.major < 4) {+ throw new IllegalArgumentException("invalid major version: should be >= 4 but got: " + version.major + " segment=" + si);+ }+ // Write the Lucene version that created this segment, since 3.1+ output.writeString(version.toString());+ output.writeInt(si.getDocCount());++ output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));+ output.writeStringStringMap(si.getDiagnostics());+ output.writeStringSet(si.files());+ CodecUtil.writeFooter(output);+ success = true;+ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(output);+ // TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?+ IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);+ } else {+ output.close();+ }+ }}}diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoWriter.javadeleted file mode 100755index dcd9e4e31d5..00000000000--- a/lucene/backward-codecs/src/test/org/apache/lucene/codecs/lucene46/Lucene46SegmentInfoWriter.java+++ /dev/null@@ -1,77 +0,0 @@-package org.apache.lucene.codecs.lucene46;--/*- * 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 org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.SegmentInfoWriter;-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.IOUtils;-import org.apache.lucene.util.Version;--/**- * Writer for 4.0 segmentinfo format for testing- * @deprecated for test purposes only- */-@Deprecated-final class Lucene46SegmentInfoWriter extends SegmentInfoWriter {-- /** Sole constructor. */- public Lucene46SegmentInfoWriter() {- }-- /** Save a single segment's info. */- @Override- public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {- final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene46SegmentInfoFormat.SI_EXTENSION);- si.addFile(fileName);-- final IndexOutput output = dir.createOutput(fileName, ioContext);-- boolean success = false;- try {- CodecUtil.writeHeader(output, Lucene46SegmentInfoFormat.CODEC_NAME, Lucene46SegmentInfoFormat.VERSION_CURRENT);- Version version = si.getVersion();- if (version.major < 4) {- throw new IllegalArgumentException("invalid major version: should be >= 4 but got: " + version.major + " segment=" + si);- }- // Write the Lucene version that created this segment, since 3.1- output.writeString(version.toString());- output.writeInt(si.getDocCount());-- output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));- output.writeStringStringMap(si.getDiagnostics());- output.writeStringSet(si.files());- CodecUtil.writeFooter(output);- success = true;- } finally {- if (!success) {- IOUtils.closeWhileHandlingException(output);- // TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?- IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);- } else {- output.close();- }- }- }-}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosFormat.javaindex efe9ff4d320..ccb826172b2 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosFormat.java@@ -18,10 +18,26 @@ package org.apache.lucene.codecs.simpletext;*/import java.io.IOException;+import java.nio.charset.StandardCharsets;+import java.util.Collections;+import java.util.HashMap;+import java.util.Map;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.codecs.FieldInfosWriter;+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.FieldInfo.DocValuesType;+import org.apache.lucene.index.FieldInfo.IndexOptions;+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.BytesRef;+import org.apache.lucene.util.BytesRefBuilder;+import org.apache.lucene.util.IOUtils;+import org.apache.lucene.util.StringHelper;/*** plaintext field infos format@@ -30,16 +46,220 @@ import org.apache.lucene.codecs.FieldInfosWriter;* @lucene.experimental*/public class SimpleTextFieldInfosFormat extends FieldInfosFormat {- private final FieldInfosReader reader = new SimpleTextFieldInfosReader();- private final FieldInfosWriter writer = new SimpleTextFieldInfosWriter();-++ /** Extension of field infos */+ static final String FIELD_INFOS_EXTENSION = "inf";++ static final BytesRef NUMFIELDS = new BytesRef("number of fields ");+ static final BytesRef NAME = new BytesRef(" name ");+ static final BytesRef NUMBER = new BytesRef(" number ");+ static final BytesRef ISINDEXED = new BytesRef(" indexed ");+ static final BytesRef STORETV = new BytesRef(" term vectors ");+ static final BytesRef STORETVPOS = new BytesRef(" term vector positions ");+ static final BytesRef STORETVOFF = new BytesRef(" term vector offsets ");+ static final BytesRef PAYLOADS = new BytesRef(" payloads ");+ static final BytesRef NORMS = new BytesRef(" norms ");+ static final BytesRef NORMS_TYPE = new BytesRef(" norms type ");+ static final BytesRef DOCVALUES = new BytesRef(" doc values ");+ static final BytesRef DOCVALUES_GEN = new BytesRef(" doc values gen ");+ static final BytesRef INDEXOPTIONS = new BytesRef(" index options ");+ static final BytesRef NUM_ATTS = new BytesRef(" attributes ");+ static final BytesRef ATT_KEY = new BytesRef(" key ");+ static final BytesRef ATT_VALUE = new BytesRef(" value ");+@Override- public FieldInfosReader getFieldInfosReader() throws IOException {- return reader;+ public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, FIELD_INFOS_EXTENSION);+ ChecksumIndexInput input = directory.openChecksumInput(fileName, iocontext);+ BytesRefBuilder scratch = new BytesRefBuilder();++ boolean success = false;+ try {++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), NUMFIELDS);+ final int size = Integer.parseInt(readString(NUMFIELDS.length, scratch));+ FieldInfo infos[] = new FieldInfo[size];++ for (int i = 0; i < size; i++) {+ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), NAME);+ String name = readString(NAME.length, scratch);++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), NUMBER);+ int fieldNumber = Integer.parseInt(readString(NUMBER.length, scratch));++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), ISINDEXED);+ boolean isIndexed = Boolean.parseBoolean(readString(ISINDEXED.length, scratch));++ final IndexOptions indexOptions;+ if (isIndexed) {+ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), INDEXOPTIONS);+ indexOptions = IndexOptions.valueOf(readString(INDEXOPTIONS.length, scratch));+ } else {+ indexOptions = null;+ }++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), STORETV);+ boolean storeTermVector = Boolean.parseBoolean(readString(STORETV.length, scratch));++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), PAYLOADS);+ boolean storePayloads = Boolean.parseBoolean(readString(PAYLOADS.length, scratch));++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), NORMS);+ boolean omitNorms = !Boolean.parseBoolean(readString(NORMS.length, scratch));++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), NORMS_TYPE);+ String nrmType = readString(NORMS_TYPE.length, scratch);+ final DocValuesType normsType = docValuesType(nrmType);++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), DOCVALUES);+ String dvType = readString(DOCVALUES.length, scratch);+ final DocValuesType docValuesType = docValuesType(dvType);++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), DOCVALUES_GEN);+ final long dvGen = Long.parseLong(readString(DOCVALUES_GEN.length, scratch));++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), NUM_ATTS);+ int numAtts = Integer.parseInt(readString(NUM_ATTS.length, scratch));+ Map<String,String> atts = new HashMap<>();++ for (int j = 0; j < numAtts; j++) {+ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), ATT_KEY);+ String key = readString(ATT_KEY.length, scratch);++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), ATT_VALUE);+ String value = readString(ATT_VALUE.length, scratch);+ atts.put(key, value);+ }++ infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,+ omitNorms, storePayloads, indexOptions, docValuesType, normsType, dvGen, Collections.unmodifiableMap(atts));+ }++ SimpleTextUtil.checkFooter(input);++ FieldInfos fieldInfos = new FieldInfos(infos);+ success = true;+ return fieldInfos;+ } finally {+ if (success) {+ input.close();+ } else {+ IOUtils.closeWhileHandlingException(input);+ }+ }+ }++ public DocValuesType docValuesType(String dvType) {+ if ("false".equals(dvType)) {+ return null;+ } else {+ return DocValuesType.valueOf(dvType);+ }+ }++ private String readString(int offset, BytesRefBuilder scratch) {+ return new String(scratch.bytes(), offset, scratch.length()-offset, StandardCharsets.UTF_8);}@Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {- return writer;+ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, FIELD_INFOS_EXTENSION);+ IndexOutput out = directory.createOutput(fileName, context);+ BytesRefBuilder scratch = new BytesRefBuilder();+ boolean success = false;+ try {+ SimpleTextUtil.write(out, NUMFIELDS);+ SimpleTextUtil.write(out, Integer.toString(infos.size()), scratch);+ SimpleTextUtil.writeNewline(out);++ for (FieldInfo fi : infos) {+ SimpleTextUtil.write(out, NAME);+ SimpleTextUtil.write(out, fi.name, scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, NUMBER);+ SimpleTextUtil.write(out, Integer.toString(fi.number), scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, ISINDEXED);+ SimpleTextUtil.write(out, Boolean.toString(fi.isIndexed()), scratch);+ SimpleTextUtil.writeNewline(out);++ if (fi.isIndexed()) {+ assert fi.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();+ SimpleTextUtil.write(out, INDEXOPTIONS);+ SimpleTextUtil.write(out, fi.getIndexOptions().toString(), scratch);+ SimpleTextUtil.writeNewline(out);+ }++ SimpleTextUtil.write(out, STORETV);+ SimpleTextUtil.write(out, Boolean.toString(fi.hasVectors()), scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, PAYLOADS);+ SimpleTextUtil.write(out, Boolean.toString(fi.hasPayloads()), scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, NORMS);+ SimpleTextUtil.write(out, Boolean.toString(!fi.omitsNorms()), scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, NORMS_TYPE);+ SimpleTextUtil.write(out, getDocValuesType(fi.getNormType()), scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, DOCVALUES);+ SimpleTextUtil.write(out, getDocValuesType(fi.getDocValuesType()), scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, DOCVALUES_GEN);+ SimpleTextUtil.write(out, Long.toString(fi.getDocValuesGen()), scratch);+ SimpleTextUtil.writeNewline(out);++ Map<String,String> atts = fi.attributes();+ int numAtts = atts == null ? 0 : atts.size();+ SimpleTextUtil.write(out, NUM_ATTS);+ SimpleTextUtil.write(out, Integer.toString(numAtts), scratch);+ SimpleTextUtil.writeNewline(out);++ if (numAtts > 0) {+ for (Map.Entry<String,String> entry : atts.entrySet()) {+ SimpleTextUtil.write(out, ATT_KEY);+ SimpleTextUtil.write(out, entry.getKey(), scratch);+ SimpleTextUtil.writeNewline(out);++ SimpleTextUtil.write(out, ATT_VALUE);+ SimpleTextUtil.write(out, entry.getValue(), scratch);+ SimpleTextUtil.writeNewline(out);+ }+ }+ }+ SimpleTextUtil.writeChecksum(out, scratch);+ success = true;+ } finally {+ if (success) {+ out.close();+ } else {+ IOUtils.closeWhileHandlingException(out);+ }+ }+ }++ private static String getDocValuesType(DocValuesType type) {+ return type == null ? "false" : type.toString();}}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.javadeleted file mode 100644index b9645092af4..00000000000--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosReader.java+++ /dev/null@@ -1,157 +0,0 @@-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 java.util.Collections;-import java.util.HashMap;-import java.util.Map;--import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.index.FieldInfo;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.IndexFileNames;-import org.apache.lucene.index.FieldInfo.IndexOptions;-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.BytesRefBuilder;-import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.StringHelper;--import static org.apache.lucene.codecs.simpletext.SimpleTextFieldInfosWriter.*;--/**- * reads plaintext field infos files- * <p>- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>- * @lucene.experimental- */-public class SimpleTextFieldInfosReader extends FieldInfosReader {-- @Override- public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, FIELD_INFOS_EXTENSION);- ChecksumIndexInput input = directory.openChecksumInput(fileName, iocontext);- BytesRefBuilder scratch = new BytesRefBuilder();-- boolean success = false;- try {-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), NUMFIELDS);- final int size = Integer.parseInt(readString(NUMFIELDS.length, scratch));- FieldInfo infos[] = new FieldInfo[size];-- for (int i = 0; i < size; i++) {- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), NAME);- String name = readString(NAME.length, scratch);-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), NUMBER);- int fieldNumber = Integer.parseInt(readString(NUMBER.length, scratch));-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), ISINDEXED);- boolean isIndexed = Boolean.parseBoolean(readString(ISINDEXED.length, scratch));-- final IndexOptions indexOptions;- if (isIndexed) {- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), INDEXOPTIONS);- indexOptions = IndexOptions.valueOf(readString(INDEXOPTIONS.length, scratch));- } else {- indexOptions = null;- }-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), STORETV);- boolean storeTermVector = Boolean.parseBoolean(readString(STORETV.length, scratch));-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), PAYLOADS);- boolean storePayloads = Boolean.parseBoolean(readString(PAYLOADS.length, scratch));-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), NORMS);- boolean omitNorms = !Boolean.parseBoolean(readString(NORMS.length, scratch));-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), NORMS_TYPE);- String nrmType = readString(NORMS_TYPE.length, scratch);- final DocValuesType normsType = docValuesType(nrmType);-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), DOCVALUES);- String dvType = readString(DOCVALUES.length, scratch);- final DocValuesType docValuesType = docValuesType(dvType);-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), DOCVALUES_GEN);- final long dvGen = Long.parseLong(readString(DOCVALUES_GEN.length, scratch));-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), NUM_ATTS);- int numAtts = Integer.parseInt(readString(NUM_ATTS.length, scratch));- Map<String,String> atts = new HashMap<>();-- for (int j = 0; j < numAtts; j++) {- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), ATT_KEY);- String key = readString(ATT_KEY.length, scratch);-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), ATT_VALUE);- String value = readString(ATT_VALUE.length, scratch);- atts.put(key, value);- }-- infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector,- omitNorms, storePayloads, indexOptions, docValuesType, normsType, dvGen, Collections.unmodifiableMap(atts));- }-- SimpleTextUtil.checkFooter(input);-- FieldInfos fieldInfos = new FieldInfos(infos);- success = true;- return fieldInfos;- } finally {- if (success) {- input.close();- } else {- IOUtils.closeWhileHandlingException(input);- }- }- }-- public DocValuesType docValuesType(String dvType) {- if ("false".equals(dvType)) {- return null;- } else {- return DocValuesType.valueOf(dvType);- }- }-- private String readString(int offset, BytesRefBuilder scratch) {- return new String(scratch.bytes(), offset, scratch.length()-offset, StandardCharsets.UTF_8);- }-}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.javadeleted file mode 100644index e0173f87f45..00000000000--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldInfosWriter.java+++ /dev/null@@ -1,151 +0,0 @@-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 org.apache.lucene.codecs.FieldInfosWriter;-import org.apache.lucene.index.FieldInfo;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.IndexFileNames;-import org.apache.lucene.index.FieldInfo.IndexOptions;-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.BytesRefBuilder;-import org.apache.lucene.util.IOUtils;--/**- * writes plaintext field infos files- * <p>- * <b><font color="red">FOR RECREATIONAL USE ONLY</font></B>- * @lucene.experimental- */-public class SimpleTextFieldInfosWriter extends FieldInfosWriter {-- /** Extension of field infos */- static final String FIELD_INFOS_EXTENSION = "inf";-- static final BytesRef NUMFIELDS = new BytesRef("number of fields ");- static final BytesRef NAME = new BytesRef(" name ");- static final BytesRef NUMBER = new BytesRef(" number ");- static final BytesRef ISINDEXED = new BytesRef(" indexed ");- static final BytesRef STORETV = new BytesRef(" term vectors ");- static final BytesRef STORETVPOS = new BytesRef(" term vector positions ");- static final BytesRef STORETVOFF = new BytesRef(" term vector offsets ");- static final BytesRef PAYLOADS = new BytesRef(" payloads ");- static final BytesRef NORMS = new BytesRef(" norms ");- static final BytesRef NORMS_TYPE = new BytesRef(" norms type ");- static final BytesRef DOCVALUES = new BytesRef(" doc values ");- static final BytesRef DOCVALUES_GEN = new BytesRef(" doc values gen ");- static final BytesRef INDEXOPTIONS = new BytesRef(" index options ");- static final BytesRef NUM_ATTS = new BytesRef(" attributes ");- final static BytesRef ATT_KEY = new BytesRef(" key ");- final static BytesRef ATT_VALUE = new BytesRef(" value ");-- @Override- public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, FIELD_INFOS_EXTENSION);- IndexOutput out = directory.createOutput(fileName, context);- BytesRefBuilder scratch = new BytesRefBuilder();- boolean success = false;- try {- SimpleTextUtil.write(out, NUMFIELDS);- SimpleTextUtil.write(out, Integer.toString(infos.size()), scratch);- SimpleTextUtil.writeNewline(out);-- for (FieldInfo fi : infos) {- SimpleTextUtil.write(out, NAME);- SimpleTextUtil.write(out, fi.name, scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, NUMBER);- SimpleTextUtil.write(out, Integer.toString(fi.number), scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, ISINDEXED);- SimpleTextUtil.write(out, Boolean.toString(fi.isIndexed()), scratch);- SimpleTextUtil.writeNewline(out);-- if (fi.isIndexed()) {- assert fi.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();- SimpleTextUtil.write(out, INDEXOPTIONS);- SimpleTextUtil.write(out, fi.getIndexOptions().toString(), scratch);- SimpleTextUtil.writeNewline(out);- }-- SimpleTextUtil.write(out, STORETV);- SimpleTextUtil.write(out, Boolean.toString(fi.hasVectors()), scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, PAYLOADS);- SimpleTextUtil.write(out, Boolean.toString(fi.hasPayloads()), scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, NORMS);- SimpleTextUtil.write(out, Boolean.toString(!fi.omitsNorms()), scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, NORMS_TYPE);- SimpleTextUtil.write(out, getDocValuesType(fi.getNormType()), scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, DOCVALUES);- SimpleTextUtil.write(out, getDocValuesType(fi.getDocValuesType()), scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, DOCVALUES_GEN);- SimpleTextUtil.write(out, Long.toString(fi.getDocValuesGen()), scratch);- SimpleTextUtil.writeNewline(out);-- Map<String,String> atts = fi.attributes();- int numAtts = atts == null ? 0 : atts.size();- SimpleTextUtil.write(out, NUM_ATTS);- SimpleTextUtil.write(out, Integer.toString(numAtts), scratch);- SimpleTextUtil.writeNewline(out);-- if (numAtts > 0) {- for (Map.Entry<String,String> entry : atts.entrySet()) {- SimpleTextUtil.write(out, ATT_KEY);- SimpleTextUtil.write(out, entry.getKey(), scratch);- SimpleTextUtil.writeNewline(out);-- SimpleTextUtil.write(out, ATT_VALUE);- SimpleTextUtil.write(out, entry.getValue(), scratch);- SimpleTextUtil.writeNewline(out);- }- }- }- SimpleTextUtil.writeChecksum(out, scratch);- success = true;- } finally {- if (success) {- out.close();- } else {- IOUtils.closeWhileHandlingException(out);- }- }- }-- private static String getDocValuesType(DocValuesType type) {- return type == null ? "false" : type.toString();- }-}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.javaindex 53440e7f3be..0b7e37c54a7 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java@@ -17,9 +17,28 @@ package org.apache.lucene.codecs.simpletext;* limitations under the License.*/+import java.io.IOException;+import java.nio.charset.StandardCharsets;+import java.text.ParseException;+import java.util.Arrays;+import java.util.HashMap;+import java.util.HashSet;+import java.util.Map;+import java.util.Set;+import org.apache.lucene.codecs.SegmentInfoFormat;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.codecs.SegmentInfoWriter;+import org.apache.lucene.index.CorruptIndexException;+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.store.IndexOutput;+import org.apache.lucene.util.BytesRef;+import org.apache.lucene.util.BytesRefBuilder;+import org.apache.lucene.util.IOUtils;+import org.apache.lucene.util.StringHelper;+import org.apache.lucene.util.Version;/*** plain text segments file format.@@ -28,18 +47,163 @@ import org.apache.lucene.codecs.SegmentInfoWriter;* @lucene.experimental*/public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {- private final SegmentInfoReader reader = new SimpleTextSegmentInfoReader();- private final SegmentInfoWriter writer = new SimpleTextSegmentInfoWriter();+ 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 ");+ final static BytesRef SI_ID = new BytesRef(" id ");public static final String SI_EXTENSION = "si";@Override- public SegmentInfoReader getSegmentInfoReader() {- return reader;+ public SegmentInfo read(Directory directory, String segmentName, IOContext context) throws IOException {+ BytesRefBuilder scratch = new BytesRefBuilder();+ String segFileName = IndexFileNames.segmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);+ ChecksumIndexInput input = directory.openChecksumInput(segFileName, context);+ boolean success = false;+ try {+ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_VERSION);+ final Version version;+ try {+ version = Version.parse(readString(SI_VERSION.length, scratch));+ } catch (ParseException pe) {+ throw new CorruptIndexException("unable to parse version string: " + pe.getMessage(), input, pe);+ }++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_DOCCOUNT);+ final int docCount = Integer.parseInt(readString(SI_DOCCOUNT.length, scratch));++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_USECOMPOUND);+ final boolean isCompoundFile = Boolean.parseBoolean(readString(SI_USECOMPOUND.length, scratch));++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), 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);+ assert StringHelper.startsWith(scratch.get(), SI_DIAG_KEY);+ String key = readString(SI_DIAG_KEY.length, scratch);++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_DIAG_VALUE);+ String value = readString(SI_DIAG_VALUE.length, scratch);+ diagnostics.put(key, value);+ }++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), 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);+ assert StringHelper.startsWith(scratch.get(), SI_FILE);+ String fileName = readString(SI_FILE.length, scratch);+ files.add(fileName);+ }++ SimpleTextUtil.readLine(input, scratch);+ assert StringHelper.startsWith(scratch.get(), SI_ID);+ final byte[] id = Arrays.copyOfRange(scratch.bytes(), SI_ID.length, scratch.length());++ SimpleTextUtil.checkFooter(input);++ SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,+ isCompoundFile, null, diagnostics, id);+ info.setFiles(files);+ success = true;+ return info;+ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(input);+ } else {+ input.close();+ }+ }}+ private String readString(int offset, BytesRefBuilder scratch) {+ return new String(scratch.bytes(), offset, scratch.length()-offset, StandardCharsets.UTF_8);+ }+@Override- public SegmentInfoWriter getSegmentInfoWriter() {- return writer;+ public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {++ String segFileName = IndexFileNames.segmentFileName(si.name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);+ si.addFile(segFileName);++ boolean success = false;+ IndexOutput output = dir.createOutput(segFileName, ioContext);++ try {+ BytesRefBuilder scratch = new BytesRefBuilder();++ SimpleTextUtil.write(output, SI_VERSION);+ SimpleTextUtil.write(output, si.getVersion().toString(), 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, Boolean.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.write(output, SI_ID);+ SimpleTextUtil.write(output, new BytesRef(si.getId()));+ SimpleTextUtil.writeNewline(output);++ SimpleTextUtil.writeChecksum(output, scratch);+ success = true;+ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(output);+ IOUtils.deleteFilesIgnoringExceptions(dir, segFileName);+ } else {+ output.close();+ }+ }}}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.javadeleted file mode 100644index 4e0f7db3947..00000000000--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoReader.java+++ /dev/null@@ -1,134 +0,0 @@-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 java.text.ParseException;-import java.util.Arrays;-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.CorruptIndexException;-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.BytesRefBuilder;-import org.apache.lucene.util.IOUtils;-import org.apache.lucene.util.StringHelper;-import org.apache.lucene.util.Version;--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_ID;-import static org.apache.lucene.codecs.simpletext.SimpleTextSegmentInfoWriter.SI_VERSION;--/**- * 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) throws IOException {- BytesRefBuilder scratch = new BytesRefBuilder();- String segFileName = IndexFileNames.segmentFileName(segmentName, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);- ChecksumIndexInput input = directory.openChecksumInput(segFileName, context);- boolean success = false;- try {- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), SI_VERSION);- final Version version;- try {- version = Version.parse(readString(SI_VERSION.length, scratch));- } catch (ParseException pe) {- throw new CorruptIndexException("unable to parse version string: " + pe.getMessage(), input, pe);- }-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), SI_DOCCOUNT);- final int docCount = Integer.parseInt(readString(SI_DOCCOUNT.length, scratch));-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), SI_USECOMPOUND);- final boolean isCompoundFile = Boolean.parseBoolean(readString(SI_USECOMPOUND.length, scratch));-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), 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);- assert StringHelper.startsWith(scratch.get(), SI_DIAG_KEY);- String key = readString(SI_DIAG_KEY.length, scratch);-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), SI_DIAG_VALUE);- String value = readString(SI_DIAG_VALUE.length, scratch);- diagnostics.put(key, value);- }-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), 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);- assert StringHelper.startsWith(scratch.get(), SI_FILE);- String fileName = readString(SI_FILE.length, scratch);- files.add(fileName);- }-- SimpleTextUtil.readLine(input, scratch);- assert StringHelper.startsWith(scratch.get(), SI_ID);- final byte[] id = Arrays.copyOfRange(scratch.bytes(), SI_ID.length, scratch.length());-- SimpleTextUtil.checkFooter(input);-- SegmentInfo info = new SegmentInfo(directory, version, segmentName, docCount,- isCompoundFile, null, diagnostics, id);- info.setFiles(files);- success = true;- return info;- } finally {- if (!success) {- IOUtils.closeWhileHandlingException(input);- } else {- input.close();- }- }- }-- private String readString(int offset, BytesRefBuilder scratch) {- return new String(scratch.bytes(), offset, scratch.length()-offset, StandardCharsets.UTF_8);- }-}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoWriter.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoWriter.javadeleted file mode 100644index 8a96854d2d8..00000000000--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoWriter.java+++ /dev/null@@ -1,123 +0,0 @@-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.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.BytesRefBuilder;-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 ");- final static BytesRef SI_ID = new BytesRef(" id ");-- @Override- public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {-- String segFileName = IndexFileNames.segmentFileName(si.name, "", SimpleTextSegmentInfoFormat.SI_EXTENSION);- si.addFile(segFileName);-- boolean success = false;- IndexOutput output = dir.createOutput(segFileName, ioContext);-- try {- BytesRefBuilder scratch = new BytesRefBuilder();-- SimpleTextUtil.write(output, SI_VERSION);- SimpleTextUtil.write(output, si.getVersion().toString(), 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, Boolean.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.write(output, SI_ID);- SimpleTextUtil.write(output, new BytesRef(si.getId()));- SimpleTextUtil.writeNewline(output);-- SimpleTextUtil.writeChecksum(output, scratch);- success = true;- } finally {- if (!success) {- IOUtils.closeWhileHandlingException(output);- IOUtils.deleteFilesIgnoringExceptions(dir, segFileName);- } else {- output.close();- }- }- }-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosFormat.javaindex 45ff741f307..3e21275f6f0 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosFormat.java@@ -20,6 +20,9 @@ package org.apache.lucene.codecs;import java.io.IOException;import org.apache.lucene.index.FieldInfos; // javadocs+import org.apache.lucene.index.SegmentInfo;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;/*** Encodes/decodes {@link FieldInfos}@@ -30,12 +33,11 @@ public abstract class FieldInfosFormat {* constructors, typically implicit.) */protected FieldInfosFormat() {}++ /** Read the {@link FieldInfos} previously written with {@link #write}. */+ public abstract FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException;- /** Returns a {@link FieldInfosReader} to read field infos- * from the index */- public abstract FieldInfosReader getFieldInfosReader() throws IOException;-- /** Returns a {@link FieldInfosWriter} to write field infos- * to the index */- public abstract FieldInfosWriter getFieldInfosWriter() throws IOException;+ /** Writes the provided {@link FieldInfos} to the+ * directory. */+ public abstract void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException;}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.javadeleted file mode 100644index c97df9b5ea3..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosReader.java+++ /dev/null@@ -1,40 +0,0 @@-package org.apache.lucene.codecs;--/*- * 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 org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.SegmentInfo;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;--/**- * Codec API for reading {@link FieldInfos}.- * @lucene.experimental- */-public abstract class FieldInfosReader {- /** Sole constructor. (For invocation by subclass- * constructors, typically implicit.) */- protected FieldInfosReader() {- }-- /** Read the {@link FieldInfos} previously written with {@link- * FieldInfosWriter}. */- public abstract FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException;-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.javadeleted file mode 100644index 59679e51174..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/FieldInfosWriter.java+++ /dev/null@@ -1,40 +0,0 @@-package org.apache.lucene.codecs;--/*- * 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 org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.SegmentInfo;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;--/**- * Codec API for writing {@link FieldInfos}.- * @lucene.experimental- */-public abstract class FieldInfosWriter {- /** Sole constructor. (For invocation by subclass- * constructors, typically implicit.) */- protected FieldInfosWriter() {- }-- /** Writes the provided {@link FieldInfos} to the- * directory. */- public abstract void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException;-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoFormat.javaindex 82a5043cf51..82af5551269 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoFormat.java@@ -17,7 +17,11 @@ package org.apache.lucene.codecs;* limitations under the License.*/+import java.io.IOException;+import org.apache.lucene.index.SegmentInfo;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;/*** Expert: Controls the format of the@@ -33,11 +37,18 @@ public abstract class SegmentInfoFormat {protected SegmentInfoFormat() {}- /** Returns the {@link SegmentInfoReader} for reading- * {@link SegmentInfo} instances. */- public abstract SegmentInfoReader getSegmentInfoReader();+ /**+ * Read {@link SegmentInfo} data from a directory.+ * @param directory directory to read from+ * @param segmentName name of the segment to read+ * @return infos instance to be populated with data+ * @throws IOException If an I/O error occurs+ */+ public abstract SegmentInfo read(Directory directory, String segmentName, IOContext context) throws IOException;- /** Returns the {@link SegmentInfoWriter} for writing- * {@link SegmentInfo} instances. */- public abstract SegmentInfoWriter getSegmentInfoWriter();+ /**+ * Write {@link SegmentInfo} data.+ * @throws IOException If an I/O error occurs+ */+ public abstract void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException;}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoReader.javadeleted file mode 100644index 98036230979..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoReader.java+++ /dev/null@@ -1,46 +0,0 @@-package org.apache.lucene.codecs;--/*- * 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 org.apache.lucene.index.SegmentInfo;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;--/**- * Specifies an API for classes that can read {@link SegmentInfo} information.- * @lucene.experimental- */--public abstract class SegmentInfoReader {-- /** Sole constructor. (For invocation by subclass- * constructors, typically implicit.) */- protected SegmentInfoReader() {- }-- /**- * Read {@link SegmentInfo} data from a directory.- * @param directory directory to read from- * @param segmentName name of the segment to read- * @return infos instance to be populated with data- * @throws IOException If an I/O error occurs- */- public abstract SegmentInfo read(Directory directory, String segmentName, IOContext context) throws IOException;-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoWriter.javadeleted file mode 100644index 09274e659d6..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/SegmentInfoWriter.java+++ /dev/null@@ -1,42 +0,0 @@-package org.apache.lucene.codecs;--/*- * 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 org.apache.lucene.index.SegmentInfo;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;--/**- * Specifies an API for classes that can write out {@link SegmentInfo} data.- * @lucene.experimental- */--public abstract class SegmentInfoWriter {- /** Sole constructor. (For invocation by subclass- * constructors, typically implicit.) */- protected SegmentInfoWriter() {- }-- /**- * Write {@link SegmentInfo} data.- * @throws IOException If an I/O error occurs- */- public abstract void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException;-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.javaindex 3f6c4014a9c..3dbe4877618 100755--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java@@ -18,14 +18,25 @@ package org.apache.lucene.codecs.lucene50;*/import java.io.IOException;+import java.util.Collections;+import java.util.Map;import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.DocValuesFormat;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.codecs.FieldInfosWriter;+import org.apache.lucene.index.CorruptIndexException;+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.FieldInfo.DocValuesType;+import org.apache.lucene.index.FieldInfo.IndexOptions;+import org.apache.lucene.store.ChecksumIndexInput;import org.apache.lucene.store.DataOutput;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.IndexInput;+import org.apache.lucene.store.IndexOutput;/*** Lucene 5.0 Field Infos format.@@ -91,21 +102,148 @@ import org.apache.lucene.store.DataOutput;* @lucene.experimental*/public final class Lucene50FieldInfosFormat extends FieldInfosFormat {- private final FieldInfosReader reader = new Lucene50FieldInfosReader();- private final FieldInfosWriter writer = new Lucene50FieldInfosWriter();/** Sole constructor. */public Lucene50FieldInfosFormat() {}-+@Override- public FieldInfosReader getFieldInfosReader() throws IOException {- return reader;+ public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene50FieldInfosFormat.EXTENSION);+ try (ChecksumIndexInput input = directory.openChecksumInput(fileName, context)) {+ Throwable priorE = null;+ FieldInfo infos[] = null;+ try {+ CodecUtil.checkSegmentHeader(input, Lucene50FieldInfosFormat.CODEC_NAME,+ Lucene50FieldInfosFormat.FORMAT_START,+ Lucene50FieldInfosFormat.FORMAT_CURRENT,+ segmentInfo.getId(), segmentSuffix);++ final int size = input.readVInt(); //read in the size+ infos = new FieldInfo[size];++ for (int i = 0; i < size; i++) {+ String name = input.readString();+ final int fieldNumber = input.readVInt();+ if (fieldNumber < 0) {+ throw new CorruptIndexException("invalid field number for field: " + name + ", fieldNumber=" + fieldNumber, input);+ }+ byte bits = input.readByte();+ boolean isIndexed = (bits & Lucene50FieldInfosFormat.IS_INDEXED) != 0;+ boolean storeTermVector = (bits & Lucene50FieldInfosFormat.STORE_TERMVECTOR) != 0;+ boolean omitNorms = (bits & Lucene50FieldInfosFormat.OMIT_NORMS) != 0;+ boolean storePayloads = (bits & Lucene50FieldInfosFormat.STORE_PAYLOADS) != 0;+ final IndexOptions indexOptions;+ if (!isIndexed) {+ indexOptions = null;+ } else if ((bits & Lucene50FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_ONLY;+ } else if ((bits & Lucene50FieldInfosFormat.OMIT_POSITIONS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS;+ } else if ((bits & Lucene50FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;+ } else {+ indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;+ }++ // DV Types are packed in one byte+ byte val = input.readByte();+ final DocValuesType docValuesType = getDocValuesType(input, (byte) (val & 0x0F));+ final DocValuesType normsType = getDocValuesType(input, (byte) ((val >>> 4) & 0x0F));+ final long dvGen = input.readLong();+ final Map<String,String> attributes = input.readStringStringMap();+ try {+ infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, omitNorms, storePayloads,+ indexOptions, docValuesType, normsType, dvGen, Collections.unmodifiableMap(attributes));+ infos[i].checkConsistency();+ } catch (IllegalStateException e) {+ throw new CorruptIndexException("invalid fieldinfo for field: " + name + ", fieldNumber=" + fieldNumber, input, e);+ }+ }+ } catch (Throwable exception) {+ priorE = exception;+ } finally {+ CodecUtil.checkFooter(input, priorE);+ }+ return new FieldInfos(infos);+ }+ }++ private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {+ if (b == 0) {+ return null;+ } else if (b == 1) {+ return DocValuesType.NUMERIC;+ } else if (b == 2) {+ return DocValuesType.BINARY;+ } else if (b == 3) {+ return DocValuesType.SORTED;+ } else if (b == 4) {+ return DocValuesType.SORTED_SET;+ } else if (b == 5) {+ return DocValuesType.SORTED_NUMERIC;+ } else {+ throw new CorruptIndexException("invalid docvalues byte: " + b, input);+ }}@Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {- return writer;+ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene50FieldInfosFormat.EXTENSION);+ try (IndexOutput output = directory.createOutput(fileName, context)) {+ CodecUtil.writeSegmentHeader(output, Lucene50FieldInfosFormat.CODEC_NAME, Lucene50FieldInfosFormat.FORMAT_CURRENT, segmentInfo.getId(), segmentSuffix);+ output.writeVInt(infos.size());+ for (FieldInfo fi : infos) {+ fi.checkConsistency();+ IndexOptions indexOptions = fi.getIndexOptions();+ byte bits = 0x0;+ if (fi.hasVectors()) bits |= Lucene50FieldInfosFormat.STORE_TERMVECTOR;+ if (fi.omitsNorms()) bits |= Lucene50FieldInfosFormat.OMIT_NORMS;+ if (fi.hasPayloads()) bits |= Lucene50FieldInfosFormat.STORE_PAYLOADS;+ if (fi.isIndexed()) {+ bits |= Lucene50FieldInfosFormat.IS_INDEXED;+ assert indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();+ if (indexOptions == IndexOptions.DOCS_ONLY) {+ bits |= Lucene50FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;+ } else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {+ bits |= Lucene50FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;+ } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) {+ bits |= Lucene50FieldInfosFormat.OMIT_POSITIONS;+ }+ }+ output.writeString(fi.name);+ output.writeVInt(fi.number);+ output.writeByte(bits);++ // pack the DV types in one byte+ final byte dv = docValuesByte(fi.getDocValuesType());+ final byte nrm = docValuesByte(fi.getNormType());+ assert (dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0;+ byte val = (byte) (0xff & ((nrm << 4) | dv));+ output.writeByte(val);+ output.writeLong(fi.getDocValuesGen());+ output.writeStringStringMap(fi.attributes());+ }+ CodecUtil.writeFooter(output);+ }+ }++ private static byte docValuesByte(DocValuesType type) {+ if (type == null) {+ return 0;+ } else if (type == DocValuesType.NUMERIC) {+ return 1;+ } else if (type == DocValuesType.BINARY) {+ return 2;+ } else if (type == DocValuesType.SORTED) {+ return 3;+ } else if (type == DocValuesType.SORTED_SET) {+ return 4;+ } else if (type == DocValuesType.SORTED_NUMERIC) {+ return 5;+ } else {+ throw new AssertionError();+ }}/** Extension of field infos */diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosReader.javadeleted file mode 100755index 0cc46c0d575..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosReader.java+++ /dev/null@@ -1,129 +0,0 @@-package org.apache.lucene.codecs.lucene50;--/*- * 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.Collections;-import java.util.Map;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.index.CorruptIndexException;-import org.apache.lucene.index.FieldInfo;-import org.apache.lucene.index.FieldInfos;-import org.apache.lucene.index.IndexFileNames;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfo.IndexOptions;-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.store.IndexInput;--/**- * Lucene 5.0 FieldInfos reader.- *- * @lucene.experimental- * @see Lucene50FieldInfosFormat- */-final class Lucene50FieldInfosReader extends FieldInfosReader {-- /** Sole constructor. */- public Lucene50FieldInfosReader() {- }-- @Override- public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene50FieldInfosFormat.EXTENSION);- try (ChecksumIndexInput input = directory.openChecksumInput(fileName, context)) {- Throwable priorE = null;- FieldInfo infos[] = null;- try {- CodecUtil.checkSegmentHeader(input, Lucene50FieldInfosFormat.CODEC_NAME,- Lucene50FieldInfosFormat.FORMAT_START,- Lucene50FieldInfosFormat.FORMAT_CURRENT,- segmentInfo.getId(), segmentSuffix);-- final int size = input.readVInt(); //read in the size- infos = new FieldInfo[size];-- for (int i = 0; i < size; i++) {- String name = input.readString();- final int fieldNumber = input.readVInt();- if (fieldNumber < 0) {- throw new CorruptIndexException("invalid field number for field: " + name + ", fieldNumber=" + fieldNumber, input);- }- byte bits = input.readByte();- boolean isIndexed = (bits & Lucene50FieldInfosFormat.IS_INDEXED) != 0;- boolean storeTermVector = (bits & Lucene50FieldInfosFormat.STORE_TERMVECTOR) != 0;- boolean omitNorms = (bits & Lucene50FieldInfosFormat.OMIT_NORMS) != 0;- boolean storePayloads = (bits & Lucene50FieldInfosFormat.STORE_PAYLOADS) != 0;- final IndexOptions indexOptions;- if (!isIndexed) {- indexOptions = null;- } else if ((bits & Lucene50FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_ONLY;- } else if ((bits & Lucene50FieldInfosFormat.OMIT_POSITIONS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS;- } else if ((bits & Lucene50FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;- } else {- indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;- }-- // DV Types are packed in one byte- byte val = input.readByte();- final DocValuesType docValuesType = getDocValuesType(input, (byte) (val & 0x0F));- final DocValuesType normsType = getDocValuesType(input, (byte) ((val >>> 4) & 0x0F));- final long dvGen = input.readLong();- final Map<String,String> attributes = input.readStringStringMap();- try {- infos[i] = new FieldInfo(name, isIndexed, fieldNumber, storeTermVector, omitNorms, storePayloads,- indexOptions, docValuesType, normsType, dvGen, Collections.unmodifiableMap(attributes));- infos[i].checkConsistency();- } catch (IllegalStateException e) {- throw new CorruptIndexException("invalid fieldinfo for field: " + name + ", fieldNumber=" + fieldNumber, input, e);- }- }- } catch (Throwable exception) {- priorE = exception;- } finally {- CodecUtil.checkFooter(input, priorE);- }- return new FieldInfos(infos);- }- }-- private static DocValuesType getDocValuesType(IndexInput input, byte b) throws IOException {- if (b == 0) {- return null;- } else if (b == 1) {- return DocValuesType.NUMERIC;- } else if (b == 2) {- return DocValuesType.BINARY;- } else if (b == 3) {- return DocValuesType.SORTED;- } else if (b == 4) {- return DocValuesType.SORTED_SET;- } else if (b == 5) {- return DocValuesType.SORTED_NUMERIC;- } else {- throw new CorruptIndexException("invalid docvalues byte: " + b, input);- }- }-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosWriter.javadeleted file mode 100755index 316c5e4b8c3..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosWriter.java+++ /dev/null@@ -1,104 +0,0 @@-package org.apache.lucene.codecs.lucene50;--/*- * 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 org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.FieldInfosWriter;-import org.apache.lucene.index.FieldInfo.DocValuesType;-import org.apache.lucene.index.FieldInfo.IndexOptions;-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.store.IndexOutput;-import org.apache.lucene.store.Directory;-import org.apache.lucene.store.IOContext;--/**- * Lucene 5.0 FieldInfos writer.- *- * @see Lucene50FieldInfosFormat- * @lucene.experimental- */-final class Lucene50FieldInfosWriter extends FieldInfosWriter {-- /** Sole constructor. */- public Lucene50FieldInfosWriter() {- }-- @Override- public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, Lucene50FieldInfosFormat.EXTENSION);- try (IndexOutput output = directory.createOutput(fileName, context)) {- CodecUtil.writeSegmentHeader(output, Lucene50FieldInfosFormat.CODEC_NAME, Lucene50FieldInfosFormat.FORMAT_CURRENT, segmentInfo.getId(), segmentSuffix);- output.writeVInt(infos.size());- for (FieldInfo fi : infos) {- fi.checkConsistency();- IndexOptions indexOptions = fi.getIndexOptions();- byte bits = 0x0;- if (fi.hasVectors()) bits |= Lucene50FieldInfosFormat.STORE_TERMVECTOR;- if (fi.omitsNorms()) bits |= Lucene50FieldInfosFormat.OMIT_NORMS;- if (fi.hasPayloads()) bits |= Lucene50FieldInfosFormat.STORE_PAYLOADS;- if (fi.isIndexed()) {- bits |= Lucene50FieldInfosFormat.IS_INDEXED;- assert indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();- if (indexOptions == IndexOptions.DOCS_ONLY) {- bits |= Lucene50FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;- } else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {- bits |= Lucene50FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;- } else if (indexOptions == IndexOptions.DOCS_AND_FREQS) {- bits |= Lucene50FieldInfosFormat.OMIT_POSITIONS;- }- }- output.writeString(fi.name);- output.writeVInt(fi.number);- output.writeByte(bits);-- // pack the DV types in one byte- final byte dv = docValuesByte(fi.getDocValuesType());- final byte nrm = docValuesByte(fi.getNormType());- assert (dv & (~0xF)) == 0 && (nrm & (~0x0F)) == 0;- byte val = (byte) (0xff & ((nrm << 4) | dv));- output.writeByte(val);- output.writeLong(fi.getDocValuesGen());- output.writeStringStringMap(fi.attributes());- }- CodecUtil.writeFooter(output);- }- }-- private static byte docValuesByte(DocValuesType type) {- if (type == null) {- return 0;- } else if (type == DocValuesType.NUMERIC) {- return 1;- } else if (type == DocValuesType.BINARY) {- return 2;- } else if (type == DocValuesType.SORTED) {- return 3;- } else if (type == DocValuesType.SORTED_SET) {- return 4;- } else if (type == DocValuesType.SORTED_NUMERIC) {- return 5;- } else {- throw new AssertionError();- }- }-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.javaindex 2127322f688..e32555cd4d6 100755--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java@@ -17,14 +17,25 @@ package org.apache.lucene.codecs.lucene50;* limitations under the License.*/+import java.io.IOException;+import java.util.Map;+import java.util.Set;+import org.apache.lucene.codecs.CodecUtil;import org.apache.lucene.codecs.SegmentInfoFormat;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.codecs.SegmentInfoWriter;+import org.apache.lucene.index.CorruptIndexException;+import org.apache.lucene.index.IndexFileNames;import org.apache.lucene.index.IndexWriter; // javadocsimport org.apache.lucene.index.SegmentInfo; // javadocsimport org.apache.lucene.index.SegmentInfos; // javadocs+import org.apache.lucene.store.ChecksumIndexInput;import org.apache.lucene.store.DataOutput; // javadocs+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.IOContext;+import org.apache.lucene.store.IndexOutput;+import org.apache.lucene.util.IOUtils;+import org.apache.lucene.util.StringHelper;+import org.apache.lucene.util.Version;/*** Lucene 5.0 Segment info format.@@ -67,21 +78,86 @@ import org.apache.lucene.store.DataOutput; // javadocs* @lucene.experimental*/public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {- private final SegmentInfoReader reader = new Lucene50SegmentInfoReader();- private final SegmentInfoWriter writer = new Lucene50SegmentInfoWriter();/** Sole constructor. */public Lucene50SegmentInfoFormat() {}@Override- public SegmentInfoReader getSegmentInfoReader() {- return reader;+ public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene50SegmentInfoFormat.SI_EXTENSION);+ try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {+ Throwable priorE = null;+ SegmentInfo si = null;+ try {+ CodecUtil.checkHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME,+ Lucene50SegmentInfoFormat.VERSION_START,+ Lucene50SegmentInfoFormat.VERSION_CURRENT);+ final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt());++ final int docCount = input.readInt();+ if (docCount < 0) {+ throw new CorruptIndexException("invalid docCount: " + docCount, input);+ }+ final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;+ final Map<String,String> diagnostics = input.readStringStringMap();+ final Set<String> files = input.readStringSet();++ byte[] id = new byte[StringHelper.ID_LENGTH];+ input.readBytes(id, 0, id.length);++ si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, id);+ si.setFiles(files);+ } catch (Throwable exception) {+ priorE = exception;+ } finally {+ CodecUtil.checkFooter(input, priorE);+ }+ return si;+ }}@Override- public SegmentInfoWriter getSegmentInfoWriter() {- return writer;+ public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {+ final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene50SegmentInfoFormat.SI_EXTENSION);+ si.addFile(fileName);++ boolean success = false;+ try (IndexOutput output = dir.createOutput(fileName, ioContext)) {+ CodecUtil.writeHeader(output, Lucene50SegmentInfoFormat.CODEC_NAME, Lucene50SegmentInfoFormat.VERSION_CURRENT);+ Version version = si.getVersion();+ if (version.major < 5) {+ throw new IllegalArgumentException("invalid major version: should be >= 5 but got: " + version.major + " segment=" + si);+ }+ // Write the Lucene version that created this segment, since 3.1+ output.writeInt(version.major);+ output.writeInt(version.minor);+ output.writeInt(version.bugfix);+ assert version.prerelease == 0;+ output.writeInt(si.getDocCount());++ output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));+ output.writeStringStringMap(si.getDiagnostics());+ Set<String> files = si.files();+ for (String file : files) {+ if (!IndexFileNames.parseSegmentName(file).equals(si.name)) {+ throw new IllegalArgumentException("invalid files: expected segment=" + si.name + ", got=" + files);+ }+ }+ output.writeStringSet(files);+ byte[] id = si.getId();+ if (id.length != StringHelper.ID_LENGTH) {+ throw new IllegalArgumentException("invalid id, got=" + StringHelper.idToString(id));+ }+ output.writeBytes(id, 0, id.length);+ CodecUtil.writeFooter(output);+ success = true;+ } finally {+ if (!success) {+ // TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?+ IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);+ }+ }}/** File extension used to store {@link SegmentInfo}. */diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoReader.javadeleted file mode 100755index 0f167b3ca7b..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoReader.java+++ /dev/null@@ -1,81 +0,0 @@-package org.apache.lucene.codecs.lucene50;--/*- * 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.text.ParseException;-import java.util.Map;-import java.util.Set;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.index.CorruptIndexException;-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.StringHelper;-import org.apache.lucene.util.Version;--/**- * Lucene 5.0 implementation of {@link SegmentInfoReader}.- *- * @see Lucene50SegmentInfoFormat- * @lucene.experimental- */-public class Lucene50SegmentInfoReader extends SegmentInfoReader {-- /** Sole constructor. */- public Lucene50SegmentInfoReader() {- }-- @Override- public SegmentInfo read(Directory dir, String segment, IOContext context) throws IOException {- final String fileName = IndexFileNames.segmentFileName(segment, "", Lucene50SegmentInfoFormat.SI_EXTENSION);- try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {- Throwable priorE = null;- SegmentInfo si = null;- try {- CodecUtil.checkHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME,- Lucene50SegmentInfoFormat.VERSION_START,- Lucene50SegmentInfoFormat.VERSION_CURRENT);- final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt());-- final int docCount = input.readInt();- if (docCount < 0) {- throw new CorruptIndexException("invalid docCount: " + docCount, input);- }- final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;- final Map<String,String> diagnostics = input.readStringStringMap();- final Set<String> files = input.readStringSet();-- byte[] id = new byte[StringHelper.ID_LENGTH];- input.readBytes(id, 0, id.length);-- si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, id);- si.setFiles(files);- } catch (Throwable exception) {- priorE = exception;- } finally {- CodecUtil.checkFooter(input, priorE);- }- return si;- }- }-}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoWriter.javadeleted file mode 100755index 398135a8147..00000000000--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoWriter.java+++ /dev/null@@ -1,89 +0,0 @@-package org.apache.lucene.codecs.lucene50;--/*- * 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.Set;--import org.apache.lucene.codecs.CodecUtil;-import org.apache.lucene.codecs.SegmentInfoWriter;-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.IOUtils;-import org.apache.lucene.util.StringHelper;-import org.apache.lucene.util.Version;--/**- * Lucene 5.0 implementation of {@link SegmentInfoWriter}.- *- * @see Lucene50SegmentInfoFormat- * @lucene.experimental- */-public class Lucene50SegmentInfoWriter extends SegmentInfoWriter {-- /** Sole constructor. */- public Lucene50SegmentInfoWriter() {- }-- /** Save a single segment's info. */- @Override- public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {- final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene50SegmentInfoFormat.SI_EXTENSION);- si.addFile(fileName);-- boolean success = false;- try (IndexOutput output = dir.createOutput(fileName, ioContext)) {- CodecUtil.writeHeader(output, Lucene50SegmentInfoFormat.CODEC_NAME, Lucene50SegmentInfoFormat.VERSION_CURRENT);- Version version = si.getVersion();- if (version.major < 5) {- throw new IllegalArgumentException("invalid major version: should be >= 5 but got: " + version.major + " segment=" + si);- }- // Write the Lucene version that created this segment, since 3.1- output.writeInt(version.major);- output.writeInt(version.minor);- output.writeInt(version.bugfix);- assert version.prerelease == 0;- output.writeInt(si.getDocCount());-- output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO));- output.writeStringStringMap(si.getDiagnostics());- Set<String> files = si.files();- for (String file : files) {- if (!IndexFileNames.parseSegmentName(file).equals(si.name)) {- throw new IllegalArgumentException("invalid files: expected segment=" + si.name + ", got=" + files);- }- }- output.writeStringSet(files);- byte[] id = si.getId();- if (id.length != StringHelper.ID_LENGTH) {- throw new IllegalArgumentException("invalid id, got=" + StringHelper.idToString(id));- }- output.writeBytes(id, 0, id.length);- CodecUtil.writeFooter(output);- success = true;- } finally {- if (!success) {- // TODO: are we doing this outside of the tracking wrapper? why must SIWriter cleanup like this?- IOUtils.deleteFilesIgnoringExceptions(si.dir, fileName);- }- }- }-}diff --git a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.javaindex c0e36db6e2e..1dd666b8819 100644--- a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java+++ b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java@@ -25,7 +25,6 @@ import java.util.Map;import org.apache.lucene.analysis.TokenStream;import org.apache.lucene.codecs.DocValuesConsumer;import org.apache.lucene.codecs.DocValuesFormat;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.codecs.NormsConsumer;import org.apache.lucene.codecs.NormsFormat;import org.apache.lucene.codecs.StoredFieldsWriter;@@ -118,8 +117,7 @@ final class DefaultIndexingChain extends DocConsumer {// consumer can alter the FieldInfo* if necessary. EG,// FreqProxTermsWriter does this with// FieldInfo.storePayload.- FieldInfosWriter infosWriter = docWriter.codec.fieldInfosFormat().getFieldInfosWriter();- infosWriter.write(state.directory, state.segmentInfo, "", state.fieldInfos, IOContext.DEFAULT);+ docWriter.codec.fieldInfosFormat().write(state.directory, state.segmentInfo, "", state.fieldInfos, IOContext.DEFAULT);}/** Writes all buffered doc values (called from {@link #flush}). */diff --git a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.javaindex f9bfd770359..781b44429ba 100644--- a/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java+++ b/lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java@@ -517,7 +517,7 @@ class DocumentsWriterPerThread {// creating CFS so that 1) .si isn't slurped into CFS,// and 2) .si reflects useCompoundFile=true change// above:- codec.segmentInfoFormat().getSegmentInfoWriter().write(directory, newSegment.info, context);+ codec.segmentInfoFormat().write(directory, newSegment.info, context);// TODO: ideally we would freeze newSegment here!!// because any changes after writing the .si will bediff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex 0e148388ff0..cef9dcce826 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -41,7 +41,7 @@ import java.util.concurrent.atomic.AtomicLong;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.codecs.Codec;-import org.apache.lucene.codecs.FieldInfosReader;+import org.apache.lucene.codecs.FieldInfosFormat;import org.apache.lucene.document.Field;import org.apache.lucene.index.DocValuesUpdate.BinaryDocValuesUpdate;import org.apache.lucene.index.DocValuesUpdate.NumericDocValuesUpdate;@@ -871,7 +871,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {// TODO: fix tests abusing this method!static FieldInfos readFieldInfos(SegmentCommitInfo si) throws IOException {Codec codec = si.info.getCodec();- FieldInfosReader reader = codec.fieldInfosFormat().getFieldInfosReader();+ FieldInfosFormat reader = codec.fieldInfosFormat();if (si.hasFieldUpdates()) {// there are updates, we read latest (always outside of CFS)@@ -2594,7 +2594,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {// above:success = false;try {- codec.segmentInfoFormat().getSegmentInfoWriter().write(trackingDir, info, context);+ codec.segmentInfoFormat().write(trackingDir, info, context);success = true;} finally {if (!success) {@@ -4060,7 +4060,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {// above:boolean success2 = false;try {- codec.segmentInfoFormat().getSegmentInfoWriter().write(directory, merge.info.info, context);+ codec.segmentInfoFormat().write(directory, merge.info.info, context);success2 = true;} finally {if (!success2) {diff --git a/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.java b/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.javaindex 3467433d1c7..9c9c2a1597e 100644--- a/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.java+++ b/lucene/core/src/java/org/apache/lucene/index/ReadersAndUpdates.java@@ -451,7 +451,7 @@ class ReadersAndUpdates {final IOContext infosContext = new IOContext(new FlushInfo(info.info.getDocCount(), estInfosSize));// separately also track which files were created for this genfinal TrackingDirectoryWrapper trackingDir = new TrackingDirectoryWrapper(dir);- infosFormat.getFieldInfosWriter().write(trackingDir, info.info, segmentSuffix, fieldInfos, infosContext);+ infosFormat.write(trackingDir, info.info, segmentSuffix, fieldInfos, infosContext);info.advanceFieldInfosGen();return trackingDir.getCreatedFiles();}diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.javaindex 0c0da70e201..ffeed5a861e 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentCoreReaders.java@@ -109,7 +109,7 @@ final class SegmentCoreReaders implements Accountable {cfsDir = dir;}- coreFieldInfos = codec.fieldInfosFormat().getFieldInfosReader().read(cfsDir, si.info, "", context);+ coreFieldInfos = codec.fieldInfosFormat().read(cfsDir, si.info, "", context);final SegmentReadState segmentReadState = new SegmentReadState(cfsDir, si.info, coreFieldInfos, context);final PostingsFormat format = codec.postingsFormat();diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.javaindex 890221df78b..9cbeb499eb1 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java@@ -307,7 +307,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfoString segName = input.readString();Codec codec = Codec.forName(input.readString());//System.out.println("SIS.read seg=" + seg + " codec=" + codec);- SegmentInfo info = codec.segmentInfoFormat().getSegmentInfoReader().read(directory, segName, IOContext.READ);+ SegmentInfo info = codec.segmentInfoFormat().read(directory, segName, IOContext.READ);info.setCodec(codec);long delGen = input.readLong();int delCount = input.readInt();diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.javaindex 9bb3c025e82..cf17adf78bb 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java@@ -22,7 +22,6 @@ import java.util.List;import org.apache.lucene.codecs.Codec;import org.apache.lucene.codecs.DocValuesConsumer;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.codecs.FieldsConsumer;import org.apache.lucene.codecs.NormsConsumer;import org.apache.lucene.codecs.StoredFieldsWriter;@@ -147,8 +146,7 @@ final class SegmentMerger {}// write the merged infos- FieldInfosWriter fieldInfosWriter = codec.fieldInfosFormat().getFieldInfosWriter();- fieldInfosWriter.write(directory, mergeState.segmentInfo, "", mergeState.mergeFieldInfos, context);+ codec.fieldInfosFormat().write(directory, mergeState.segmentInfo, "", mergeState.mergeFieldInfos, context);return mergeState;}diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.javaindex ed048ff45e6..a7850164cb0 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java@@ -182,7 +182,7 @@ public final class SegmentReader extends LeafReader implements Accountable {// updates always outside of CFSFieldInfosFormat fisFormat = si.info.getCodec().fieldInfosFormat();final String segmentSuffix = Long.toString(si.getFieldInfosGen(), Character.MAX_RADIX);- return fisFormat.getFieldInfosReader().read(si.info.dir, si.info, segmentSuffix, IOContext.READONCE);+ return fisFormat.read(si.info.dir, si.info, segmentSuffix, IOContext.READONCE);}}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.javaindex dbd0ebec055..644893fafe7 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.java@@ -331,7 +331,7 @@ public class TestIndexWriterThreadsToSegments extends LuceneTestCase {String segName = IndexFileNames.parseSegmentName(fileName);if (segSeen.contains(segName) == false) {segSeen.add(segName);- SegmentInfo si = TestUtil.getDefaultCodec().segmentInfoFormat().getSegmentInfoReader().read(dir, segName, IOContext.DEFAULT);+ SegmentInfo si = TestUtil.getDefaultCodec().segmentInfoFormat().read(dir, segName, IOContext.DEFAULT);si.setCodec(codec);SegmentCommitInfo sci = new SegmentCommitInfo(si, 0, -1, -1, -1);SegmentReader sr = new SegmentReader(sci, IOContext.DEFAULT);diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyFieldInfosFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyFieldInfosFormat.javaindex 98af87c98c3..be51cb5127b 100644--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyFieldInfosFormat.java+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankyFieldInfosFormat.java@@ -21,8 +21,6 @@ import java.io.IOException;import java.util.Random;import org.apache.lucene.codecs.FieldInfosFormat;-import org.apache.lucene.codecs.FieldInfosReader;-import org.apache.lucene.codecs.FieldInfosWriter;import org.apache.lucene.index.FieldInfos;import org.apache.lucene.index.SegmentInfo;import org.apache.lucene.store.Directory;@@ -36,35 +34,17 @@ class CrankyFieldInfosFormat extends FieldInfosFormat {this.delegate = delegate;this.random = random;}-+@Override- public FieldInfosReader getFieldInfosReader() throws IOException {- return delegate.getFieldInfosReader();+ public FieldInfos read(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, IOContext iocontext) throws IOException {+ return delegate.read(directory, segmentInfo, segmentSuffix, iocontext);}@Override- public FieldInfosWriter getFieldInfosWriter() throws IOException {+ public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {if (random.nextInt(100) == 0) {throw new IOException("Fake IOException from FieldInfosFormat.getFieldInfosWriter()");}- return new CrankyFieldInfosWriter(delegate.getFieldInfosWriter(), random);- }-- static class CrankyFieldInfosWriter extends FieldInfosWriter {- final FieldInfosWriter delegate;- final Random random;-- CrankyFieldInfosWriter(FieldInfosWriter delegate, Random random) {- this.delegate = delegate;- this.random = random;- }-- @Override- public void write(Directory directory, SegmentInfo segmentInfo, String segmentSuffix, FieldInfos infos, IOContext context) throws IOException {- if (random.nextInt(100) == 0) {- throw new IOException("Fake IOException from FieldInfosWriter.write()");- }- delegate.write(directory, segmentInfo, segmentSuffix, infos, context);- }+ delegate.write(directory, segmentInfo, segmentSuffix, infos, context);}}diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankySegmentInfoFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankySegmentInfoFormat.javaindex 770084a88fc..936fae44c95 100644--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankySegmentInfoFormat.java+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/cranky/CrankySegmentInfoFormat.java@@ -21,8 +21,6 @@ import java.io.IOException;import java.util.Random;import org.apache.lucene.codecs.SegmentInfoFormat;-import org.apache.lucene.codecs.SegmentInfoReader;-import org.apache.lucene.codecs.SegmentInfoWriter;import org.apache.lucene.index.SegmentInfo;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;@@ -37,30 +35,15 @@ class CrankySegmentInfoFormat extends SegmentInfoFormat {}@Override- public SegmentInfoReader getSegmentInfoReader() {- return delegate.getSegmentInfoReader();+ public SegmentInfo read(Directory directory, String segmentName, IOContext context) throws IOException {+ return delegate.read(directory, segmentName, context);}@Override- public SegmentInfoWriter getSegmentInfoWriter() {- return new CrankySegmentInfoWriter(delegate.getSegmentInfoWriter(), random);- }-- static class CrankySegmentInfoWriter extends SegmentInfoWriter {- final SegmentInfoWriter delegate;- final Random random;-- CrankySegmentInfoWriter(SegmentInfoWriter delegate, Random random) {- this.delegate = delegate;- this.random = random;- }-- @Override- public void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException {- if (random.nextInt(100) == 0) {- throw new IOException("Fake IOException from SegmentInfoWriter.write()");- }- delegate.write(dir, info, ioContext);+ public void write(Directory dir, SegmentInfo info, IOContext ioContext) throws IOException {+ if (random.nextInt(100) == 0) {+ throw new IOException("Fake IOException from SegmentInfoFormat.write()");}+ delegate.write(dir, info, ioContext);}}diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.javaindex 86ac0dc61ed..4a8736f8f1a 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseSegmentInfoFormatTestCase.java@@ -50,8 +50,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTSegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,Collections.<String,String>emptyMap(), StringHelper.randomId());info.setFiles(Collections.<String>emptySet());- codec.segmentInfoFormat().getSegmentInfoWriter().write(dir, info, IOContext.DEFAULT);- SegmentInfo info2 = codec.segmentInfoFormat().getSegmentInfoReader().read(dir, "_123", IOContext.DEFAULT);+ codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);+ SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", IOContext.DEFAULT);assertEquals(info.files(), info2.files());dir.close();}@@ -64,13 +64,13 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTCollections.<String,String>emptyMap(), StringHelper.randomId());Set<String> originalFiles = Collections.singleton("_123.a");info.setFiles(originalFiles);- codec.segmentInfoFormat().getSegmentInfoWriter().write(dir, info, IOContext.DEFAULT);+ codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);Set<String> modifiedFiles = info.files();assertTrue(modifiedFiles.containsAll(originalFiles));assertTrue("did you forget to add yourself to files()", modifiedFiles.size() > originalFiles.size());- SegmentInfo info2 = codec.segmentInfoFormat().getSegmentInfoReader().read(dir, "_123", IOContext.DEFAULT);+ SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", IOContext.DEFAULT);assertEquals(info.files(), info2.files());dir.close();}@@ -85,8 +85,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTSegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,diagnostics, StringHelper.randomId());info.setFiles(Collections.<String>emptySet());- codec.segmentInfoFormat().getSegmentInfoWriter().write(dir, info, IOContext.DEFAULT);- SegmentInfo info2 = codec.segmentInfoFormat().getSegmentInfoReader().read(dir, "_123", IOContext.DEFAULT);+ codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);+ SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", IOContext.DEFAULT);assertEquals(diagnostics, info2.getDiagnostics());dir.close();}@@ -99,8 +99,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTSegmentInfo info = new SegmentInfo(dir, getVersions()[0], "_123", 1, false, codec,Collections.<String,String>emptyMap(), id);info.setFiles(Collections.<String>emptySet());- codec.segmentInfoFormat().getSegmentInfoWriter().write(dir, info, IOContext.DEFAULT);- SegmentInfo info2 = codec.segmentInfoFormat().getSegmentInfoReader().read(dir, "_123", IOContext.DEFAULT);+ codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);+ SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", IOContext.DEFAULT);assertIDEquals(id, info2.getId());dir.close();}@@ -113,8 +113,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTSegmentInfo info = new SegmentInfo(dir, v, "_123", 1, false, codec,Collections.<String,String>emptyMap(), StringHelper.randomId());info.setFiles(Collections.<String>emptySet());- codec.segmentInfoFormat().getSegmentInfoWriter().write(dir, info, IOContext.DEFAULT);- SegmentInfo info2 = codec.segmentInfoFormat().getSegmentInfoReader().read(dir, "_123", IOContext.DEFAULT);+ codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);+ SegmentInfo info2 = codec.segmentInfoFormat().read(dir, "_123", IOContext.DEFAULT);assertEquals(info2.getVersion(), v);dir.close();}@@ -151,8 +151,8 @@ public abstract class BaseSegmentInfoFormatTestCase extends BaseIndexFileFormatTSegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile, codec, diagnostics, id);info.setFiles(files);- codec.segmentInfoFormat().getSegmentInfoWriter().write(dir, info, IOContext.DEFAULT);- SegmentInfo info2 = codec.segmentInfoFormat().getSegmentInfoReader().read(dir, name, IOContext.DEFAULT);+ codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT);+ SegmentInfo info2 = codec.segmentInfoFormat().read(dir, name, IOContext.DEFAULT);assertEquals(info, info2);dir.close();