Add DataBufferUtils.compose
Added a utility method that composes data buffers into a single buffer. Depending on the `DataBuffer` implementation, the returned buffer may be a single buffer containing all data of the provided buffers, or it may be a true composite that contains references to the buffers. Issue: SPR-16365
This commit is contained in:
@@ -479,5 +479,18 @@ public class DataBufferTests extends AbstractDataBufferAllocatingTestCase {
|
||||
release(buffer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void composite() {
|
||||
DataBuffer composite = this.bufferFactory.compose(Arrays.asList(stringBuffer("a"),
|
||||
stringBuffer("b"), stringBuffer("c")));
|
||||
assertEquals(3, composite.readableByteCount());
|
||||
byte[] bytes = new byte[3];
|
||||
composite.read(bytes);
|
||||
|
||||
assertArrayEquals(new byte[] {'a','b','c'}, bytes);
|
||||
|
||||
release(composite);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -351,5 +351,19 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compose() {
|
||||
DataBuffer foo = stringBuffer("foo");
|
||||
DataBuffer bar = stringBuffer("bar");
|
||||
DataBuffer baz = stringBuffer("baz");
|
||||
Flux<DataBuffer> flux = Flux.just(foo, bar, baz);
|
||||
|
||||
DataBuffer result = DataBufferUtils.compose(flux).block(Duration.ofSeconds(5));
|
||||
|
||||
assertEquals("foobarbaz", DataBufferTestUtils.dumpString(result, StandardCharsets.UTF_8));
|
||||
|
||||
release(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user