Package io.helidon.common.reactive
Class OutputStreamPublisher
- java.lang.Object
-
- java.io.OutputStream
-
- io.helidon.common.reactive.OutputStreamPublisher
-
- All Implemented Interfaces:
Flow.Publisher<ByteBuffer>
,Closeable
,Flushable
,AutoCloseable
public class OutputStreamPublisher extends OutputStream implements Flow.Publisher<ByteBuffer>
Output stream thatFlow.Publisher
publishes any data written to it asByteBuffer
events.
-
-
Constructor Summary
Constructors Constructor Description OutputStreamPublisher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
Send empty buffer as an indication of a user-requested flush.void
signalCloseComplete(Throwable throwable)
Signals this publishing output stream that it can safely return from otherwise blocking invocation to it'sclose()
method.void
subscribe(Flow.Subscriber<? super ByteBuffer> subscriberParam)
Adds the given Subscriber if possible.void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Method Detail
-
subscribe
public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriberParam)
Description copied from interface:Flow.Publisher
Adds the given Subscriber if possible. If already subscribed, or the attempt to subscribe fails due to policy violations or errors, the Subscriber'sonError
method is invoked with anIllegalStateException
. Otherwise, the Subscriber'sonSubscribe
method is invoked with a newFlow.Subscription
. Subscribers may enable receiving items by invoking therequest
method of this Subscription, and may unsubscribe by invoking itscancel
method.- Specified by:
subscribe
in interfaceFlow.Publisher<ByteBuffer>
- Parameters:
subscriberParam
- the subscriber
-
write
public void write(byte[] b) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
signalCloseComplete
public void signalCloseComplete(Throwable throwable)
Signals this publishing output stream that it can safely return from otherwise blocking invocation to it'sclose()
method. Subsequent multiple invocations of this method are allowed, but have no effect on this publishing output stream.When the
close()
method on this output stream is invoked, it will block waiting for a signal to complete. This is useful in cases, when the receiving side needs to synchronize it's completion with the publisher, e.g. to ensure that any resources used by the subscribing party are not released prematurely due to a premature exit from publishing output streamclose()
method.Additionally, this mechanism can be used to propagate any downstream completion exceptions back to this publisher and up it's call stack. When a non-null
throwable
parameter is passed into the method, it will be wrapped in anIOException
and thrown from theclose()
method when it is invoked.- Parameters:
throwable
- represents a completion error condition that should be thrown when aclose()
method is invoked on this publishing output stream. If set tonull
, theclose()
method will exit normally.
-
flush
public void flush() throws IOException
Send empty buffer as an indication of a user-requested flush.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- If an I/O occurs.
-
-