Skip to content

Update StreamUtils drain and emptyInput to use JDK builtins - #28961

Closed
kilink wants to merge 1 commit into
spring-projects:mainfrom
kilink:stream-utils-drain-empty-input
Closed

Update StreamUtils drain and emptyInput to use JDK builtins#28961
kilink wants to merge 1 commit into
spring-projects:mainfrom
kilink:stream-utils-drain-empty-input

Conversation

@kilink

@kilink kilink commented Aug 13, 2022

Copy link
Copy Markdown
Contributor

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

j3graham commented Sep 1, 2022

Copy link
Copy Markdown
Contributor

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

kilink commented Sep 1, 2022

Copy link
Copy Markdown
Contributor Author

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.

4 participants