Class OutputStreamBufferOutput

  • All Implemented Interfaces:
    MessageBufferOutput, java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class OutputStreamBufferOutput
    extends java.lang.Object
    implements MessageBufferOutput
    MessageBufferOutput adapter for OutputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(byte[] buffer, int offset, int length)
      Writes an external payload data.
      void close()  
      void flush()  
      MessageBuffer next​(int minimumSize)
      Allocates the next buffer to write.
      java.io.OutputStream reset​(java.io.OutputStream out)
      Reset Stream.
      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 class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OutputStreamBufferOutput

        public OutputStreamBufferOutput​(java.io.OutputStream out)
      • OutputStreamBufferOutput

        public OutputStreamBufferOutput​(java.io.OutputStream out,
                                        int bufferSize)
    • Method Detail

      • reset

        public java.io.OutputStream reset​(java.io.OutputStream out)
                                   throws java.io.IOException
        Reset Stream. This method doesn't close the old stream.
        Parameters:
        out - new stream
        Returns:
        the old stream
        Throws:
        java.io.IOException
      • next

        public MessageBuffer next​(int minimumSize)
                           throws java.io.IOException
        Description copied from interface: MessageBufferOutput
        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 MessageBufferOutput.writeBuffer(int) in between. In this case, the buffer should be discarded without flushing it to the output.

        Specified by:
        next in interface MessageBufferOutput
        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

        public void writeBuffer​(int length)
                         throws java.io.IOException
        Description copied from interface: MessageBufferOutput
        Writes the previously allocated buffer.

        This method should write the buffer previously returned from MessageBufferOutput.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 MessageBufferOutput.next(int) call. In this case, the buffer should be discarded without flushing it to the output when the next MessageBufferOutput.next(int) is called.

        Specified by:
        writeBuffer in interface MessageBufferOutput
        Parameters:
        length - the number of bytes to write
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] buffer,
                          int offset,
                          int length)
                   throws java.io.IOException
        Description copied from interface: MessageBufferOutput
        Writes an external payload data. This method should follow semantics of OutputStream.
        Specified by:
        write in interface MessageBufferOutput
        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

        public void add​(byte[] buffer,
                        int offset,
                        int length)
                 throws java.io.IOException
        Description copied from interface: MessageBufferOutput
        Writes an external payload data.

        Unlike MessageBufferOutput.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.

        Specified by:
        add in interface MessageBufferOutput
        Parameters:
        buffer - the data to add
        offset - the start offset in the data
        length - the number of bytes to add
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Throws:
        java.io.IOException