/** * 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; }
/** * Read a {@link Map} of {@code K}-type keys to {@code V}-type {@link List}s. * <pre><code> * Map<String, List<String>> map = in.readMapOfLists(StreamInput::readString, StreamInput::readString); * </code></pre> * * @param keyReader The key reader * @param valueReader The value reader * @return Never {@code null}. */ public <K, V> Map<K, List<V>> readMapOfLists(final Writeable.Reader<K> keyReader, final Writeable.Reader<V> valueReader) throws IOException { final int size = readArraySize(); if (size == 0) { return Collections.emptyMap(); } final Map<K, List<V>> map = new HashMap<>(size); for (int i = 0; i < size; ++i) { map.put(keyReader.read(this), readList(valueReader)); } return map; }
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; }
/** * 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; }
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; }
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; }
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); } } }
@Override public Diff<V> readDiff(StreamInput in, K key) throws IOException { return diffReader.read(in); } }
public <T> T[] readArray(Writeable.Reader<T> reader, IntFunction<T[]> arraySupplier) throws IOException { int length = readArraySize(); T[] values = arraySupplier.apply(length); for (int i = 0; i < length; i++) { values[i] = reader.read(this); } return values; }
/** * 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; }
@Override public T read(StreamInput in) throws IOException { return reader.read(in); }
@Override public T read(StreamInput in) throws IOException { return reader.read(in); }
public Request newRequest(StreamInput in) throws IOException { return requestReader.read(in); }
@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 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 V read(StreamInput in, K key) throws IOException { return reader.read(in); }
@Override public Response read(StreamInput in) throws IOException { return reader.read(in); } }
ProxyRequest(StreamInput in, Writeable.Reader<T> reader) throws IOException { super(in); targetNode = new DiscoveryNode(in); wrapped = reader.read(in); }