public final class BufferPublisherInputStream
extends java.io.InputStream
InputStream
built around a Publisher<Buffer>
, which can either be read
OIO style or provide its wrapped Publisher
. This allows us to provide JAX-RS with an InputStream
and also short-circuit its usage when our code can directly deal with
the Publisher<Buffer>
it wraps.
Not threadsafe and intended to be used internally only, where no concurrency occurs
between read()
, read(byte[], int, int)
and bufferPublisher()
.
Constructor and Description |
---|
BufferPublisherInputStream(Publisher<Buffer> publisher,
int queueCapacity)
Creates a new
BufferPublisherInputStream instance. |
Modifier and Type | Method and Description |
---|---|
static <T> T |
handleEntityStream(java.io.InputStream entityStream,
BufferAllocator allocator,
java.util.function.BiFunction<Publisher<Buffer>,BufferAllocator,T> bufferPublisherHandler,
java.util.function.BiFunction<java.io.InputStream,BufferAllocator,T> inputStreamHandler)
Helper method for dealing with a request entity
InputStream that is potentially
a BufferPublisherInputStream . |
void |
offloadSourcePublisher(HttpExecutionStrategy executionStrategy,
Executor fallbackExecutor)
Offload operations on the wrapped
Publisher<Buffer> to the designated executor. |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
public BufferPublisherInputStream(Publisher<Buffer> publisher, int queueCapacity)
BufferPublisherInputStream
instance.publisher
- the Publisher<Buffer>
to read from.queueCapacity
- the capacity hint for the intermediary queue that stores items.public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public void offloadSourcePublisher(HttpExecutionStrategy executionStrategy, Executor fallbackExecutor)
Publisher<Buffer>
to the designated executor.executionStrategy
- the HttpExecutionStrategy
to use.fallbackExecutor
- the Executor
to use as a fallback with the HttpExecutionStrategy
.public static <T> T handleEntityStream(java.io.InputStream entityStream, BufferAllocator allocator, java.util.function.BiFunction<Publisher<Buffer>,BufferAllocator,T> bufferPublisherHandler, java.util.function.BiFunction<java.io.InputStream,BufferAllocator,T> inputStreamHandler)
InputStream
that is potentially
a BufferPublisherInputStream
.T
- the type of data returned by the BiFunction
s.entityStream
- the request entity InputStream
allocator
- the BufferAllocator
to usebufferPublisherHandler
- a BiFunction
that is called in case the entity InputStream
is
a BufferPublisherInputStream
inputStreamHandler
- a BiFunction
that is called in case the entity InputStream
is not
a BufferPublisherInputStream
BiFunction
.