Interface WriteStream<T>

  • Type Parameters:
    T - the type of item emitted.

    public interface WriteStream<T>
    The write end of a data stream.

    Users of a write stream must not call any of the methods of this interface concurrently. That is, write streams are not thread safe.

    See Also:
    Streams.streamMap(Publisher, StreamMapper)
    • Method Detail

      • item

        void item​(T item)
        Emit an item.
        Parameters:
        item - the item to emit
      • error

        void error​(Throwable throwable)
        Signals a stream error.

        No other methods should be called on this stream after calling this method. It is not necessary to enforce this on user provided implementations of write streams as this is managed internally.

        Parameters:
        throwable - the error
      • complete

        void complete()
        Signals that the stream has completed and that no more items (or errors) are to come.

        No other methods should be called on this stream after calling this method. It is not necessary to enforce this on user provided implementations of write streams as this is managed internally.

      • itemMap

        default <O> WriteStream<O> itemMap​(Subscription subscription,
                                           Action<? super O> itemMapper)
        Creates a new write stream that passes error and complete signals on to this stream, but passes items to the given action.

        This effectively creates an upstream write stream that transforms items. It is often useful when Streams.streamMap(Publisher, StreamMapper) mapping streams}.

        The itemMapper typically manually calls item(Object) on this stream, one or more times, when receiving an item. That is, the action may emit multiple items downstream in a particular invocation. If the mapper throws an exception, the exception will be emitted via error(Throwable) and the subscription will be cancelled. The mapper may call complete() or error(Throwable), but should ensure that it does not call any other methods of this interface after.

        Type Parameters:
        O - the type of item received by the returned write stream
        Parameters:
        subscription - the upstream subscription
        itemMapper - the item mapper
        Returns:
        a write stream that writes through to this write stream
        Since:
        1.4