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.InputStream
AnInputStream
built around aPublisher<Buffer>
, which can either be read OIO style or provide its wrappedPublisher
. This allows us to provide JAX-RS with anInputStream
and 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 newBufferPublisherInputStream
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 entityInputStream
that is potentially aBufferPublisherInputStream
.void
offloadSourcePublisher(HttpExecutionStrategy executionStrategy, Executor fallbackExecutor)
Offload operations on the wrappedPublisher<Buffer>
to the designated executor.int
read()
int
read(byte[] b, int off, int len)
-
-
-
Constructor Detail
-
BufferPublisherInputStream
public BufferPublisherInputStream(Publisher<Buffer> publisher, int queueCapacity)
Creates a newBufferPublisherInputStream
instance.- 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:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in 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
- theHttpExecutionStrategy
to use.fallbackExecutor
- theExecutor
to 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 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
.
-
-