Use InputStream's new methods instead of StreamUtils#27702
Use InputStream's new methods instead of StreamUtils#27702yaboong wants to merge 2 commits intospring-projects:mainfrom
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.
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.
@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.
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.
@yaboong Thanks. It's a good idea to use transferTo() within the copy method.
There was a problem hiding this comment.
@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 byInputStreamin JDK9 instead ofStreamUtils.