Class BufferPublisherInputStream
- java.lang.Object
-
- java.io.InputStream
-
- io.servicetalk.http.router.jersey.internal.BufferPublisherInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class BufferPublisherInputStream extends java.io.InputStreamAnInputStreambuilt around aPublisher<Buffer>, which can either be read OIO style or provide its wrappedPublisher. This allows us to provide JAX-RS with anInputStreamand also short-circuit its usage when our code can directly deal with thePublisher<Buffer>it wraps.Not threadsafe and intended to be used internally only, where no concurrency occurs between
read(),read(byte[], int, int)andbufferPublisher().
-
-
Constructor Summary
Constructors Constructor Description BufferPublisherInputStream(Publisher<Buffer> publisher, int queueCapacity)Creates a newBufferPublisherInputStreaminstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ThandleEntityStream(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 entityInputStreamthat is potentially aBufferPublisherInputStream.voidoffloadSourcePublisher(HttpExecutionStrategy executionStrategy, Executor fallbackExecutor)Offload operations on the wrappedPublisher<Buffer>to the designated executor.intread()intread(byte[] b, int off, int len)
-
-
-
Constructor Detail
-
BufferPublisherInputStream
public BufferPublisherInputStream(Publisher<Buffer> publisher, int queueCapacity)
Creates a newBufferPublisherInputStreaminstance.- Parameters:
publisher- thePublisher<Buffer>to read from.queueCapacity- the capacity hint for the intermediary queue that stores items.
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
offloadSourcePublisher
public void offloadSourcePublisher(HttpExecutionStrategy executionStrategy, Executor fallbackExecutor)
Offload operations on the wrappedPublisher<Buffer>to the designated executor.- Parameters:
executionStrategy- theHttpExecutionStrategyto use.fallbackExecutor- theExecutorto use as a fallback with theHttpExecutionStrategy.
-
handleEntityStream
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)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.
-
-