Class StreamOutput

java.lang.Object
java.io.OutputStream
org.elasticsearch.common.io.stream.StreamOutput
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
BufferedChecksumStreamOutput, BufferedStreamOutput, BytesRefStreamOutput, BytesStream, CountingStreamOutput, OutputStreamStreamOutput, VersionCheckingStreamOutput

public abstract class StreamOutput extends OutputStream
A stream into which a structured Writeable may be written, e.g. for sending over a transport connection to a remote node.

This class's methods are optimized so you can put the methods that read and write a class next to each other and you can scan them visually for differences. That means that most variables should be read and written in a single line so even large objects fit both reading and writing on the screen. It also means that the methods on this class are named very similarly to StreamInput. 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 Lists rather than Arrays. For the most part calls should adapt to lists, either by storing Lists internally or just converting to and from a List when calling. This comment is repeated on StreamInput.


It is possible to use a StreamOutput as an adapter to send a Writeable to a raw-bytes OutputStream such as a file or a compressing stream, for instance using OutputStreamStreamOutput or BufferedStreamOutput. Often, however, we want to capture the serialized representation of an object in memory as a byte[] or more generally a BytesReference (a sequence of slices of byte[]s). For example, this is how the org.elasticsearch.transport subsystem prepares a network message for transmission. There are several different ways to achieve this objective, with different performance characteristics, as described in the documentation for the following classes.