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.Publisherpublishes any data written to it asByteBufferevents.
-
-
Constructor Summary
Constructors Constructor Description OutputStreamPublisher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()Send empty buffer as an indication of a user-requested flush.voidsignalCloseComplete(Throwable throwable)Signals this publishing output stream that it can safely return from otherwise blocking invocation to it'sclose()method.voidsubscribe(Flow.Subscriber<? super ByteBuffer> subscriberParam)Adds the given Subscriber if possible.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(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.PublisherAdds the given Subscriber if possible. If already subscribed, or the attempt to subscribe fails due to policy violations or errors, the Subscriber'sonErrormethod is invoked with anIllegalStateException. Otherwise, the Subscriber'sonSubscribemethod is invoked with a newFlow.Subscription. Subscribers may enable receiving items by invoking therequestmethod of this Subscription, and may unsubscribe by invoking itscancelmethod.- Specified by:
subscribein interfaceFlow.Publisher<ByteBuffer>- Parameters:
subscriberParam- the subscriber
-
write
public void write(byte[] b) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(int b) throws IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein 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
throwableparameter is passed into the method, it will be wrapped in anIOExceptionand 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 IOExceptionSend empty buffer as an indication of a user-requested flush.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- If an I/O occurs.
-
-