-
Notifications
You must be signed in to change notification settings - Fork 38.5k
use try-with-resources
statement in ResourceRegionHttpMessageConverter
#35051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use try-with-resources
statement in ResourceRegionHttpMessageConverter
#35051
Conversation
39e24fc
to
746ba02
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
history is mystery.
} | ||
finally { | ||
try { | ||
in.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these is no special handling at all.
we still ignore IO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -173,19 +173,10 @@ protected void writeResourceRegion(ResourceRegion region, HttpOutputMessage outp | |||
responseHeaders.add("Content-Range", "bytes " + start + '-' + end + '/' + resourceLength); | |||
responseHeaders.setContentLength(rangeLength); | |||
|
|||
InputStream in = region.getResource().getInputStream(); | |||
// We cannot use try-with-resources here for the InputStream, since we have | |||
// custom handling of the close() method in a finally-block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these is no special handling at all.
we still ignore IO.
746ba02
to
4373d57
Compare
...ebsocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java
Outdated
Show resolved
Hide resolved
4373d57
to
b317def
Compare
print(out, "Content-Range: bytes " + | ||
region.getPosition() + '-' + (region.getPosition() + region.getCount() - 1) + | ||
'/' + resourceLength); | ||
println(out); | ||
println(out); | ||
// Printing content | ||
StreamUtils.copyRange(in, out, start, end); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -227,14 +219,14 @@ private void writeResourceRegionCollection(Collection<ResourceRegion> resourceRe | |||
println(out); | |||
} | |||
long resourceLength = region.getResource().contentLength(); | |||
end = Math.min(end, resourceLength - inputStreamPosition - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
min,max,modulo
its all used very often from Math
of course, as this is the happy path all around.
print(out, "Content-Range: bytes " + | ||
region.getPosition() + '-' + (region.getPosition() + region.getCount() - 1) + | ||
'/' + resourceLength); | ||
println(out); | ||
println(out); | ||
// Printing content | ||
StreamUtils.copyRange(in, out, start, end); | ||
copyRange(in, out, start, end); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its random impl. detail where this comes from we want to copyRange who how or what seems different concern.
...web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java
Show resolved
Hide resolved
// custom handling of the close() method in a finally-block. | ||
try { | ||
StreamUtils.copyRange(in, outputMessage.getBody(), start, end); | ||
try (var in = region.getResource().getInputStream()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Vincent Potucek <[email protected]>
b317def
to
af07e87
Compare
Sorry but we cannot process PRs like this. Its title says one thing but the content is all over the place, mixing stylistic changes, new attempts at introducing try-with-resources (and some changing the behavior again), a dozen comments and screenshots. Please be more considerate of our time and stop submitting similar PRs. |
yes im sorry. will give test for the catch as im interested now. dont understand so tests will help. can we merge test then at least to improve cover? |
before:
now: