-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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 InputStream's new methods instead of StreamUtils #27702
Conversation
* @return the number of bytes copied | ||
* @throws IOException in case of I/O errors | ||
*/ | ||
public static int copy(InputStream in, OutputStream out) throws IOException { |
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.
Don't delete it. We have many legacy projects that still use this functionality. I propose to do this deprecate.
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.
@AntonLGVS Restored the method I deleted, thanks.
If it's still needed to support legacy projects, how about making this method use transferTo()
in InputStream
?
like below
public static int copy(InputStream in, OutputStream out) throws IOException {
Assert.notNull(in, "No InputStream specified");
Assert.notNull(out, "No OutputStream specified");
int byteCount = (int) in.transferTo(out);
out.flush();
return byteCount;
}
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.
I'm not sure Spring should keep StreamUtils#copy method. For Utils such as copy method, It looks like more proper to use apache commons or guava libraries for legacy projects.
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.
@yaboong Thanks. It's a good idea to use transferTo()
within the copy
method.
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.
@bananayong Why use an external library when Spring provides a basic set of methods. If you want to delete, you must first make a deprecate to give time for the transition. Otherwise, updating the spring package will break everything.
As Spring Framework 6 uses JDK17 for its baseline, we can make use of the methods
transferTo(OutputStream out)
andreadAllBytes()
supported byInputStream
in JDK9 instead ofStreamUtils
.