diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index d1f5e9d0e35..be2155f3433 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java index 74d930f67b4..106cc114e89 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java index 12ab9ad8c6a..b1e96092f03 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/io/buffer/DataBufferTestUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpRequest.java b/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpRequest.java index 638a2446f17..c6568c1fca5 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -149,18 +149,13 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest { Charset charset = Optional.ofNullable(getHeaders().getContentType()).map(MimeType::getCharset) .orElse(StandardCharsets.UTF_8); - return getBody() - .reduce(bufferFactory().allocateBuffer(), (previous, current) -> { - previous.write(current); - DataBufferUtils.release(current); - return previous; + return DataBufferUtils.join(getBody()) + .map(buffer -> { + String s = buffer.toString(charset); + DataBufferUtils.release(buffer); + return s; }) - .map(buffer -> bufferToString(buffer, charset)); - } - - private static String bufferToString(DataBuffer buffer, Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); - return buffer.toString(charset); + .defaultIfEmpty(""); } } diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpResponse.java b/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpResponse.java index b553fc9ac7b..4e3d1a76adc 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/reactive/MockClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,19 +122,13 @@ public class MockClientHttpResponse implements ClientHttpResponse { * charset of the Content-Type response or otherwise as "UTF-8". */ public Mono getBodyAsString() { - Charset charset = getCharset(); - return Flux.from(getBody()) - .reduce(this.bufferFactory.allocateBuffer(), (previous, current) -> { - previous.write(current); - DataBufferUtils.release(current); - return previous; + return DataBufferUtils.join(getBody()) + .map(buffer -> { + String s = buffer.toString(getCharset()); + DataBufferUtils.release(buffer); + return s; }) - .map(buffer -> dumpString(buffer, charset)); - } - - private static String dumpString(DataBuffer buffer, Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); - return buffer.toString(charset); + .defaultIfEmpty(""); } private Charset getCharset() { diff --git a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpResponse.java b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpResponse.java index 905ea67baf6..af068c8a903 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,20 +142,13 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse { Charset charset = Optional.ofNullable(getHeaders().getContentType()).map(MimeType::getCharset) .orElse(StandardCharsets.UTF_8); - return getBody() - .reduce(bufferFactory().allocateBuffer(), (previous, current) -> { - previous.write(current); - DataBufferUtils.release(current); - return previous; + return DataBufferUtils.join(getBody()) + .map(buffer -> { + String s = buffer.toString(charset); + DataBufferUtils.release(buffer); + return s; }) - .map(buffer -> bufferToString(buffer, charset)); - } - - private static String bufferToString(DataBuffer buffer, Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); - String str = buffer.toString(charset); - DataBufferUtils.release(buffer); - return str; + .defaultIfEmpty(""); } } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpRequest.java index 321b48e7453..1fdd0edcd3b 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -149,18 +149,13 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest { Charset charset = Optional.ofNullable(getHeaders().getContentType()).map(MimeType::getCharset) .orElse(StandardCharsets.UTF_8); - return getBody() - .reduce(bufferFactory().allocateBuffer(), (previous, current) -> { - previous.write(current); - DataBufferUtils.release(current); - return previous; + return DataBufferUtils.join(getBody()) + .map(buffer -> { + String s = buffer.toString(charset); + DataBufferUtils.release(buffer); + return s; }) - .map(buffer -> bufferToString(buffer, charset)); - } - - private static String bufferToString(DataBuffer buffer, Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); - return buffer.toString(charset); + .defaultIfEmpty(""); } } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpResponse.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpResponse.java index 65815cf78f8..7ee7e6afb95 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpResponse.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/MockClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,19 +122,13 @@ public class MockClientHttpResponse implements ClientHttpResponse { * charset of the Content-Type response or otherwise as "UTF-8". */ public Mono getBodyAsString() { - Charset charset = getCharset(); - return Flux.from(getBody()) - .reduce(this.bufferFactory.allocateBuffer(), (previous, current) -> { - previous.write(current); - DataBufferUtils.release(current); - return previous; + return DataBufferUtils.join(getBody()) + .map(buffer -> { + String s = buffer.toString(getCharset()); + DataBufferUtils.release(buffer); + return s; }) - .map(buffer -> dumpString(buffer, charset)); - } - - private static String dumpString(DataBuffer buffer, Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); - return buffer.toString(charset); + .defaultIfEmpty(""); } private Charset getCharset() { diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpResponse.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpResponse.java index 5a1f2b438a0..b3f95854e4e 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpResponse.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,20 +142,13 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse { Charset charset = Optional.ofNullable(getHeaders().getContentType()).map(MimeType::getCharset) .orElse(StandardCharsets.UTF_8); - return getBody() - .reduce(bufferFactory().allocateBuffer(), (previous, current) -> { - previous.write(current); - DataBufferUtils.release(current); - return previous; + return DataBufferUtils.join(getBody()) + .map(buffer -> { + String s = buffer.toString(charset); + DataBufferUtils.release(buffer); + return s; }) - .map(buffer -> bufferToString(buffer, charset)); - } - - private static String bufferToString(DataBuffer buffer, Charset charset) { - Assert.notNull(charset, "'charset' must not be null"); - String s = buffer.toString(charset); - DataBufferUtils.release(buffer); - return s; + .defaultIfEmpty(""); } }