LUCENE-7426: remove deprecated DataInput/Output map/string methods

This commit is contained in:
Robert Muir 2016-08-25 12:02:01 -04:00
parent 81c796a1fa
commit f6253d5ed1
8 changed files with 30 additions and 180 deletions

View File

@ -18,7 +18,6 @@ package org.apache.lucene.codecs.lucene50;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -50,7 +49,7 @@ public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {
Throwable priorE = null; Throwable priorE = null;
SegmentInfo si = null; SegmentInfo si = null;
try { try {
int format = CodecUtil.checkIndexHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME, CodecUtil.checkIndexHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME,
Lucene50SegmentInfoFormat.VERSION_START, Lucene50SegmentInfoFormat.VERSION_START,
Lucene50SegmentInfoFormat.VERSION_CURRENT, Lucene50SegmentInfoFormat.VERSION_CURRENT,
segmentID, ""); segmentID, "");
@ -62,19 +61,9 @@ public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {
} }
final boolean isCompoundFile = input.readByte() == SegmentInfo.YES; final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
final Map<String,String> diagnostics; final Map<String,String> diagnostics = input.readMapOfStrings();
final Set<String> files; final Set<String> files = input.readSetOfStrings();
final Map<String,String> attributes; final Map<String,String> attributes = input.readMapOfStrings();
if (format >= VERSION_SAFE_MAPS) {
diagnostics = input.readMapOfStrings();
files = input.readSetOfStrings();
attributes = input.readMapOfStrings();
} else {
diagnostics = Collections.unmodifiableMap(input.readStringStringMap());
files = Collections.unmodifiableSet(input.readStringSet());
attributes = Collections.unmodifiableMap(input.readStringStringMap());
}
si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID, attributes, null); si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID, attributes, null);
si.setFiles(files); si.setFiles(files);
@ -95,7 +84,7 @@ public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {
/** File extension used to store {@link SegmentInfo}. */ /** File extension used to store {@link SegmentInfo}. */
public final static String SI_EXTENSION = "si"; public final static String SI_EXTENSION = "si";
static final String CODEC_NAME = "Lucene50SegmentInfo"; static final String CODEC_NAME = "Lucene50SegmentInfo";
static final int VERSION_START = 0;
static final int VERSION_SAFE_MAPS = 1; static final int VERSION_SAFE_MAPS = 1;
static final int VERSION_START = VERSION_SAFE_MAPS;
static final int VERSION_CURRENT = VERSION_SAFE_MAPS; static final int VERSION_CURRENT = VERSION_SAFE_MAPS;
} }

View File

@ -18,7 +18,6 @@ package org.apache.lucene.codecs.lucene50;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -50,7 +49,7 @@ public class Lucene50RWSegmentInfoFormat extends Lucene50SegmentInfoFormat {
Throwable priorE = null; Throwable priorE = null;
SegmentInfo si = null; SegmentInfo si = null;
try { try {
int format = CodecUtil.checkIndexHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME, CodecUtil.checkIndexHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME,
Lucene50SegmentInfoFormat.VERSION_START, Lucene50SegmentInfoFormat.VERSION_START,
Lucene50SegmentInfoFormat.VERSION_CURRENT, Lucene50SegmentInfoFormat.VERSION_CURRENT,
segmentID, ""); segmentID, "");
@ -62,19 +61,9 @@ public class Lucene50RWSegmentInfoFormat extends Lucene50SegmentInfoFormat {
} }
final boolean isCompoundFile = input.readByte() == SegmentInfo.YES; final boolean isCompoundFile = input.readByte() == SegmentInfo.YES;
final Map<String,String> diagnostics; final Map<String,String> diagnostics = input.readMapOfStrings();
final Set<String> files; final Set<String> files = input.readSetOfStrings();
final Map<String,String> attributes; final Map<String,String> attributes = input.readMapOfStrings();
if (format >= VERSION_SAFE_MAPS) {
diagnostics = input.readMapOfStrings();
files = input.readSetOfStrings();
attributes = input.readMapOfStrings();
} else {
diagnostics = Collections.unmodifiableMap(input.readStringStringMap());
files = Collections.unmodifiableSet(input.readStringSet());
attributes = Collections.unmodifiableMap(input.readStringStringMap());
}
si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID, attributes, null); si = new SegmentInfo(dir, version, segment, docCount, isCompoundFile, null, diagnostics, segmentID, attributes, null);
si.setFiles(files); si.setFiles(files);
@ -130,7 +119,7 @@ public class Lucene50RWSegmentInfoFormat extends Lucene50SegmentInfoFormat {
/** File extension used to store {@link SegmentInfo}. */ /** File extension used to store {@link SegmentInfo}. */
public final static String SI_EXTENSION = "si"; public final static String SI_EXTENSION = "si";
static final String CODEC_NAME = "Lucene50SegmentInfo"; static final String CODEC_NAME = "Lucene50SegmentInfo";
static final int VERSION_START = 0;
static final int VERSION_SAFE_MAPS = 1; static final int VERSION_SAFE_MAPS = 1;
static final int VERSION_START = VERSION_SAFE_MAPS;
static final int VERSION_CURRENT = VERSION_SAFE_MAPS; static final int VERSION_CURRENT = VERSION_SAFE_MAPS;
} }

View File

@ -112,7 +112,7 @@ public final class Lucene50FieldInfosFormat extends FieldInfosFormat {
Throwable priorE = null; Throwable priorE = null;
FieldInfo infos[] = null; FieldInfo infos[] = null;
try { try {
int format = CodecUtil.checkIndexHeader(input, Lucene50FieldInfosFormat.CODEC_NAME, CodecUtil.checkIndexHeader(input, Lucene50FieldInfosFormat.CODEC_NAME,
Lucene50FieldInfosFormat.FORMAT_START, Lucene50FieldInfosFormat.FORMAT_START,
Lucene50FieldInfosFormat.FORMAT_CURRENT, Lucene50FieldInfosFormat.FORMAT_CURRENT,
segmentInfo.getId(), segmentSuffix); segmentInfo.getId(), segmentSuffix);
@ -139,12 +139,8 @@ public final class Lucene50FieldInfosFormat extends FieldInfosFormat {
// DV Types are packed in one byte // DV Types are packed in one byte
final DocValuesType docValuesType = getDocValuesType(input, input.readByte()); final DocValuesType docValuesType = getDocValuesType(input, input.readByte());
final long dvGen = input.readLong(); final long dvGen = input.readLong();
Map<String,String> attributes; Map<String,String> attributes = input.readMapOfStrings();
if (format >= FORMAT_SAFE_MAPS) {
attributes = input.readMapOfStrings();
} else {
attributes = Collections.unmodifiableMap(input.readStringStringMap());
}
// just use the last field's map if its the same // just use the last field's map if its the same
if (attributes.equals(lastAttributes)) { if (attributes.equals(lastAttributes)) {
attributes = lastAttributes; attributes = lastAttributes;
@ -288,8 +284,8 @@ public final class Lucene50FieldInfosFormat extends FieldInfosFormat {
// Codec header // Codec header
static final String CODEC_NAME = "Lucene50FieldInfos"; static final String CODEC_NAME = "Lucene50FieldInfos";
static final int FORMAT_START = 0;
static final int FORMAT_SAFE_MAPS = 1; static final int FORMAT_SAFE_MAPS = 1;
static final int FORMAT_START = FORMAT_SAFE_MAPS;
static final int FORMAT_CURRENT = FORMAT_SAFE_MAPS; static final int FORMAT_CURRENT = FORMAT_SAFE_MAPS;
// Field flags // Field flags

View File

@ -119,10 +119,6 @@ import org.apache.lucene.util.Version;
*/ */
public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo> { public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo> {
/** The file format version for the segments_N codec header, since 5.0+ */
public static final int VERSION_50 = 4;
/** The file format version for the segments_N codec header, since 5.1+ */
public static final int VERSION_51 = 5; // use safe maps
/** Adds the {@link Version} that committed this segments_N file, as well as the {@link Version} of the oldest segment, since 5.3+ */ /** Adds the {@link Version} that committed this segments_N file, as well as the {@link Version} of the oldest segment, since 5.3+ */
public static final int VERSION_53 = 6; public static final int VERSION_53 = 6;
@ -294,7 +290,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
if (magic != CodecUtil.CODEC_MAGIC) { if (magic != CodecUtil.CODEC_MAGIC) {
throw new IndexFormatTooOldException(input, magic, CodecUtil.CODEC_MAGIC, CodecUtil.CODEC_MAGIC); throw new IndexFormatTooOldException(input, magic, CodecUtil.CODEC_MAGIC, CodecUtil.CODEC_MAGIC);
} }
int format = CodecUtil.checkHeaderNoMagic(input, "segments", VERSION_50, VERSION_CURRENT); int format = CodecUtil.checkHeaderNoMagic(input, "segments", VERSION_53, VERSION_CURRENT);
byte id[] = new byte[StringHelper.ID_LENGTH]; byte id[] = new byte[StringHelper.ID_LENGTH];
input.readBytes(id, 0, id.length); input.readBytes(id, 0, id.length);
CodecUtil.checkIndexHeaderSuffix(input, Long.toString(generation, Character.MAX_RADIX)); CodecUtil.checkIndexHeaderSuffix(input, Long.toString(generation, Character.MAX_RADIX));
@ -351,11 +347,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
long fieldInfosGen = input.readLong(); long fieldInfosGen = input.readLong();
long dvGen = input.readLong(); long dvGen = input.readLong();
SegmentCommitInfo siPerCommit = new SegmentCommitInfo(info, delCount, delGen, fieldInfosGen, dvGen); SegmentCommitInfo siPerCommit = new SegmentCommitInfo(info, delCount, delGen, fieldInfosGen, dvGen);
if (format >= VERSION_51) {
siPerCommit.setFieldInfosFiles(input.readSetOfStrings()); siPerCommit.setFieldInfosFiles(input.readSetOfStrings());
} else {
siPerCommit.setFieldInfosFiles(Collections.unmodifiableSet(input.readStringSet()));
}
final Map<Integer,Set<String>> dvUpdateFiles; final Map<Integer,Set<String>> dvUpdateFiles;
final int numDVFields = input.readInt(); final int numDVFields = input.readInt();
if (numDVFields == 0) { if (numDVFields == 0) {
@ -363,11 +355,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
} else { } else {
Map<Integer,Set<String>> map = new HashMap<>(numDVFields); Map<Integer,Set<String>> map = new HashMap<>(numDVFields);
for (int i = 0; i < numDVFields; i++) { for (int i = 0; i < numDVFields; i++) {
if (format >= VERSION_51) {
map.put(input.readInt(), input.readSetOfStrings()); map.put(input.readInt(), input.readSetOfStrings());
} else {
map.put(input.readInt(), Collections.unmodifiableSet(input.readStringSet()));
}
} }
dvUpdateFiles = Collections.unmodifiableMap(map); dvUpdateFiles = Collections.unmodifiableMap(map);
} }
@ -381,11 +369,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
} }
} }
if (format >= VERSION_51) {
infos.userData = input.readMapOfStrings(); infos.userData = input.readMapOfStrings();
} else {
infos.userData = Collections.unmodifiableMap(input.readStringStringMap());
}
CodecUtil.checkFooter(input); CodecUtil.checkFooter(input);

View File

@ -256,24 +256,6 @@ public abstract class DataInput implements Cloneable {
} }
} }
/** Reads a Map&lt;String,String&gt; previously written
* with {@link DataOutput#writeStringStringMap(Map)}.
* @deprecated Only for reading existing formats. Encode maps with
* {@link DataOutput#writeMapOfStrings(Map)} instead.
*/
@Deprecated
public Map<String,String> readStringStringMap() throws IOException {
final Map<String,String> map = new HashMap<>();
final int count = readInt();
for(int i=0;i<count;i++) {
final String key = readString();
final String val = readString();
map.put(key, val);
}
return map;
}
/** /**
* Reads a Map&lt;String,String&gt; previously written * Reads a Map&lt;String,String&gt; previously written
* with {@link DataOutput#writeMapOfStrings(Map)}. * with {@link DataOutput#writeMapOfStrings(Map)}.
@ -296,21 +278,6 @@ public abstract class DataInput implements Cloneable {
} }
} }
/** Reads a Set&lt;String&gt; previously written
* with {@link DataOutput#writeStringSet(Set)}.
* @deprecated Only for reading existing formats. Encode maps with
* {@link DataOutput#writeSetOfStrings(Set)} instead. */
@Deprecated
public Set<String> readStringSet() throws IOException {
final Set<String> set = new HashSet<>();
final int count = readInt();
for(int i=0;i<count;i++) {
set.add(readString());
}
return set;
}
/** /**
* Reads a Set&lt;String&gt; previously written * Reads a Set&lt;String&gt; previously written
* with {@link DataOutput#writeSetOfStrings(Set)}. * with {@link DataOutput#writeSetOfStrings(Set)}.

View File

@ -280,29 +280,6 @@ public abstract class DataOutput {
} }
} }
/**
* Writes a String map.
* <p>
* First the size is written as an {@link #writeInt(int) Int32},
* followed by each key-value pair written as two consecutive
* {@link #writeString(String) String}s.
*
* @param map Input map. May be null (equivalent to an empty map)
* @deprecated Use {@link #writeMapOfStrings(Map)} instead.
*/
@Deprecated
public void writeStringStringMap(Map<String,String> map) throws IOException {
if (map == null) {
writeInt(0);
} else {
writeInt(map.size());
for(final Map.Entry<String, String> entry: map.entrySet()) {
writeString(entry.getKey());
writeString(entry.getValue());
}
}
}
/** /**
* Writes a String map. * Writes a String map.
* <p> * <p>
@ -321,28 +298,6 @@ public abstract class DataOutput {
} }
} }
/**
* Writes a String set.
* <p>
* First the size is written as an {@link #writeInt(int) Int32},
* followed by each value written as a
* {@link #writeString(String) String}.
*
* @param set Input set. May be null (equivalent to an empty set)
* @deprecated Use {@link #writeMapOfStrings(Map)} instead.
*/
@Deprecated
public void writeStringSet(Set<String> set) throws IOException {
if (set == null) {
writeInt(0);
} else {
writeInt(set.size());
for(String value : set) {
writeString(value);
}
}
}
/** /**
* Writes a String set. * Writes a String set.
* <p> * <p>

View File

@ -290,36 +290,6 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
dir.close(); dir.close();
} }
public void testStringSet() throws Exception {
Directory dir = getDirectory(createTempDir("testStringSet"));
IndexOutput output = dir.createOutput("stringset", newIOContext(random()));
output.writeStringSet(asSet("test1", "test2"));
output.close();
IndexInput input = dir.openInput("stringset", newIOContext(random()));
assertEquals(16, input.length());
assertEquals(asSet("test1", "test2"), input.readStringSet());
input.close();
dir.close();
}
public void testStringMap() throws Exception {
Map<String,String> m = new HashMap<>();
m.put("test1", "value1");
m.put("test2", "value2");
Directory dir = getDirectory(createTempDir("testStringMap"));
IndexOutput output = dir.createOutput("stringmap", newIOContext(random()));
output.writeStringStringMap(m);
output.close();
IndexInput input = dir.openInput("stringmap", newIOContext(random()));
assertEquals(30, input.length());
assertEquals(m, input.readStringStringMap());
input.close();
dir.close();
}
public void testSetOfStrings() throws Exception { public void testSetOfStrings() throws Exception {
Directory dir = getDirectory(createTempDir("testSetOfStrings")); Directory dir = getDirectory(createTempDir("testSetOfStrings"));

View File

@ -177,12 +177,6 @@ public class MockIndexInputWrapper extends IndexInput {
return delegate.readString(); return delegate.readString();
} }
@Override
public Map<String,String> readStringStringMap() throws IOException {
ensureOpen();
return delegate.readStringStringMap();
}
@Override @Override
public int readVInt() throws IOException { public int readVInt() throws IOException {
ensureOpen(); ensureOpen();
@ -207,18 +201,24 @@ public class MockIndexInputWrapper extends IndexInput {
return delegate.readZLong(); return delegate.readZLong();
} }
@Override
public Set<String> readStringSet() throws IOException {
ensureOpen();
return delegate.readStringSet();
}
@Override @Override
public void skipBytes(long numBytes) throws IOException { public void skipBytes(long numBytes) throws IOException {
ensureOpen(); ensureOpen();
super.skipBytes(numBytes); super.skipBytes(numBytes);
} }
@Override
public Map<String,String> readMapOfStrings() throws IOException {
ensureOpen();
return delegate.readMapOfStrings();
}
@Override
public Set<String> readSetOfStrings() throws IOException {
ensureOpen();
return delegate.readSetOfStrings();
}
@Override @Override
public String toString() { public String toString() {
return "MockIndexInputWrapper(" + delegate + ")"; return "MockIndexInputWrapper(" + delegate + ")";