Simplify conversion of DataBuffer to String
See gh-24786
This commit is contained in:
committed by
Rossen Stoyanchev
parent
ac11acb532
commit
f17b0125ff
@@ -48,9 +48,9 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*/
|
||||
public class MockClientHttpRequest extends AbstractClientHttpRequest {
|
||||
|
||||
private HttpMethod httpMethod;
|
||||
private final HttpMethod httpMethod;
|
||||
|
||||
private URI url;
|
||||
private final URI url;
|
||||
|
||||
private final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
|
||||
|
||||
@@ -160,9 +160,7 @@ public class MockClientHttpRequest extends AbstractClientHttpRequest {
|
||||
|
||||
private static String bufferToString(DataBuffer buffer, Charset charset) {
|
||||
Assert.notNull(charset, "'charset' must not be null");
|
||||
byte[] bytes = new byte[buffer.readableByteCount()];
|
||||
buffer.read(bytes);
|
||||
return new String(bytes, charset);
|
||||
return buffer.toString(charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,9 +134,7 @@ public class MockClientHttpResponse implements ClientHttpResponse {
|
||||
|
||||
private static String dumpString(DataBuffer buffer, Charset charset) {
|
||||
Assert.notNull(charset, "'charset' must not be null");
|
||||
byte[] bytes = new byte[buffer.readableByteCount()];
|
||||
buffer.read(bytes);
|
||||
return new String(bytes, charset);
|
||||
return buffer.toString(charset);
|
||||
}
|
||||
|
||||
private Charset getCharset() {
|
||||
|
||||
@@ -153,10 +153,9 @@ public class MockServerHttpResponse extends AbstractServerHttpResponse {
|
||||
|
||||
private static String bufferToString(DataBuffer buffer, Charset charset) {
|
||||
Assert.notNull(charset, "'charset' must not be null");
|
||||
byte[] bytes = new byte[buffer.readableByteCount()];
|
||||
buffer.read(bytes);
|
||||
String str = buffer.toString(charset);
|
||||
DataBufferUtils.release(buffer);
|
||||
return new String(bytes, charset);
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user