Skip to content
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

Update StreamUtils drain and emptyInput to use JDK builtins #28961

Closed

Conversation

kilink
Copy link
Contributor

@kilink kilink commented Aug 13, 2022

Update StreamUtils.drain to use InputStream.transferTo with a null OutputStream. This avoids allocating buffers for cases where the supplied InputStream has an optimized transferTo method (e.g., ByteArrayInputStream and FileInputStream).

Additionally, update StreamUtils.emptyInput to simply call InputStream.nullInputStream.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 13, 2022
Update StreamUtils.drain to use InputStream.transferTo with a null
OutputStream. This avoids allocating buffers for cases where the
supplied InputStream has an optimized transferTo method (e.g.,
ByteArrayInputStream and FileInputStream).

Additionally, update StreamUtils.emptyInput to simply call
InputStream.nullInputStream.
@kilink kilink force-pushed the stream-utils-drain-empty-input branch from 590ea9d to 646540f Compare August 16, 2022 17:09
@j3graham
Copy link
Contributor

j3graham commented Sep 1, 2022

There are a few more similar opportunities in StreamUtils:

  • copyToByteArray could use in.readAllBytes() instead of going through a ByteArrayOutputStream
  • copy(InputStream in, OutputStream out) could also use transferTo

@kilink
Copy link
Contributor Author

kilink commented Sep 1, 2022

There are a few more similar opportunities in StreamUtils:

  • copyToByteArray could use in.readAllBytes() instead of going through a ByteArrayOutputStream
  • copy(InputStream in, OutputStream out) could also use transferTo

There's already a PR for that here: #27702

@bclozel bclozel self-assigned this Sep 9, 2022
@bclozel bclozel added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 9, 2022
@bclozel bclozel added this to the 6.0.0-M6 milestone Sep 9, 2022
@bclozel bclozel closed this in d4a74c8 Sep 12, 2022
@kilink kilink deleted the stream-utils-drain-empty-input branch March 15, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants