Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
javanna committed Dec 14, 2018
1 parent 718a791 commit 0bc1858
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,19 @@ public <T> void writeOptionalArray(final Writer<T> writer, final @Nullable T[] a
}
}

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

/**
* Same as {@link #writeArray(Writeable[])} but the provided array may be null. An additional boolean value is
* serialized to indicate whether the array was null or not.
*/
public <T extends Writeable> void writeOptionalArray(@Nullable T[] array) throws IOException {
writeOptionalArray((out, value) -> value.writeTo(out), array);
}
Expand Down
11 changes: 2 additions & 9 deletions server/src/main/java/org/elasticsearch/common/lucene/Lucene.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,18 +565,11 @@ public static SortField readSortField(StreamInput in) throws IOException {
}

public static SortField[] readSortFields(StreamInput in) throws IOException {
SortField[] fields = new SortField[in.readVInt()];
for (int i = 0; i < fields.length; i++) {
fields[i] = readSortField(in);
}
return fields;
return in.readArray(Lucene::readSortField, SortField[]::new);
}

public static void writeSortFields(StreamOutput out, SortField[] sortFields) throws IOException {
out.writeVInt(sortFields.length);
for (SortField sortField : sortFields) {
writeSortField(out, sortField);
}
out.writeArray(Lucene::writeSortField, sortFields);
}

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

0 comments on commit 0bc1858

Please sign in to comment.