Top Description Inners Fields Constructors Methods
org.springframework.core.io.buffer

pack-priv final Class OutputStreamPublisher

extends Object
implements Publisher<DataBuffer>
Class Inheritance
All Implemented Interfaces
org.reactivestreams.Publisher
Imports
java.io.BufferedOutputStream, .IOException, .OutputStream, java.util.Objects, java.util.concurrent.Executor, java.util.concurrent.atomic.AtomicLong, .AtomicReference, java.util.concurrent.locks.LockSupport, java.util.function.Consumer, org.reactivestreams.Publisher, .Subscriber, .Subscription, org.springframework.lang.Nullable

Bridges between OutputStream and Publisher<DataBuffer>.

Note that this class has a near duplicate in org.springframework.http.client.OutputStreamPublisher.

Authors
Oleh Dokuka, Arjen Poutsma
Since
6.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final DataBufferFactory
private final int
private final Executor
private final Consumer<OutputStream>

Constructor Summary

AccessConstructor and Description
pack-priv
OutputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, Executor executor, int chunkSize)

Method Summary

Modifier and TypeMethod and Description
public void
subscribe(Subscriber<? super DataBuffer>
the Subscriber that will consume signals from this Publisher
subscriber
)

Implements org.reactivestreams.Publisher.subscribe.

Request Publisher to start streaming data.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferFactoryback to summary
private final DataBufferFactory bufferFactory
chunkSizeback to summary
private final int chunkSize
executorback to summary
private final Executor executor
outputStreamConsumerback to summary
private final Consumer<OutputStream> outputStreamConsumer

Constructor Detail

OutputStreamPublisherback to summary
pack-priv OutputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, Executor executor, int chunkSize)

Method Detail

subscribeback to summary
public void subscribe(Subscriber<? super DataBuffer> subscriber)

Implements org.reactivestreams.Publisher.subscribe.

Doc from org.reactivestreams.Publisher.subscribe.

Request Publisher to start streaming data.

This is a "factory method" and can be called multiple times, each time starting a new Subscription.

Each Subscription will work for only a single Subscriber.

A Subscriber should only subscribe once to a single Publisher.

If the Publisher rejects the subscription attempt or otherwise fails it will signal the error via Subscriber#onError(Throwable).

Parameters
subscriber:Subscriber<? super DataBuffer>

the Subscriber that will consume signals from this Publisher

Annotations
@Override
org.springframework.core.io.buffer back to summary

private final Class OutputStreamPublisher.OutputStreamSubscription

extends OutputStream
implements Subscription
Class Inheritance
All Implemented Interfaces
org.reactivestreams.Subscription

Field Summary

Modifier and TypeField and Description
private final Subscriber<? super DataBuffer>
private final DataBufferFactory
private final int
private volatile Throwable
private final Consumer<OutputStream>
private final AtomicReference<Object>
private long
private static final Object
private final AtomicLong

Constructor Summary

AccessConstructor and Description
pack-priv
OutputStreamSubscription(Subscriber<? super DataBuffer> actual, Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize)

Method Summary

Modifier and TypeMethod and Description
private long
addCap(long n)

private static long
addCap(long a, long b)

private void
public void
cancel()

Implements org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.
private void
private void
private static boolean
isCancelled(long state)

private static boolean
isTerminated(long state)

public void
request(long
the strictly positive number of elements to requests to the upstream Publisher
n
)

Implements org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.
private void
private long
private long
tryProduce(long n)

private long
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
b
)

Overrides java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream.
public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
Inherited from java.io.OutputStream:
closeflushnullOutputStream

Field Detail

actualback to summary
private final Subscriber<? super DataBuffer> actual
bufferFactoryback to summary
private final DataBufferFactory bufferFactory
chunkSizeback to summary
private final int chunkSize
errorback to summary
private volatile Throwable error
Annotations
@Nullable
outputStreamHandlerback to summary
private final Consumer<OutputStream> outputStreamHandler
parkedThreadback to summary
private final AtomicReference<Object> parkedThread
producedback to summary
private long produced
READYback to summary
private static final Object READY
requestedback to summary
private final AtomicLong requested

Constructor Detail

OutputStreamSubscriptionback to summary
pack-priv OutputStreamSubscription(Subscriber<? super DataBuffer> actual, Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize)

Method Detail

addCapback to summary
private long addCap(long n)
addCapback to summary
private static long addCap(long a, long b)
awaitback to summary
private void await()
cancelback to summary
public void cancel()

Implements org.reactivestreams.Subscription.cancel.

Doc from org.reactivestreams.Subscription.cancel.

Request the Publisher to stop sending data and clean up resources.

Data may still be sent to meet previously signalled demand after calling cancel.

Annotations
@Override
checkDemandAndAwaitIfNeededback to summary
private void checkDemandAndAwaitIfNeeded() throws IOException
invokeHandlerback to summary
private void invokeHandler()
isCancelledback to summary
private static boolean isCancelled(long state)
isTerminatedback to summary
private static boolean isTerminated(long state)
requestback to summary
public void request(long n)

Implements org.reactivestreams.Subscription.request.

Doc from org.reactivestreams.Subscription.request.

No events will be sent by a Publisher until demand is signaled via this method.

It can be called however often and whenever needed—but if the outstanding cumulative demand ever becomes Long.MAX_VALUE or more, it may be treated by the Publisher as "effectively unbounded".

Whatever has been requested can be sent by the Publisher so only signal demand for what can be safely handled.

A Publisher can send less than is requested if the stream ends but then must emit either Subscriber#onError(Throwable) or Subscriber#onComplete().

Parameters
n:long

the strictly positive number of elements to requests to the upstream Publisher

Annotations
@Override
resumeback to summary
private void resume()
tryCancelback to summary
private long tryCancel()
tryProduceback to summary
private long tryProduce(long n)
tryTerminateback to summary
private long tryTerminate()
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] b) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Parameters
b:byte[]

the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.