Class BufferPublisherInputStream
java.lang.Object
java.io.InputStream
io.servicetalk.http.router.jersey.internal.BufferPublisherInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
An
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 Summary
ConstructorsConstructorDescriptionBufferPublisherInputStream
(Publisher<Buffer> publisher, int queueCapacity) Creates a newBufferPublisherInputStream
instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
handleEntityStream
(InputStream entityStream, BufferAllocator allocator, BiFunction<Publisher<Buffer>, BufferAllocator, T> bufferPublisherHandler, BiFunction<InputStream, BufferAllocator, T> inputStreamHandler) Helper method for dealing with a request entityInputStream
that is potentially aBufferPublisherInputStream
.void
offloadSourcePublisher
(HttpExecutionStrategy executionStrategy, Executor executor) Offload operations on the wrappedPublisher<Buffer>
to the designated executor.int
read()
int
read
(byte[] b, int off, int len) Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
BufferPublisherInputStream
Creates a newBufferPublisherInputStream
instance.- Parameters:
publisher
- thePublisher<Buffer>
to read from.queueCapacity
- the capacity hint for the intermediary queue that stores items.
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
offloadSourcePublisher
Offload operations on the wrappedPublisher<Buffer>
to the designated executor.- Parameters:
executionStrategy
- theHttpExecutionStrategy
to use.executor
- theExecutor
to use with theHttpExecutionStrategy
.
-
handleEntityStream
public static <T> T handleEntityStream(InputStream entityStream, BufferAllocator allocator, BiFunction<Publisher<Buffer>, BufferAllocator, T> bufferPublisherHandler, BiFunction<InputStream, BufferAllocator, T> inputStreamHandler) Helper method for dealing with a request entityInputStream
that is potentially aBufferPublisherInputStream
.- Type Parameters:
T
- the type of data returned by theBiFunction
s.- Parameters:
entityStream
- the request entityInputStream
allocator
- theBufferAllocator
to usebufferPublisherHandler
- aBiFunction
that is called in case the entityInputStream
is aBufferPublisherInputStream
inputStreamHandler
- aBiFunction
that is called in case the entityInputStream
is not aBufferPublisherInputStream
- Returns:
- the data returned by one of the
BiFunction
.
-