Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1f02d2

Browse files
author
Vincent Potucek
committedJun 13, 2025
simplify try with resource
Signed-off-by: Vincent Potucek <[email protected]>
1 parent a143254 commit f1f02d2

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed
 

‎spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,10 @@ protected void writeResourceRegion(ResourceRegion region, HttpOutputMessage outp
173173
responseHeaders.add("Content-Range", "bytes " + start + '-' + end + '/' + resourceLength);
174174
responseHeaders.setContentLength(rangeLength);
175175

176-
InputStream in = region.getResource().getInputStream();
177-
// We cannot use try-with-resources here for the InputStream, since we have
178-
// custom handling of the close() method in a finally-block.
179-
try {
176+
try (InputStream in = region.getResource().getInputStream()) {
180177
StreamUtils.copyRange(in, outputMessage.getBody(), start, end);
181-
}
182-
finally {
183-
try {
184-
in.close();
185-
}
186-
catch (IOException ex) {
187-
// ignore
188-
}
178+
} catch (IOException ex) {
179+
// ignore
189180
}
190181
}
191182

0 commit comments

Comments
 (0)
Please sign in to comment.