Class ByteBufStreams
- java.lang.Object
-
- ratpack.exec.stream.bytebuf.ByteBufStreams
-
public class ByteBufStreams extends Object
Utilities for dealing with streams ofByteBuf.- Since:
- 1.5
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.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.static Promise<io.netty.buffer.CompositeByteBuf>compose(Publisher<? extends io.netty.buffer.ByteBuf> publisher)Reduces the stream to a single composite byte buf.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.static Promise<byte[]>toByteArray(Publisher<? extends io.netty.buffer.ByteBuf> publisher)Reduces the stream to a singlebyte[].static Publisher<byte[]>toByteArrays(Publisher<? extends io.netty.buffer.ByteBuf> publisher)Converts the byte buf stream to a stream ofbyte[].
-
-
-
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)withByteBufAllocator.DEFAULT- Parameters:
publisher- the publisher of byte bufs to buffersizeWatermark- the watermark size for a compositemaxNum- 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 untilmaxNumhave been received, or the cumulative size of buffered byte bufs is greater than or equal tosizeWatermark. Note that unlikeBufferedInputStream, 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 buffersizeWatermark- the watermark size for a compositemaxNum- the maximum number of composite componentsalloc- 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)withByteBufAllocator.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 streamalloc- 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 singlebyte[].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[]
-
-