Skip to content

Commit b749dbc

Browse files
committed
Add writing and reading of String lists to StreamIO classes
1 parent 3ac5271 commit b749dbc

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/main/java/org/elasticsearch/common/io/stream/StreamInput.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,18 @@ public String[] readStringArray() throws IOException {
335335
return ret;
336336
}
337337

338+
public List<String> readStringList() throws IOException {
339+
int size = readVInt();
340+
if (size == 0) {
341+
return Collections.emptyList();
342+
}
343+
List<String> ret = new ArrayList<>(size);
344+
for (int i = 0; i < size; i++) {
345+
ret.add(readString());
346+
}
347+
return ret;
348+
}
349+
338350
@Nullable
339351
public Map<String, Object> readMap() throws IOException {
340352
return (Map<String, Object>) readGenericValue();
@@ -427,7 +439,7 @@ public int[] readIntArray() throws IOException {
427439
}
428440
return values;
429441
}
430-
442+
431443
public long[] readLongArray() throws IOException {
432444
int length = readVInt();
433445
long[] values = new long[length];
@@ -436,7 +448,7 @@ public long[] readLongArray() throws IOException {
436448
}
437449
return values;
438450
}
439-
451+
440452
public float[] readFloatArray() throws IOException {
441453
int length = readVInt();
442454
float[] values = new float[length];
@@ -445,7 +457,7 @@ public float[] readFloatArray() throws IOException {
445457
}
446458
return values;
447459
}
448-
460+
449461
public double[] readDoubleArray() throws IOException {
450462
int length = readVInt();
451463
double[] values = new double[length];

src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ public void writeStringArray(String[] array) throws IOException {
283283
}
284284
}
285285

286+
public void writeStringList(List<String> stringList) throws IOException {
287+
writeVInt(stringList.size());
288+
for (String s : stringList) {
289+
writeString(s);
290+
}
291+
}
292+
286293
/**
287294
* Writes a string array, for nullable string, writes it as 0 (empty string).
288295
*/
@@ -399,21 +406,21 @@ public void writeIntArray(int[] value) throws IOException {
399406
writeInt(value[i]);
400407
}
401408
}
402-
409+
403410
public void writeLongArray(long[] value) throws IOException {
404411
writeVInt(value.length);
405412
for (int i=0; i<value.length; i++) {
406413
writeLong(value[i]);
407414
}
408415
}
409-
416+
410417
public void writeFloatArray(float[] value) throws IOException {
411418
writeVInt(value.length);
412419
for (int i=0; i<value.length; i++) {
413420
writeFloat(value[i]);
414421
}
415422
}
416-
423+
417424
public void writeDoubleArray(double[] value) throws IOException {
418425
writeVInt(value.length);
419426
for (int i=0; i<value.length; i++) {

src/main/java/org/elasticsearch/index/query/IdsQueryBuilder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,18 @@ public QueryValidationException validate() {
177177
return null;
178178
}
179179

180-
@SuppressWarnings("unchecked")
181180
@Override
182181
public void readFrom(StreamInput in) throws IOException {
183-
this.types = (List<String>) in.readGenericValue();
184-
this.ids = (List<String>) in.readGenericValue();
182+
this.types = in.readStringList();
183+
this.ids = in.readStringList();
185184
queryName = in.readOptionalString();
186185
boost = in.readFloat();
187186
}
188187

189188
@Override
190189
public void writeTo(StreamOutput out) throws IOException {
191-
out.writeGenericValue(this.types);
192-
out.writeGenericValue(this.ids);
190+
out.writeStringList(this.types);
191+
out.writeStringList(this.ids);
193192
out.writeOptionalString(queryName);
194193
out.writeFloat(boost);
195194
}

0 commit comments

Comments
 (0)