parent
d4a74c8f9d
commit
0770d86936
|
|
@ -17,12 +17,12 @@
|
|||
package org.springframework.scripting.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
|
@ -60,7 +60,7 @@ public class ResourceScriptSourceTests {
|
|||
// does not support File-based reading; delegates to InputStream-style reading...
|
||||
//resource.getFile();
|
||||
//mock.setThrowable(new FileNotFoundException());
|
||||
given(resource.getInputStream()).willReturn(StreamUtils.emptyInput());
|
||||
given(resource.getInputStream()).willReturn(InputStream.nullInputStream());
|
||||
|
||||
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
|
||||
assertThat(scriptSource.isModified()).as("ResourceScriptSource must start off in the 'isModified' state (it obviously isn't).").isTrue();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -216,11 +216,14 @@ public abstract class StreamUtils {
|
|||
Assert.notNull(in, "No InputStream specified");
|
||||
return (int) in.transferTo(OutputStream.nullOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an efficient empty {@link InputStream}.
|
||||
* @return an InputStream which contains no bytes
|
||||
* @since 4.2.2
|
||||
* @deprecated as of 6.0 in favor of {@link InputStream#nullInputStream()}
|
||||
*/
|
||||
@Deprecated
|
||||
public static InputStream emptyInput() {
|
||||
return InputStream.nullInputStream();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.util.xml;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
|
@ -37,7 +38,6 @@ import org.xml.sax.ContentHandler;
|
|||
import org.xml.sax.XMLReader;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Convenience methods for working with the StAX API. Partly historic due to JAXP 1.3
|
||||
|
|
@ -54,7 +54,7 @@ import org.springframework.util.StreamUtils;
|
|||
public abstract class StaxUtils {
|
||||
|
||||
private static final XMLResolver NO_OP_XML_RESOLVER =
|
||||
(publicID, systemID, base, ns) -> StreamUtils.emptyInput();
|
||||
(publicID, systemID, base, ns) -> InputStream.nullInputStream();
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import java.sql.Blob;
|
|||
import java.sql.SQLException;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Simple JDBC {@link Blob} adapter that exposes a given byte array or binary stream.
|
||||
|
|
@ -65,7 +64,7 @@ class PassThroughBlob implements Blob {
|
|||
return new ByteArrayInputStream(this.content);
|
||||
}
|
||||
else {
|
||||
return (this.binaryStream != null ? this.binaryStream : StreamUtils.emptyInput());
|
||||
return (this.binaryStream != null ? this.binaryStream : InputStream.nullInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import java.sql.SQLException;
|
|||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Simple JDBC {@link Clob} adapter that exposes a given String or character stream.
|
||||
|
|
@ -84,7 +83,7 @@ class PassThroughClob implements Clob {
|
|||
}
|
||||
else {
|
||||
return new InputStreamReader(
|
||||
(this.asciiStream != null ? this.asciiStream : StreamUtils.emptyInput()),
|
||||
(this.asciiStream != null ? this.asciiStream : InputStream.nullInputStream()),
|
||||
StandardCharsets.US_ASCII);
|
||||
}
|
||||
}
|
||||
|
|
@ -100,7 +99,7 @@ class PassThroughClob implements Clob {
|
|||
return new ByteArrayInputStream(tempContent.getBytes(StandardCharsets.US_ASCII));
|
||||
}
|
||||
else {
|
||||
return (this.asciiStream != null ? this.asciiStream : StreamUtils.emptyInput());
|
||||
return (this.asciiStream != null ? this.asciiStream : InputStream.nullInputStream());
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
|
|
@ -102,7 +101,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
|
||||
|
||||
private static final ServletInputStream EMPTY_SERVLET_INPUT_STREAM =
|
||||
new DelegatingServletInputStream(StreamUtils.emptyInput());
|
||||
new DelegatingServletInputStream(InputStream.nullInputStream());
|
||||
|
||||
private static final BufferedReader EMPTY_BUFFERED_READER =
|
||||
new BufferedReader(new StringReader(""));
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
|
@ -804,7 +803,7 @@ public class MockHttpServletRequestBuilder
|
|||
HttpInputMessage message = new HttpInputMessage() {
|
||||
@Override
|
||||
public InputStream getBody() {
|
||||
return (content != null ? new ByteArrayInputStream(content) : StreamUtils.emptyInput());
|
||||
return (content != null ? new ByteArrayInputStream(content) : InputStream.nullInputStream());
|
||||
}
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import org.apache.http.util.EntityUtils;
|
|||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpResponse} implementation based on
|
||||
|
|
@ -84,7 +83,7 @@ final class HttpComponentsClientHttpResponse implements ClientHttpResponse {
|
|||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
HttpEntity entity = this.httpResponse.getEntity();
|
||||
return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
|
||||
return (entity != null ? entity.getContent() : InputStream.nullInputStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import org.springframework.http.HttpHeaders;
|
|||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* {@link ClientHttpResponse} implementation based on OkHttp 3.x.
|
||||
|
|
@ -69,7 +68,7 @@ class OkHttp3ClientHttpResponse implements ClientHttpResponse {
|
|||
@Override
|
||||
public InputStream getBody() throws IOException {
|
||||
ResponseBody body = this.response.body();
|
||||
return (body != null ? body.byteStream() : StreamUtils.emptyInput());
|
||||
return (body != null ? body.byteStream() : InputStream.nullInputStream());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
|
|||
(publicId, systemId) -> new InputSource(new StringReader(""));
|
||||
|
||||
private static final XMLResolver NO_OP_XML_RESOLVER =
|
||||
(publicID, systemID, base, ns) -> StreamUtils.emptyInput();
|
||||
(publicID, systemID, base, ns) -> InputStream.nullInputStream();
|
||||
|
||||
private static final Set<Class<?>> SUPPORTED_CLASSES = new HashSet<>(8);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.springframework.web.client;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
|
@ -52,7 +53,6 @@ import org.springframework.http.converter.GenericHttpMessageConverter;
|
|||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.KotlinSerializationJsonHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
|
@ -284,7 +284,7 @@ class RestTemplateTests {
|
|||
mockSentRequest(GET, "https://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150");
|
||||
mockResponseStatus(HttpStatus.OK);
|
||||
given(response.getHeaders()).willReturn(new HttpHeaders());
|
||||
given(response.getBody()).willReturn(StreamUtils.emptyInput());
|
||||
given(response.getBody()).willReturn(InputStream.nullInputStream());
|
||||
|
||||
Map<String, String> uriVariables = new HashMap<>(2);
|
||||
uriVariables.put("hotel", "1");
|
||||
|
|
@ -440,7 +440,7 @@ class RestTemplateTests {
|
|||
responseHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
responseHeaders.setContentLength(10);
|
||||
given(response.getHeaders()).willReturn(responseHeaders);
|
||||
given(response.getBody()).willReturn(StreamUtils.emptyInput());
|
||||
given(response.getBody()).willReturn(InputStream.nullInputStream());
|
||||
given(converter.read(String.class, response)).willReturn(null);
|
||||
|
||||
String result = template.postForObject("https://example.com", null, String.class);
|
||||
|
|
@ -460,7 +460,7 @@ class RestTemplateTests {
|
|||
responseHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
responseHeaders.setContentLength(10);
|
||||
given(response.getHeaders()).willReturn(responseHeaders);
|
||||
given(response.getBody()).willReturn(StreamUtils.emptyInput());
|
||||
given(response.getBody()).willReturn(InputStream.nullInputStream());
|
||||
given(converter.read(String.class, response)).willReturn(null);
|
||||
|
||||
ResponseEntity<String> result = template.postForEntity("https://example.com", null, String.class);
|
||||
|
|
@ -556,7 +556,7 @@ class RestTemplateTests {
|
|||
responseHeaders.setContentType(MediaType.TEXT_PLAIN);
|
||||
responseHeaders.setContentLength(10);
|
||||
given(response.getHeaders()).willReturn(responseHeaders);
|
||||
given(response.getBody()).willReturn(StreamUtils.emptyInput());
|
||||
given(response.getBody()).willReturn(InputStream.nullInputStream());
|
||||
|
||||
String result = template.patchForObject("https://example.com", null, String.class);
|
||||
assertThat(result).as("Invalid POST result").isNull();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.web.filter;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
|
|
@ -23,7 +24,6 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
|
||||
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
|
||||
|
||||
|
|
@ -45,18 +45,18 @@ public class ShallowEtagHeaderFilterTests {
|
|||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput())).isTrue();
|
||||
assertThat(filter.isEligibleForEtag(request, response, 300, StreamUtils.emptyInput())).isFalse();
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, InputStream.nullInputStream())).isTrue();
|
||||
assertThat(filter.isEligibleForEtag(request, response, 300, InputStream.nullInputStream())).isFalse();
|
||||
|
||||
request = new MockHttpServletRequest("HEAD", "/hotels");
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput())).isFalse();
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, InputStream.nullInputStream())).isFalse();
|
||||
|
||||
request = new MockHttpServletRequest("POST", "/hotels");
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput())).isFalse();
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, InputStream.nullInputStream())).isFalse();
|
||||
|
||||
request = new MockHttpServletRequest("POST", "/hotels");
|
||||
request.addHeader("Cache-Control","must-revalidate, no-store");
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput())).isFalse();
|
||||
assertThat(filter.isEligibleForEtag(request, response, 200, InputStream.nullInputStream())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.util.UrlPathHelper;
|
||||
|
||||
|
|
@ -102,7 +101,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
|||
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
|
||||
|
||||
private static final ServletInputStream EMPTY_SERVLET_INPUT_STREAM =
|
||||
new DelegatingServletInputStream(StreamUtils.emptyInput());
|
||||
new DelegatingServletInputStream(InputStream.nullInputStream());
|
||||
|
||||
private static final BufferedReader EMPTY_BUFFERED_READER =
|
||||
new BufferedReader(new StringReader(""));
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ import org.springframework.http.server.ServletServerHttpRequest;
|
|||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.annotation.ValidationAnnotationUtils;
|
||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||
|
|
@ -346,7 +345,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements
|
|||
|
||||
@Override
|
||||
public InputStream getBody() {
|
||||
return (this.body != null ? this.body : StreamUtils.emptyInput());
|
||||
return (this.body != null ? this.body : InputStream.nullInputStream());
|
||||
}
|
||||
|
||||
public boolean hasBody() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue