public abstract class StreamInput
extends java.io.InputStream
StreamOutput
. Finally
it means that the "barrier to entry" for adding new methods to this class is relatively low even though it is a shared class with code
everywhere. That being said, this class deals primarily with List
s rather than Arrays. For the most part calls should adapt to
lists, either by storing List
s internally or just converting to and from a List
when calling. This comment is repeated
on StreamInput
.Constructor and Description |
---|
StreamInput() |
Modifier and Type | Method and Description |
---|---|
abstract int |
available() |
abstract void |
close()
Closes the stream to further operations.
|
protected abstract void |
ensureCanReadBytes(int length)
This method throws an
EOFException if the given number of bytes can not be read from the this stream. |
Version |
getVersion()
The version of the node on the other side of this stream.
|
<T> T[] |
readArray(Writeable.Reader<T> reader,
java.util.function.IntFunction<T[]> arraySupplier) |
boolean |
readBoolean()
Reads a boolean.
|
abstract byte |
readByte()
Reads and returns a single byte.
|
byte[] |
readByteArray() |
abstract void |
readBytes(byte[] b,
int offset,
int len)
Reads a specified number of bytes into an array at the specified offset.
|
org.apache.lucene.util.BytesRef |
readBytesRef() |
org.apache.lucene.util.BytesRef |
readBytesRef(int length) |
BytesReference |
readBytesReference()
Reads a bytes reference from this stream, might hold an actual reference to the underlying
bytes of the stream.
|
BytesReference |
readBytesReference(int length)
Reads a bytes reference from this stream, might hold an actual reference to the underlying
bytes of the stream.
|
double |
readDouble() |
double[] |
readDoubleArray() |
<E extends java.lang.Enum<E>> |
readEnum(java.lang.Class<E> enumClass)
Reads an enum with type E that was serialized based on the value of it's ordinal
|
<T extends java.lang.Exception> |
readException() |
float |
readFloat() |
float[] |
readFloatArray() |
void |
readFully(byte[] b) |
java.lang.Object |
readGenericValue() |
GeoPoint |
readGeoPoint()
Reads a
GeoPoint from this stream input |
int |
readInt()
Reads four bytes and returns an int.
|
int[] |
readIntArray() |
<T> java.util.List<T> |
readList(Writeable.Reader<T> reader)
Reads a list of objects
|
long |
readLong()
Reads eight bytes and returns a long.
|
long[] |
readLongArray() |
java.util.Map<java.lang.String,java.lang.Object> |
readMap() |
<K,V> java.util.Map<K,V> |
readMap(Writeable.Reader<K> keyReader,
Writeable.Reader<V> valueReader) |
<K,V> java.util.Map<K,java.util.List<V>> |
readMapOfLists(Writeable.Reader<K> keyReader,
Writeable.Reader<V> valueReader)
Read a
Map of K -type keys to V -type List s. |
<C extends NamedWriteable> |
readNamedWriteable(java.lang.Class<C> categoryClass)
Reads a
NamedWriteable from the current stream, by first reading its name and then looking for
the corresponding entry in the registry by name, so that the proper object can be read and returned. |
<C extends NamedWriteable> |
readNamedWriteable(java.lang.Class<C> categoryClass,
java.lang.String name)
Reads a
NamedWriteable from the current stream with the given name. |
<T extends NamedWriteable> |
readNamedWriteableList(java.lang.Class<T> categoryClass)
Reads a list of
NamedWriteable s. |
<T> T[] |
readOptionalArray(Writeable.Reader<T> reader,
java.util.function.IntFunction<T[]> arraySupplier) |
java.lang.Boolean |
readOptionalBoolean() |
BytesReference |
readOptionalBytesReference()
Reads an optional bytes reference from this stream.
|
java.lang.Double |
readOptionalDouble() |
java.lang.Float |
readOptionalFloat() |
java.lang.Long |
readOptionalLong() |
<C extends NamedWriteable> |
readOptionalNamedWriteable(java.lang.Class<C> categoryClass)
Reads an optional
NamedWriteable . |
<T extends Streamable> |
readOptionalStreamable(java.util.function.Supplier<T> supplier)
Serializes a potential null value.
|
java.lang.String |
readOptionalString() |
java.lang.String[] |
readOptionalStringArray() |
Text |
readOptionalText() |
org.joda.time.DateTimeZone |
readOptionalTimeZone()
Read an optional DateTimeZone.
|
java.lang.Integer |
readOptionalVInt() |
<T extends Writeable> |
readOptionalWriteable(Writeable.Reader<T> reader) |
short |
readShort() |
<T extends Streamable> |
readStreamableList(java.util.function.Supplier<T> constructor)
|
java.lang.String |
readString() |
java.lang.String[] |
readStringArray() |
Text |
readText() |
org.joda.time.DateTimeZone |
readTimeZone()
Read a DateTimeZone.
|
int |
readVInt()
Reads an int stored in variable-length format.
|
int[] |
readVIntArray() |
long |
readVLong()
Reads a long stored in variable-length format.
|
long[] |
readVLongArray() |
long |
readZLong() |
void |
setVersion(Version version)
Set the version of the node on the other side of this stream.
|
static StreamInput |
wrap(byte[] bytes) |
static StreamInput |
wrap(byte[] bytes,
int offset,
int length) |
public Version getVersion()
public void setVersion(Version version)
public abstract byte readByte() throws java.io.IOException
java.io.IOException
public abstract void readBytes(byte[] b, int offset, int len) throws java.io.IOException
b
- the array to read bytes intooffset
- the offset in the array to start storing byteslen
- the number of bytes to readjava.io.IOException
public BytesReference readBytesReference() throws java.io.IOException
java.io.IOException
@Nullable public BytesReference readOptionalBytesReference() throws java.io.IOException
readBytesReference()
and
StreamOutput.writeBytesReference(BytesReference)
if you do not.java.io.IOException
public BytesReference readBytesReference(int length) throws java.io.IOException
java.io.IOException
public org.apache.lucene.util.BytesRef readBytesRef() throws java.io.IOException
java.io.IOException
public org.apache.lucene.util.BytesRef readBytesRef(int length) throws java.io.IOException
java.io.IOException
public void readFully(byte[] b) throws java.io.IOException
java.io.IOException
public short readShort() throws java.io.IOException
java.io.IOException
public int readInt() throws java.io.IOException
java.io.IOException
public int readVInt() throws java.io.IOException
readInt()
java.io.IOException
public long readLong() throws java.io.IOException
java.io.IOException
public long readVLong() throws java.io.IOException
readLong()
or readZLong()
for negative numbers.java.io.IOException
public long readZLong() throws java.io.IOException
java.io.IOException
@Nullable public java.lang.Long readOptionalLong() throws java.io.IOException
java.io.IOException
@Nullable public Text readOptionalText() throws java.io.IOException
java.io.IOException
public Text readText() throws java.io.IOException
java.io.IOException
@Nullable public java.lang.String readOptionalString() throws java.io.IOException
java.io.IOException
@Nullable public java.lang.Float readOptionalFloat() throws java.io.IOException
java.io.IOException
@Nullable public java.lang.Integer readOptionalVInt() throws java.io.IOException
java.io.IOException
public java.lang.String readString() throws java.io.IOException
java.io.IOException
public final float readFloat() throws java.io.IOException
java.io.IOException
public final double readDouble() throws java.io.IOException
java.io.IOException
@Nullable public final java.lang.Double readOptionalDouble() throws java.io.IOException
java.io.IOException
public final boolean readBoolean() throws java.io.IOException
java.io.IOException
@Nullable public final java.lang.Boolean readOptionalBoolean() throws java.io.IOException
java.io.IOException
public abstract void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
public abstract int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public java.lang.String[] readStringArray() throws java.io.IOException
java.io.IOException
@Nullable public java.lang.String[] readOptionalStringArray() throws java.io.IOException
java.io.IOException
public <K,V> java.util.Map<K,V> readMap(Writeable.Reader<K> keyReader, Writeable.Reader<V> valueReader) throws java.io.IOException
java.io.IOException
public <K,V> java.util.Map<K,java.util.List<V>> readMapOfLists(Writeable.Reader<K> keyReader, Writeable.Reader<V> valueReader) throws java.io.IOException
Map
of K
-type keys to V
-type List
s.
Map<String, List<String>> map = in.readMapOfLists(StreamInput::readString, StreamInput::readString);
keyReader
- The key readervalueReader
- The value readernull
.java.io.IOException
@Nullable public java.util.Map<java.lang.String,java.lang.Object> readMap() throws java.io.IOException
java.io.IOException
@Nullable public java.lang.Object readGenericValue() throws java.io.IOException
java.io.IOException
public GeoPoint readGeoPoint() throws java.io.IOException
GeoPoint
from this stream inputjava.io.IOException
public org.joda.time.DateTimeZone readTimeZone() throws java.io.IOException
java.io.IOException
public org.joda.time.DateTimeZone readOptionalTimeZone() throws java.io.IOException
java.io.IOException
public int[] readIntArray() throws java.io.IOException
java.io.IOException
public int[] readVIntArray() throws java.io.IOException
java.io.IOException
public long[] readLongArray() throws java.io.IOException
java.io.IOException
public long[] readVLongArray() throws java.io.IOException
java.io.IOException
public float[] readFloatArray() throws java.io.IOException
java.io.IOException
public double[] readDoubleArray() throws java.io.IOException
java.io.IOException
public byte[] readByteArray() throws java.io.IOException
java.io.IOException
public <T> T[] readArray(Writeable.Reader<T> reader, java.util.function.IntFunction<T[]> arraySupplier) throws java.io.IOException
java.io.IOException
public <T> T[] readOptionalArray(Writeable.Reader<T> reader, java.util.function.IntFunction<T[]> arraySupplier) throws java.io.IOException
java.io.IOException
@Nullable public <T extends Streamable> T readOptionalStreamable(java.util.function.Supplier<T> supplier) throws java.io.IOException
java.io.IOException
@Nullable public <T extends Writeable> T readOptionalWriteable(Writeable.Reader<T> reader) throws java.io.IOException
java.io.IOException
public <T extends java.lang.Exception> T readException() throws java.io.IOException
java.io.IOException
@Nullable public <C extends NamedWriteable> C readNamedWriteable(java.lang.Class<C> categoryClass) throws java.io.IOException
NamedWriteable
from the current stream, by first reading its name and then looking for
the corresponding entry in the registry by name, so that the proper object can be read and returned.
Default implementation throws UnsupportedOperationException
as StreamInput doesn't hold a registry.
Use FilterInputStream
instead which wraps a stream and supports a NamedWriteableRegistry
too.java.io.IOException
@Nullable public <C extends NamedWriteable> C readNamedWriteable(java.lang.Class<C> categoryClass, java.lang.String name) throws java.io.IOException
NamedWriteable
from the current stream with the given name. It is assumed that the caller obtained the name
from other source, so it's not read from the stream. The name is used for looking for
the corresponding entry in the registry by name, so that the proper object can be read and returned.
Default implementation throws UnsupportedOperationException
as StreamInput doesn't hold a registry.
Use FilterInputStream
instead which wraps a stream and supports a NamedWriteableRegistry
too.
Prefer readNamedWriteable(Class)
and StreamOutput.writeNamedWriteable(NamedWriteable)
unless you
have a compelling reason to use this method instead.java.io.IOException
@Nullable public <C extends NamedWriteable> C readOptionalNamedWriteable(java.lang.Class<C> categoryClass) throws java.io.IOException
NamedWriteable
.java.io.IOException
public <T extends Streamable> java.util.List<T> readStreamableList(java.util.function.Supplier<T> constructor) throws java.io.IOException
List
of Streamable
objects, using the constructor
to instantiate each instance.
This is expected to take the form:
List<MyStreamableClass> list = in.readStreamList(MyStreamableClass::new);
constructor
- Streamable instance creatornull
.java.io.IOException
- if any step failspublic <T> java.util.List<T> readList(Writeable.Reader<T> reader) throws java.io.IOException
java.io.IOException
public <T extends NamedWriteable> java.util.List<T> readNamedWriteableList(java.lang.Class<T> categoryClass) throws java.io.IOException
NamedWriteable
s.java.io.IOException
public <E extends java.lang.Enum<E>> E readEnum(java.lang.Class<E> enumClass) throws java.io.IOException
java.io.IOException
public static StreamInput wrap(byte[] bytes)
public static StreamInput wrap(byte[] bytes, int offset, int length)
protected abstract void ensureCanReadBytes(int length) throws java.io.EOFException
EOFException
if the given number of bytes can not be read from the this stream. This method might
be a no-op depending on the underlying implementation if the information of the remaining bytes is not present.java.io.EOFException