Interface WriteStream<T>

All Superinterfaces:
MutinyDelegate, StreamBase
All Known Subinterfaces:
StreamChannel, WebSocketBase
All Known Implementing Classes:
AmqpSender, AsyncFile, ClientWebSocket, HttpClientRequest, HttpServerResponse, KafkaProducer, NetSocket, QuicStream, ServerWebSocket, SockJSSocket, StreamChannel.StreamChannelImpl, WebSocket, WebSocketBase.WebSocketBaseImpl, WriteStream.WriteStreamImpl

public interface WriteStream<T> extends StreamBase, MutinyDelegate
Represents a stream of data that can be written to.

Any class that implements this interface can be used by a Pipe to pipe data from a ReadStream to it.

NOTE: This class has been automatically generated from the original non Mutiny-ified interface.

Author:
Tim Fox
See Also:
  • WriteStream
  • Method Details

    • getDelegate

      io.vertx.core.streams.WriteStream getDelegate()
      Specified by:
      getDelegate in interface MutinyDelegate
      Specified by:
      getDelegate in interface StreamBase
      Returns:
      the delegate used by this Mutiny object of generated type
    • write

      @CheckReturnValue io.smallrye.mutiny.Uni<Void> write(T data)
      Write some data to the stream.

      The data is usually put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the writeQueueFull() method before writing. This is done automatically if using a Pipe.

      When the data is moved from the queue to the actual medium, the returned Future will be completed with the write result, e.g the uni is succeeded when a server HTTP response buffer is written to the socket and failed if the remote client has closed the socket while the data was still pending for write.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Parameters:
      data - the data to write
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • io.vertx.core.streams.WriteStream#write(T)
    • end

      @CheckReturnValue io.smallrye.mutiny.Uni<Void> end()
      Ends the stream.

      Once the stream has ended, it cannot be used any more.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • WriteStream.end()
    • end

      @CheckReturnValue io.smallrye.mutiny.Uni<Void> end(T data)
      Same as end() but writes some data to the stream before ending.

      Unlike the bare Vert.x variant, this method returns a Uni. The uni emits the result of the operation as item. If the operation fails, the uni emits the failure.

      Don't forget to subscribe on it to trigger the operation.

      Parameters:
      data - the data to write
      Returns:
      A Uni representing the asynchronous result of this operation.
      See Also:
      • io.vertx.core.streams.WriteStream#end(T)
    • exceptionHandler

      WriteStream<T> exceptionHandler(Consumer<Throwable> handler)
      Set an exception handler on the write stream.
      Specified by:
      exceptionHandler in interface StreamBase
      Parameters:
      handler - the exception handler. Can be null.
      Returns:
      a reference to this, so the API can be used fluently
    • setWriteQueueMaxSize

      WriteStream<T> setWriteQueueMaxSize(int maxSize)
      Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pipe to provide flow control.

      The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, etc...

      Parameters:
      maxSize - the max size of the write stream
      Returns:
      a reference to this, so the API can be used fluently
    • writeQueueFull

      boolean writeQueueFull()
      This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize(int)
      Returns:
      true if write queue is full
    • drainHandler

      WriteStream<T> drainHandler(Runnable handler)
      Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pipe for an example of this being used.

      The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to maxSize / 2.

      Parameters:
      handler - the handler. Can be null.
      Returns:
      a reference to this, so the API can be used fluently
    • newInstance

      static <T> WriteStream<T> newInstance(io.vertx.core.streams.WriteStream<T> delegate)
      Creates a new instance of the WriteStream.
    • newInstance

      static <T> WriteStream<T> newInstance(io.vertx.core.streams.WriteStream<T> delegate, TypeArg<T> typeArg_0)
      Creates a new instance of the WriteStream.