Class StreamOutput

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable
    Direct Known Subclasses:
    OutputStreamStreamOutput

    public abstract class StreamOutput
    extends OutputStream
    A stream from another node to this node. Technically, it can also be streamed from a byte array but that is mostly for testing.

    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.

    • Constructor Detail

      • StreamOutput

        public StreamOutput()
    • Method Detail

      • writeByte

        public abstract void writeByte​(byte b)
                                throws IOException
        Writes a single byte.
        Throws:
        IOException
      • writeBytes

        public void writeBytes​(byte[] b)
                        throws IOException
        Writes an array of bytes.
        Parameters:
        b - the bytes to write
        Throws:
        IOException
      • writeBytes

        public void writeBytes​(byte[] b,
                               int length)
                        throws IOException
        Writes an array of bytes.
        Parameters:
        b - the bytes to write
        length - the number of bytes to write
        Throws:
        IOException
      • writeBytes

        public abstract void writeBytes​(byte[] b,
                                        int offset,
                                        int length)
                                 throws IOException
        Writes an array of bytes.
        Parameters:
        b - the bytes to write
        offset - the offset in the byte array
        length - the number of bytes to write
        Throws:
        IOException
      • writeInt

        public void writeInt​(int i)
                      throws IOException
        Writes an int as four bytes.
        Throws:
        IOException
      • writeVInt

        public void writeVInt​(int i)
                       throws IOException
        Writes an int in a variable-length format. Writes between one and five bytes. Smaller values take fewer bytes. Negative numbers will always use all 5 bytes and are therefore better serialized using writeInt(int)
        Throws:
        IOException
      • writeLong

        public void writeLong​(long i)
                       throws IOException
        Writes a long as eight bytes.
        Throws:
        IOException
      • writeVLong

        public void writeVLong​(long i)
                        throws IOException
        Writes a non-negative long in a variable-length format. Writes between one and ten bytes. Smaller values take fewer bytes. Negative numbers use ten bytes and trip assertions (if running in tests) so prefer writeLong(long) or writeZLong(long) for negative numbers.
        Throws:
        IOException
      • writeZLong

        public void writeZLong​(long i)
                        throws IOException
        Writes a long in a variable-length format. Writes between one and ten bytes. Values are remapped by sliding the sign bit into the lsb and then encoded as an unsigned number e.g., 0 -;> 0, -1 -;> 1, 1 -;> 2, ..., Long.MIN_VALUE -;> -1, Long.MAX_VALUE -;> -2 Numbers with small absolute value will have a small encoding If the numbers are known to be non-negative, use writeVLong(long)
        Throws:
        IOException
      • writeGenericValue

        public void writeGenericValue​(Object value)
                               throws IOException
        Notice: when serialization a map, the stream out map with the stream in map maybe have the different key-value orders, they will maybe have different stream order. If want to keep stream out map and stream in map have the same stream order when stream, can use writeMapWithConsistentOrder
        Throws:
        IOException