Class ByteBufStreams


  • public class ByteBufStreams
    extends Object
    Utilities for dealing with streams of ByteBuf.
    Since:
    1.5
    • Method Detail

      • buffer

        public static TransformablePublisher<? extends io.netty.buffer.ByteBuf> buffer​(Publisher<? extends io.netty.buffer.ByteBuf> publisher,
                                                                                       long sizeWatermark,
                                                                                       int maxNum)
        Buffers and composes byte bufs together into composites before emitting.

        Calls buffer(Publisher, long, int, ByteBufAllocator) with ByteBufAllocator.DEFAULT

        Parameters:
        publisher - the publisher of byte bufs to buffer
        sizeWatermark - the watermark size for a composite
        maxNum - the maximum number of composite components
        Returns:
        a byte buf composing publisher
      • buffer

        public static TransformablePublisher<? extends io.netty.buffer.ByteBuf> buffer​(Publisher<? extends io.netty.buffer.ByteBuf> publisher,
                                                                                       long sizeWatermark,
                                                                                       int maxNum,
                                                                                       io.netty.buffer.ByteBufAllocator alloc)
        Buffers and composes byte bufs together into composites before emitting.

        This is roughly analogous to BufferedInputStream. The returned published accumulates upstream buffers until maxNum have been received, or the cumulative size of buffered byte bufs is greater than or equal to sizeWatermark. Note that unlike BufferedInputStream, the downstream writes are not guaranteed to be less than the buffer size.

        Byte bufs are requested of the given publisher one at a time. If this is inefficient, consider wrapping it with Streams.batch(int, Publisher, Action) before giving to this method.

        Parameters:
        publisher - the publisher of byte bufs to buffer
        sizeWatermark - the watermark size for a composite
        maxNum - the maximum number of composite components
        alloc - the allocator of composites
        Returns:
        a byte buf composing publisher
      • compose

        public static Promise<io.netty.buffer.CompositeByteBuf> compose​(Publisher<? extends io.netty.buffer.ByteBuf> publisher)
        Reduces the stream to a single composite byte buf.

        Calls compose(Publisher, ByteBufAllocator) with ByteBufAllocator.DEFAULT.

        Parameters:
        publisher - the stream
        Returns:
        the reduced composite buffer
      • compose

        public static Promise<io.netty.buffer.CompositeByteBuf> compose​(Publisher<? extends io.netty.buffer.ByteBuf> publisher,
                                                                        io.netty.buffer.ByteBufAllocator alloc)
        Reduces the stream to a single composite byte buf.
        Parameters:
        publisher - the stream
        alloc - the buffer allocator
        Returns:
        the reduced composite buffer
      • toByteArray

        public static Promise<byte[]> toByteArray​(Publisher<? extends io.netty.buffer.ByteBuf> publisher)
        Reduces the stream to a single byte[].

        This should only be used when it is known that the stream is small, as this will effectively force the entire stream to be held in memory.

        Parameters:
        publisher - the byte stream
        Returns:
        the bytes as a byte[]
      • toByteArrays

        public static Publisher<byte[]> toByteArrays​(Publisher<? extends io.netty.buffer.ByteBuf> publisher)
        Converts the byte buf stream to a stream of byte[].
        Parameters:
        publisher - the byte stream
        Returns:
        a publisher of byte[]