ResourceHttpMessageConverter allows for using InputStreamResource

Issue: SPR-13443
This commit is contained in:
Juergen Hoeller
2015-09-08 11:04:34 +02:00
parent e393c7b1ee
commit 1feb757c54
2 changed files with 33 additions and 13 deletions

View File

@@ -40,6 +40,8 @@ import org.springframework.util.StringUtils;
* If JAF is not available, {@code application/octet-stream} is used.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author Kazuki Shimizu
* @since 3.0.2
*/
public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<Resource> {
@@ -62,8 +64,16 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
return new ByteArrayResource(body);
if (InputStreamResource.class == clazz){
return new InputStreamResource(inputMessage.getBody());
}
else if (clazz.isAssignableFrom(ByteArrayResource.class)) {
byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
return new ByteArrayResource(body);
}
else {
throw new IllegalStateException("Unsupported resource class: " + clazz);
}
}
@Override