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
6fa493908b
commit
30db112d37
|
@ -85,7 +85,17 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
|||
protected void writeInternal(Resource resource, HttpOutputMessage outputMessage)
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue