Use InputStream's contracts instead of StreamUtils
Since Spring Framework 6.0 requires Java 17, we can now use `InputStream` new contracts when manipulating streams. Closes gh-27702
This commit is contained in:
committed by
Brian Clozel
parent
0770d86936
commit
fa1f7f6dc7
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.http.converter;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
@@ -53,11 +52,7 @@ public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<
|
||||
|
||||
@Override
|
||||
public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException {
|
||||
long contentLength = inputMessage.getHeaders().getContentLength();
|
||||
ByteArrayOutputStream bos =
|
||||
new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE);
|
||||
StreamUtils.copy(inputMessage.getBody(), bos);
|
||||
return bos.toByteArray();
|
||||
return inputMessage.getBody().readAllBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.http.converter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
@@ -144,7 +145,9 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||
try {
|
||||
InputStream in = resource.getInputStream();
|
||||
try {
|
||||
StreamUtils.copy(in, outputMessage.getBody());
|
||||
OutputStream out = outputMessage.getBody();
|
||||
in.transferTo(out);
|
||||
out.flush();
|
||||
}
|
||||
catch (NullPointerException ex) {
|
||||
// ignore, see SPR-13620
|
||||
|
||||
Reference in New Issue
Block a user