Update StreamUtils drain and emptyInput to use JDK builtins
Update StreamUtils.drain to use InputStream.transferTo with a null OutputStream. This avoids allocating buffers for cases where the supplied InputStream has an optimized transferTo method (e.g., ByteArrayInputStream and FileInputStream). Additionally, update StreamUtils.emptyInput to simply call InputStream.nullInputStream. Closes gh-28961
This commit is contained in:
committed by
Brian Clozel
parent
7642ac82f6
commit
d4a74c8f9d
@@ -28,6 +28,7 @@ import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willDoNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -99,7 +100,10 @@ public class SimpleClientHttpResponseTests {
|
||||
InputStream is = mock(InputStream.class);
|
||||
given(this.connection.getErrorStream()).willReturn(is);
|
||||
willDoNothing().given(is).close();
|
||||
given(is.read(any())).willThrow(new NullPointerException("from HttpURLConnection#ErrorStream"));
|
||||
given(is.transferTo(any())).willCallRealMethod();
|
||||
given(is.read(any(), anyInt(), anyInt())).willThrow(new NullPointerException("from HttpURLConnection#ErrorStream"));
|
||||
|
||||
is.readAllBytes();
|
||||
|
||||
InputStream responseStream = this.response.getBody();
|
||||
responseStream.close();
|
||||
|
||||
Reference in New Issue
Block a user