Skip to content

Commit 0befc60

Browse files
committed
Renamed DataBufferUtils/DataBufferFactory.compose to join
Issue: SPR-16365
1 parent 3f3141c commit 0befc60

File tree

16 files changed

+43
-38
lines changed

16 files changed

+43
-38
lines changed

spring-core/src/main/java/org/springframework/core/codec/AbstractDataBufferDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Flux<T> decode(Publisher<DataBuffer> inputStream, ResolvableType elementT
6363
public Mono<T> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
6464
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
6565

66-
return DataBufferUtils.compose(inputStream)
66+
return DataBufferUtils.join(inputStream)
6767
.map(buffer -> decodeDataBuffer(buffer, elementType, mimeType, hints));
6868
}
6969

spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferFactory.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ public interface DataBufferFactory {
6363
DataBuffer wrap(byte[] bytes);
6464

6565
/**
66-
* Create a composite data buffer from the list of provided data buffers. Depending on the
67-
* implementation, the returned buffer may be a single buffer containing all data of the
68-
* provided buffers, or it may be a true composite that contains references to the buffers.
66+
* Return a new {@code DataBuffer} composed of the {@code dataBuffers} elements joined together.
67+
* Depending on the implementation, the returned buffer may be a single buffer containing all
68+
* data of the provided buffers, or it may be a true composite that contains references to the
69+
* buffers.
6970
* <p>Note that the given data buffers do <strong>not</strong> have to be released, as they are
7071
* released as part of the returned composite.
7172
* @param dataBuffers the data buffers to be composed
72-
* @return a buffer that composes {@code dataBuffers} into one
73+
* @return a buffer that is composed from the {@code dataBuffers} argument
74+
* @since 5.0.3
7375
*/
74-
DataBuffer compose(List<DataBuffer> dataBuffers);
76+
DataBuffer join(List<? extends DataBuffer> dataBuffers);
7577
}

spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -507,23 +507,23 @@ public static Consumer<DataBuffer> releaseConsumer() {
507507
}
508508

509509
/**
510-
* Composes the buffers in the given {@link Publisher} into a single data buffer. Depending on
511-
* the {@code DataBuffer} implementation, the returned buffer may be a single buffer containing
512-
* all data of the provided buffers, or it may be a true composite that contains references to
513-
* the buffers.
514-
* @param publisher the data buffers that are to be composed
515-
* @return the composed data buffer
510+
* Return a new {@code DataBuffer} composed of the {@code dataBuffers} elements joined together.
511+
* Depending on the {@link DataBuffer} implementation, the returned buffer may be a single
512+
* buffer containing all data of the provided buffers, or it may be a true composite that
513+
* contains references to the buffers.
514+
* @param dataBuffers the data buffers that are to be composed
515+
* @return a buffer that is composed from the {@code dataBuffers} argument
516+
* @since 5.0.3
516517
*/
517-
public static Mono<DataBuffer> compose(Publisher<DataBuffer> publisher) {
518-
Assert.notNull(publisher, "'publisher' must not be null");
519-
520-
Flux<DataBuffer> source = Flux.from(publisher);
521-
522-
return source.collectList()
523-
.filter(dataBuffers -> !dataBuffers.isEmpty())
524-
.map(dataBuffers -> {
525-
DataBufferFactory bufferFactory = dataBuffers.get(0).factory();
526-
return bufferFactory.compose(dataBuffers);
518+
public static Mono<DataBuffer> join(Publisher<? extends DataBuffer> dataBuffers) {
519+
Assert.notNull(dataBuffers, "'dataBuffers' must not be null");
520+
521+
return Flux.from(dataBuffers)
522+
.collectList()
523+
.filter(list -> !list.isEmpty())
524+
.map(list -> {
525+
DataBufferFactory bufferFactory = list.get(0).factory();
526+
return bufferFactory.join(list);
527527
});
528528
}
529529

spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBufferFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ public DataBuffer wrap(byte[] bytes) {
109109
* in {@code dataBuffers}.
110110
*/
111111
@Override
112-
public DataBuffer compose(List<DataBuffer> dataBuffers) {
112+
public DataBuffer join(List<? extends DataBuffer> dataBuffers) {
113113
Assert.notEmpty(dataBuffers, "'dataBuffers' must not be empty");
114114

115115
int capacity = dataBuffers.stream()
116116
.mapToInt(DataBuffer::readableByteCount)
117117
.sum();
118118
DefaultDataBuffer dataBuffer = allocateBuffer(capacity);
119-
return dataBuffers.stream()
119+
DataBuffer result = dataBuffers.stream()
120+
.map(o -> (DataBuffer) o)
120121
.reduce(dataBuffer, DataBuffer::write);
122+
dataBuffers.forEach(DataBufferUtils::release);
123+
return result;
121124
}
122125

123126
@Override

spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBufferFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public DataBuffer wrap(byte[] bytes) {
8787
* <p>This implementation uses Netty's {@link CompositeByteBuf}.
8888
*/
8989
@Override
90-
public DataBuffer compose(List<DataBuffer> dataBuffers) {
90+
public DataBuffer join(List<? extends DataBuffer> dataBuffers) {
9191
Assert.notNull(dataBuffers, "'dataBuffers' must not be null");
9292
CompositeByteBuf composite = this.byteBufAllocator.compositeBuffer(dataBuffers.size());
9393
for (DataBuffer dataBuffer : dataBuffers) {

spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ public void spr16351() {
480480
}
481481

482482
@Test
483-
public void composite() {
484-
DataBuffer composite = this.bufferFactory.compose(Arrays.asList(stringBuffer("a"),
483+
public void join() {
484+
DataBuffer composite = this.bufferFactory.join(Arrays.asList(stringBuffer("a"),
485485
stringBuffer("b"), stringBuffer("c")));
486486
assertEquals(3, composite.readableByteCount());
487487
byte[] bytes = new byte[3];

spring-core/src/test/java/org/springframework/core/io/buffer/DataBufferUtilsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,13 @@ private Answer<Integer> putByte(int b) {
322322
}
323323

324324
@Test
325-
public void compose() {
325+
public void join() {
326326
DataBuffer foo = stringBuffer("foo");
327327
DataBuffer bar = stringBuffer("bar");
328328
DataBuffer baz = stringBuffer("baz");
329329
Flux<DataBuffer> flux = Flux.just(foo, bar, baz);
330330

331-
DataBuffer result = DataBufferUtils.compose(flux).block(Duration.ofSeconds(5));
331+
DataBuffer result = DataBufferUtils.join(flux).block(Duration.ofSeconds(5));
332332

333333
assertEquals("foobarbaz", DataBufferTestUtils.dumpString(result, StandardCharsets.UTF_8));
334334

spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public Mono<MultiValueMap<String, String>> readMono(ResolvableType elementType,
9696
MediaType contentType = message.getHeaders().getContentType();
9797
Charset charset = getMediaTypeCharset(contentType);
9898

99-
return DataBufferUtils.compose(message.getBody())
99+
return DataBufferUtils.join(message.getBody())
100100
.map(buffer -> {
101101
CharBuffer charBuffer = charset.decode(buffer.asByteBuffer());
102102
String body = charBuffer.toString();

spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public Flux<XMLEvent> decode(Publisher<DataBuffer> inputStream, ResolvableType e
103103
.doFinally(signalType -> aaltoMapper.endOfInput());
104104
}
105105
else {
106-
Mono<DataBuffer> singleBuffer = DataBufferUtils.compose(flux);
106+
Mono<DataBuffer> singleBuffer = DataBufferUtils.join(flux);
107107
return singleBuffer.
108108
flatMapMany(dataBuffer -> {
109109
try {

spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void resolveParts() throws IOException {
8989
assertTrue(part instanceof FilePart);
9090
assertEquals("fooPart", part.name());
9191
assertEquals("foo.txt", ((FilePart) part).filename());
92-
DataBuffer buffer = DataBufferUtils.compose(part.content()).block();
92+
DataBuffer buffer = DataBufferUtils.join(part.content()).block();
9393
assertEquals(12, buffer.readableByteCount());
9494
byte[] byteContent = new byte[12];
9595
buffer.read(byteContent);

spring-web/src/test/java/org/springframework/http/server/reactive/MultipartIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void assertFooPart(Part part) {
103103
assertEquals("fooPart", part.name());
104104
assertTrue(part instanceof FilePart);
105105
assertEquals("foo.txt", ((FilePart) part).filename());
106-
DataBuffer buffer = DataBufferUtils.compose(part.content()).block();
106+
DataBuffer buffer = DataBufferUtils.join(part.content()).block();
107107
assertEquals(12, buffer.readableByteCount());
108108
byte[] byteContent = new byte[12];
109109
buffer.read(byteContent);

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ private <T extends Publisher<?>> T bodyToPublisher(ClientResponse response,
457457

458458
private static Mono<WebClientResponseException> createResponseException(ClientResponse response) {
459459

460-
return DataBufferUtils.compose(response.body(BodyExtractors.toDataBuffers()))
460+
return DataBufferUtils.join(response.body(BodyExtractors.toDataBuffers()))
461461
.map(dataBuffer -> {
462462
byte[] bytes = new byte[dataBuffer.readableByteCount()];
463463
dataBuffer.read(bytes);

spring-webflux/src/main/java/org/springframework/web/reactive/resource/AppCacheManifestTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Mono<Resource> transform(ServerWebExchange exchange, Resource inputResour
112112
DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
113113
Flux<DataBuffer> flux = DataBufferUtils
114114
.read(outputResource, bufferFactory, StreamUtils.BUFFER_SIZE);
115-
return DataBufferUtils.compose(flux)
115+
return DataBufferUtils.join(flux)
116116
.flatMap(dataBuffer -> {
117117
CharBuffer charBuffer = DEFAULT_CHARSET.decode(dataBuffer.asByteBuffer());
118118
DataBufferUtils.release(dataBuffer);

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ContentVersionStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ContentVersionStrategy extends AbstractFileNameVersionStrategy {
4646
public Mono<String> getResourceVersion(Resource resource) {
4747
Flux<DataBuffer> flux =
4848
DataBufferUtils.read(resource, dataBufferFactory, StreamUtils.BUFFER_SIZE);
49-
return DataBufferUtils.compose(flux)
49+
return DataBufferUtils.join(flux)
5050
.map(buffer -> {
5151
byte[] result = new byte[buffer.readableByteCount()];
5252
buffer.read(result);

spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public Mono<Resource> transform(ServerWebExchange exchange, Resource inputResour
8989
DataBufferFactory bufferFactory = exchange.getResponse().bufferFactory();
9090
Flux<DataBuffer> flux = DataBufferUtils
9191
.read(ouptputResource, bufferFactory, StreamUtils.BUFFER_SIZE);
92-
return DataBufferUtils.compose(flux)
92+
return DataBufferUtils.join(flux)
9393
.flatMap(dataBuffer -> {
9494
CharBuffer charBuffer = DEFAULT_CHARSET.decode(dataBuffer.asByteBuffer());
9595
DataBufferUtils.release(dataBuffer);

spring-webflux/src/test/java/org/springframework/web/reactive/function/BodyInsertersTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public void fromMultipartDataWithMultipleValues() {
332332
Mono<Void> result = inserter.insert(request, this.context);
333333
StepVerifier.create(result).expectComplete().verify();
334334

335-
StepVerifier.create(DataBufferUtils.compose(request.getBody()))
335+
StepVerifier.create(DataBufferUtils.join(request.getBody()))
336336
.consumeNextWith(dataBuffer -> {
337337
byte[] resultBytes = new byte[dataBuffer.readableByteCount()];
338338
dataBuffer.read(resultBytes);

0 commit comments

Comments
 (0)