Polishing contribution
See gh-24786
This commit is contained in:
@@ -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("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String> 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() {
|
||||
|
||||
@@ -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("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user