Close InputStream in ResourceHttpMessageConverter
Spring 3.2.2 introduced a change to avoid closing the response stream in HttpMessageConverters (SPR-10095). However, the InputStream of resources being written, for example as part of a multi-part request should be closed. This change ensures that. Issue: SPR-10460
This commit is contained in:
parent
be224e1f30
commit
ad272a0c87
|
|
@ -85,7 +85,17 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||||
protected void writeInternal(Resource resource, HttpOutputMessage outputMessage)
|
protected void writeInternal(Resource resource, HttpOutputMessage outputMessage)
|
||||||
throws IOException, HttpMessageNotWritableException {
|
throws IOException, HttpMessageNotWritableException {
|
||||||
|
|
||||||
StreamUtils.copy(resource.getInputStream(), outputMessage.getBody());
|
InputStream in = resource.getInputStream();
|
||||||
|
try {
|
||||||
|
StreamUtils.copy(in, outputMessage.getBody());
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
outputMessage.getBody().flush();
|
outputMessage.getBody().flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue