/** * 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); }
/** * Writes a list of {@link Writeable} objects */ public void writeList(List<? extends Writeable> list) throws IOException { writeVInt(list.size()); for (Writeable obj: list) { obj.writeTo(this); } }
/** * 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); }
public void writeOptionalWriteable(@Nullable Writeable writeable) throws IOException { if (writeable != null) { writeBoolean(true); writeable.writeTo(this); } else { writeBoolean(false); } }
public <T extends Writeable> void writeArray(T[] array) throws IOException { writeVInt(array.length); for (T value: array) { value.writeTo(this); } }
/** * Writes a list of {@link Writeable} objects */ public void writeList(List<? extends Writeable> list) throws IOException { writeVInt(list.size()); for (Writeable obj: list) { obj.writeTo(this); } }
public <T extends Writeable> void writeArray(T[] array) throws IOException { writeVInt(array.length); for (T value: array) { value.writeTo(this); } }
/** * Writes a list of {@link Writeable} objects */ public void writeList(List<? extends Writeable> list) throws IOException { writeVInt(list.size()); for (Writeable obj: list) { obj.writeTo(this); } }
/** * Writes a list of {@link Writeable} objects */ public <T extends Writeable<T>> void writeList(List<T> list) throws IOException { writeVInt(list.size()); for (T obj: list) { obj.writeTo(this); } } }
public void writeOptionalWriteable(@Nullable Writeable writeable) throws IOException { if (writeable != null) { writeBoolean(true); writeable.writeTo(this); } else { writeBoolean(false); } }
public void writeOptionalWriteable(@Nullable Writeable writeable) throws IOException { if (writeable != null) { writeBoolean(true); writeable.writeTo(this); } else { writeBoolean(false); } }
/** * Simulates sending diffs over the wire */ public static <T extends Writeable> T copyInstance(T diffs, NamedWriteableRegistry namedWriteableRegistry, Reader<T> reader) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { diffs.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) { return reader.read(in); } } }
/** * Create a copy of an original {@link Writeable} object by running it through a {@link BytesStreamOutput} and * reading it in again using a provided {@link Writeable.Reader}. The stream that is wrapped around the {@link StreamInput} * potentially need to use a {@link NamedWriteableRegistry}, so this needs to be provided too (although it can be * empty if the object that is streamed doesn't contain any {@link NamedWriteable} objects itself. */ public static <T extends Writeable> T copyWriteable(T original, NamedWriteableRegistry namedWritabelRegistry, Writeable.Reader<T> reader) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { original.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWritabelRegistry)) { return reader.read(in); } } }
protected T copyInstance(T instance, Version version) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { output.setVersion(version); instance.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), getNamedWriteableRegistry())) { in.setVersion(version); return instanceReader().read(in); } } }