Interface MessageBufferOutput

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable, java.io.Flushable
    All Known Implementing Classes:
    ArrayBufferOutput, ChannelBufferOutput, OutputStreamBufferOutput

    public interface MessageBufferOutput
    extends java.io.Closeable, java.io.Flushable
    Provides a buffered output stream that writes sequence of MessageBuffer instances.

    A MessageBufferOutput implementation has total control of the buffer memory so that it can reuse buffer memory, use buffer pools, or use memory-mapped files.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(byte[] buffer, int offset, int length)
      Writes an external payload data.
      MessageBuffer next​(int minimumSize)
      Allocates the next buffer to write.
      void write​(byte[] buffer, int offset, int length)
      Writes an external payload data.
      void writeBuffer​(int length)
      Writes the previously allocated buffer.
      • Methods inherited from interface java.io.Closeable

        close
      • Methods inherited from interface java.io.Flushable

        flush
    • Method Detail

      • next

        MessageBuffer next​(int minimumSize)
                    throws java.io.IOException
        Allocates the next buffer to write.

        This method should return a MessageBuffer instance that has specified size of capacity at least.

        When this method is called twice, the previously returned buffer is no longer used. This method may be called twice without call of writeBuffer(int) in between. In this case, the buffer should be discarded without flushing it to the output.

        Parameters:
        minimumSize - the mimium required buffer size to allocate
        Returns:
        the MessageBuffer instance with at least minimumSize bytes of capacity
        Throws:
        java.io.IOException
      • writeBuffer

        void writeBuffer​(int length)
                  throws java.io.IOException
        Writes the previously allocated buffer.

        This method should write the buffer previously returned from next(int) method until specified number of bytes. Once the buffer is written, the buffer is no longer used.

        This method is not always called for each next(int) call. In this case, the buffer should be discarded without flushing it to the output when the next next(int) is called.

        Parameters:
        length - the number of bytes to write
        Throws:
        java.io.IOException
      • write

        void write​(byte[] buffer,
                   int offset,
                   int length)
            throws java.io.IOException
        Writes an external payload data. This method should follow semantics of OutputStream.
        Parameters:
        buffer - the data to write
        offset - the start offset in the data
        length - the number of bytes to write
        Throws:
        java.io.IOException
      • add

        void add​(byte[] buffer,
                 int offset,
                 int length)
          throws java.io.IOException
        Writes an external payload data.

        Unlike write(byte[], int, int) method, the buffer is given - this MessageBufferOutput implementation gets ownership of the buffer and may modify contents of the buffer. Contents of this buffer won't be modified by the caller.

        Parameters:
        buffer - the data to add
        offset - the start offset in the data
        length - the number of bytes to add
        Throws:
        java.io.IOException