Skip to content

Commit 0bc1858

Browse files
committed
address review comments
1 parent 718a791 commit 0bc1858

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,10 +798,19 @@ public <T> void writeOptionalArray(final Writer<T> writer, final @Nullable T[] a
798798
}
799799
}
800800

801+
/**
802+
* Writes the specified array of {@link Writeable}s. This method can be seen as
803+
* writer version of {@link StreamInput#readArray(Writeable.Reader, IntFunction)}. The length of array encoded as a variable-length
804+
* integer is first written to the stream, and then the elements of the array are written to the stream.
805+
*/
801806
public <T extends Writeable> void writeArray(T[] array) throws IOException {
802807
writeArray((out, value) -> value.writeTo(out), array);
803808
}
804809

810+
/**
811+
* Same as {@link #writeArray(Writeable[])} but the provided array may be null. An additional boolean value is
812+
* serialized to indicate whether the array was null or not.
813+
*/
805814
public <T extends Writeable> void writeOptionalArray(@Nullable T[] array) throws IOException {
806815
writeOptionalArray((out, value) -> value.writeTo(out), array);
807816
}

server/src/main/java/org/elasticsearch/common/lucene/Lucene.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -565,18 +565,11 @@ public static SortField readSortField(StreamInput in) throws IOException {
565565
}
566566

567567
public static SortField[] readSortFields(StreamInput in) throws IOException {
568-
SortField[] fields = new SortField[in.readVInt()];
569-
for (int i = 0; i < fields.length; i++) {
570-
fields[i] = readSortField(in);
571-
}
572-
return fields;
568+
return in.readArray(Lucene::readSortField, SortField[]::new);
573569
}
574570

575571
public static void writeSortFields(StreamOutput out, SortField[] sortFields) throws IOException {
576-
out.writeVInt(sortFields.length);
577-
for (SortField sortField : sortFields) {
578-
writeSortField(out, sortField);
579-
}
572+
out.writeArray(Lucene::writeSortField, sortFields);
580573
}
581574

582575
public static void writeSortType(StreamOutput out, SortField.Type sortType) throws IOException {

0 commit comments

Comments
 (0)