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 newBufferPublisherInputStreaminstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ThandleEntityStream(InputStream entityStream, BufferAllocator allocator, BiFunction<Publisher<Buffer>, BufferAllocator, T> bufferPublisherHandler, BiFunction<InputStream, BufferAllocator, T> inputStreamHandler) Helper method for dealing with a request entityInputStreamthat is potentially aBufferPublisherInputStream.voidoffloadSourcePublisher(HttpExecutionStrategy executionStrategy, Executor executor) Offload operations on the wrappedPublisher<Buffer>to the designated executor.intread()intread(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 newBufferPublisherInputStreaminstance.- Parameters:
publisher- thePublisher<Buffer>to read from.queueCapacity- the capacity hint for the intermediary queue that stores items.
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
offloadSourcePublisher
Offload operations on the wrappedPublisher<Buffer>to the designated executor.- Parameters:
executionStrategy- theHttpExecutionStrategyto use.executor- theExecutorto 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 entityInputStreamthat is potentially aBufferPublisherInputStream.- Type Parameters:
T- the type of data returned by theBiFunctions.- Parameters:
entityStream- the request entityInputStreamallocator- theBufferAllocatorto usebufferPublisherHandler- aBiFunctionthat is called in case the entityInputStreamis aBufferPublisherInputStreaminputStreamHandler- aBiFunctionthat is called in case the entityInputStreamis not aBufferPublisherInputStream- Returns:
- the data returned by one of the
BiFunction.
-