/** * Reads an array from the stream using the specified {@link org.elasticsearch.common.io.stream.Writeable.Reader} to read array elements * from the stream. This method can be seen as the reader version of {@link StreamOutput#writeArray(Writeable.Writer, Object[])}. It is * assumed that the stream first contains a variable-length integer representing the size of the array, and then contains that many * elements that can be read from the stream. * * @param reader the reader used to read individual elements * @param arraySupplier a supplier used to construct a new array * @param <T> the type of the elements of the array * @return an array read from the stream * @throws IOException if an I/O exception occurs while reading the array */ public <T> T[] readArray(final Writeable.Reader<T> reader, final IntFunction<T[]> arraySupplier) throws IOException { final int length = readArraySize(); final T[] values = arraySupplier.apply(length); for (int i = 0; i < length; i++) { values[i] = reader.read(this); } return values; }
public Request newRequest(StreamInput in) throws IOException { return requestReader.read(in); }
@Override public V read(StreamInput in, K key) throws IOException { return reader.read(in); }
@Nullable public <T extends Writeable> T readOptionalWriteable(Writeable.Reader<T> reader) throws IOException { if (readBoolean()) { T t = reader.read(this); if (t == null) { throw new IOException("Writeable.Reader [" + reader + "] returned null which is not allowed and probably means it screwed up the stream."); } return t; } else { return null; } }
@Override public V read(StreamInput in, K key) throws IOException { return reader.read(in); }
public Request newRequest(StreamInput in) throws IOException { return requestReader.read(in); }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); targetNode = new DiscoveryNode(in); wrapped = reader.read(in); }
@Override public Diff<V> readDiff(StreamInput in, K key) throws IOException { return diffReader.read(in); } }
/** * Read simple diff from the stream */ CompleteDiff(Reader<T> reader, StreamInput in) throws IOException { if (in.readBoolean()) { this.part = reader.read(in); } else { this.part = null; } }
@Override public <C extends NamedWriteable> C readNamedWriteable(@SuppressWarnings("unused") Class<C> categoryClass, @SuppressWarnings("unused") String name) throws IOException { Writeable.Reader<? extends C> reader = namedWriteableRegistry.getReader(categoryClass, name); C c = reader.read(this); if (c == null) { throw new IOException( "Writeable.Reader [" + reader + "] returned null which is not allowed and probably means it screwed up the stream."); } assert name.equals(c.getWriteableName()) : c + " claims to have a different name [" + c.getWriteableName() + "] than it was read from [" + name + "]."; return c; } }
@Nullable public <T extends Writeable> T readOptionalWriteable(Writeable.Reader<T> reader) throws IOException { if (readBoolean()) { T t = reader.read(this); if (t == null) { throw new IOException("Writeable.Reader [" + reader + "] returned null which is not allowed and probably means it screwed up the stream."); } return t; } else { return null; } }
@Override public V read(StreamInput in, K key) throws IOException { return reader.read(in); }
/** * Read simple diff from the stream */ CompleteDiff(Reader<T> reader, StreamInput in) throws IOException { if (in.readBoolean()) { this.part = reader.read(in); } else { this.part = null; } }
/** * Read simple diff from the stream */ CompleteDiff(Reader<T> reader, StreamInput in) throws IOException { if (in.readBoolean()) { this.part = reader.read(in); } else { this.part = null; } }
/** * Reads a list of objects */ public <T> List<T> readList(Writeable.Reader<T> reader) throws IOException { int count = readArraySize(); List<T> builder = new ArrayList<>(count); for (int i=0; i<count; i++) { builder.add(reader.read(this)); } return builder; }
/** * Reads a collection of objects */ private <T, C extends Collection<? super T>> C readCollection(Writeable.Reader<T> reader, IntFunction<C> constructor) throws IOException { int count = readArraySize(); C builder = constructor.apply(count); for (int i=0; i<count; i++) { builder.add(reader.read(this)); } return builder; }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); targetNode = new DiscoveryNode(in); wrapped = reader.read(in); }
/** * 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); } } }
private AB copyAggregation(AB agg) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { agg.writeTo(output); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) { @SuppressWarnings("unchecked") AB secondAgg = (AB) namedWriteableRegistry.getReader(AggregationBuilder.class, agg.getWriteableName()).read(in); return secondAgg; } } }
public <K, V> Map<K, V> readMap(Writeable.Reader<K> keyReader, Writeable.Reader<V> valueReader) throws IOException { int size = readArraySize(); Map<K, V> map = new HashMap<>(size); for (int i = 0; i < size; i++) { K key = keyReader.read(this); V value = valueReader.read(this); map.put(key, value); } return map; }