Skip to content

Commit

Permalink
Close InputStream in ResourceHttpMessageConverter
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rstoyanchev committed May 10, 2013
1 parent 6fa4939 commit 30db112
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ protected Long getContentLength(Resource resource, MediaType contentType) throws
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();
}

Expand Down

0 comments on commit 30db112

Please sign in to comment.