ResourceRegion fits better in core.io.support (next to EncodedResource)
Issue: SPR-14221
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceRegion;
|
||||
import org.springframework.core.io.support.ResourceRegion;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -64,7 +64,7 @@ public abstract class HttpRange {
|
||||
* information contained in the current {@code HttpRange}.
|
||||
* @param resource the {@code Resource} to select the region from
|
||||
* @return the selected region of the given {@code Resource}
|
||||
* @since 4.3.0
|
||||
* @since 4.3
|
||||
*/
|
||||
public ResourceRegion toResourceRegion(Resource resource) {
|
||||
// Don't try to determine contentLength on InputStreamResource - cannot be read afterwards...
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.core.io.ResourceRegion;
|
||||
import org.springframework.core.io.support.ResourceRegion;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
@@ -33,11 +33,11 @@ import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Implementation of {@link HttpMessageConverter} that can write a single {@link ResourceRegion ResourceRegion},
|
||||
* Implementation of {@link HttpMessageConverter} that can write a single {@link ResourceRegion},
|
||||
* or Collections of {@link ResourceRegion ResourceRegions}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 4.3.0
|
||||
* @since 4.3
|
||||
*/
|
||||
public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessageConverter<Object> {
|
||||
|
||||
@@ -45,6 +45,32 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
|
||||
super(MediaType.ALL);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean supports(Class<?> clazz) {
|
||||
// should not be called as we override canRead/canWrite
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceRegion readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
|
||||
return canWrite(clazz, null, mediaType);
|
||||
@@ -152,6 +178,7 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
|
||||
print(out, "--" + boundaryString + "--");
|
||||
}
|
||||
|
||||
|
||||
private static void println(OutputStream os) throws IOException {
|
||||
os.write('\r');
|
||||
os.write('\n');
|
||||
@@ -161,28 +188,4 @@ public class ResourceRegionHttpMessageConverter extends AbstractGenericHttpMessa
|
||||
os.write(buf.getBytes("US-ASCII"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supports(Class<?> clazz) {
|
||||
// should not be called as we override canRead/canWrite
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceRegion readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage)
|
||||
throws IOException, HttpMessageNotReadableException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.http;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -22,13 +23,13 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.ResourceRegion;
|
||||
import org.springframework.core.io.support.ResourceRegion;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link HttpRange}.
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.http.converter;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@@ -30,13 +27,16 @@ import org.junit.Test;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceRegion;
|
||||
import org.springframework.core.io.support.ResourceRegion;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpRange;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.MockHttpOutputMessage;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test cases for {@link ResourceRegionHttpMessageConverter} class.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user