Class BufferPublisherInputStream

  • All Implemented Interfaces:, java.lang.AutoCloseable

    public final class BufferPublisherInputStream
    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 Detail

      • BufferPublisherInputStream

        public BufferPublisherInputStream​(Publisher<Buffer> publisher,
                                          int queueCapacity)
        Creates a new BufferPublisherInputStream instance.
        publisher - the Publisher<Buffer> to read from.
        queueCapacity - the capacity hint for the intermediary queue that stores items.
    • Method Detail

      • read

        public int read()
        Specified by:
        read in class
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
        read in class
      • handleEntityStream

        public static <T> T handleEntityStream​( entityStream,
                                               BufferAllocator allocator,
                                               java.util.function.BiFunction<Publisher<Buffer>,​BufferAllocator,​T> bufferPublisherHandler,
                                               java.util.function.BiFunction<,​BufferAllocator,​T> inputStreamHandler)
        Helper method for dealing with a request entity InputStream that is potentially a BufferPublisherInputStream.
        Type Parameters:
        T - the type of data returned by the BiFunctions.
        entityStream - the request entity InputStream
        allocator - the BufferAllocator to use
        bufferPublisherHandler - 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
        the data returned by one of the BiFunction.