Interface MessageSink


public sealed interface MessageSink
A destination of bytes that a MessageWriter writes to.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Adapts a MessageSink to an I/O abstraction such as WritableByteChannel or OutputStream.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the buffer allocator used by this message sink.
    Returns the write buffer of this messge sink.
    void
    ensureRemaining(int length)
    Ensures that the buffer of this message sink has at least length bytes remaining.
    void
    Flushes this message sink.
    void
    Flushes the buffer of this message sink.
    long
    transferFrom(ReadableByteChannel channel, long length)
    Transfers up to length bytes from the given channel to this message sink.
    void
    write(byte value)
    Writes a byte.
    void
    write(byte value1, byte value2)
    Writes a byte followed by a byte.
    void
    write(byte value1, double value2)
    Writes a byte followed by a double.
    void
    write(byte value1, float value2)
    Writes a byte followed by a float.
    void
    write(byte value1, int value2)
    Writes a byte followed by an int.
    void
    write(byte value1, long value2)
    Writes a byte followed by a long.
    void
    write(byte value1, short value2)
    Writes a byte followed by a short.
    void
    write(double value)
    Writes a double.
    void
    write(float value)
    Writes a float.
    void
    write(int value)
    Writes an int.
    void
    write(long value)
    Writes a long.
    void
    write(short value)
    Writes a short.
    void
    write(ByteBuffer buffer)
    Writes the remaining bytes of the given buffer.
    void
    write(ByteBuffer... buffers)
    Writes the remaining bytes of the given buffers.
  • Method Details

    • buffer

      ByteBuffer buffer()
      Returns the write buffer of this messge sink.
      Returns:
      the write buffer of this message sink
    • allocator

      BufferAllocator allocator()
      Returns the buffer allocator used by this message sink.
      Returns:
      the byte allocator used by this message sink
    • write

      void write(ByteBuffer buffer) throws IOException

      Writes the remaining bytes of the given buffer.

      This method blocks until the given buffer has been written.

      Parameters:
      buffer - the buffer to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(ByteBuffer... buffers) throws IOException

      Writes the remaining bytes of the given buffers.

      This method blocks until the given buffers have been written. Calling this method may be more efficient than repeatedly calling write(ByteBuffer).

      Parameters:
      buffers - the buffers to write
      Throws:
      IOException - if an I/O error occurs
    • transferFrom

      long transferFrom(ReadableByteChannel channel, long length) throws IOException

      Transfers up to length bytes from the given channel to this message sink.

      Fewer than length bytes may be transferred if the channel's end of input is reached.

      Parameters:
      channel - the channel to read from
      length - the number of bytes to transfer
      Returns:
      the actual number of bytes transferred (between 0 and length)
      Throws:
      IOException - if an I/O error occurs
    • ensureRemaining

      void ensureRemaining(int length) throws IOException

      Ensures that the buffer of this message sink has at least length bytes remaining.

      If the buffer has fewer than length bytes remaining, this method blocks until enough bytes have been written.

      Parameters:
      length - the minimum number of bytes that the buffer needs to have remaining
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(byte value) throws IOException
      Writes a byte.
      Parameters:
      value - the value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(short value) throws IOException
      Writes a short.
      Parameters:
      value - the value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(int value) throws IOException
      Writes an int.
      Parameters:
      value - the value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(long value) throws IOException
      Writes a long.
      Parameters:
      value - the value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(float value) throws IOException
      Writes a float.
      Parameters:
      value - the value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(double value) throws IOException
      Writes a double.
      Parameters:
      value - the value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(byte value1, byte value2) throws IOException
      Writes a byte followed by a byte.
      Parameters:
      value1 - the first value to write
      value2 - the second value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(byte value1, short value2) throws IOException
      Writes a byte followed by a short.
      Parameters:
      value1 - the first value to write
      value2 - the second value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(byte value1, int value2) throws IOException
      Writes a byte followed by an int.
      Parameters:
      value1 - the first value to write
      value2 - the second value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(byte value1, long value2) throws IOException
      Writes a byte followed by a long.
      Parameters:
      value1 - the first value to write
      value2 - the second value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(byte value1, float value2) throws IOException
      Writes a byte followed by a float.
      Parameters:
      value1 - the first value to write
      value2 - the second value to write
      Throws:
      IOException - if an I/O error occurs
    • write

      void write(byte value1, double value2) throws IOException
      Writes a byte followed by a double.
      Parameters:
      value1 - the first value to write
      value2 - the second value to write
      Throws:
      IOException - if an I/O error occurs
    • flushBuffer

      void flushBuffer() throws IOException
      Flushes the buffer of this message sink.
      Throws:
      IOException - if an I/O error occurs
    • flush

      void flush() throws IOException

      Flushes this message sink.

      This method calls flushBuffer() and MessageSink.Provider.flush().

      Throws:
      IOException - if an I/O error occurs