Skip to content

Use InputStream.transferTo() instead of FileUtil.copy() and simplify usages#9278

Merged
mbien merged 1 commit intoapache:masterfrom
mbien:use-transferto
Mar 18, 2026
Merged

Use InputStream.transferTo() instead of FileUtil.copy() and simplify usages#9278
mbien merged 1 commit intoapache:masterfrom
mbien:use-transferto

Conversation

@mbien
Copy link
Copy Markdown
Member

@mbien mbien commented Mar 16, 2026

waited with this until most of the codebase migrated to JDK 17+ (#8813), so that we don't have to do it multiple times.

motivation:

  • JDK's InputStream implementation of transferTo() is somewhat similar to FileUtil.copy() (the buffer is a little bit smaller)
  • subclasses like BufferedInputStream, FileInputStream and others have specialized implementations

changes:

  • deprecated FileUtil.copy() and replaced usage with transferTo()
  • bumped enterprise/web.jsf.navigation, enterprise/web.jsf, enterprise/websvc.utilities and groovy/groovy.samples to release 17
  • bumped remaining rust cluster to release 21
  • some sections were further simplified after inlining (ARM, readAllBytes() or write(bytes) conversions)

@mbien mbien added this to the NB30 milestone Mar 16, 2026
@mbien mbien added Code cleanup Label for cleanup done on the Netbeans IDE performance tests ci:all-tests [ci] enable all tests labels Mar 16, 2026
Copy link
Copy Markdown
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I caught a few instances where a ByteArrayInputStream was used just to write a byte array to a stream. I don't see a reason, so I suggest to dump that.

There were other instances that could be replaced with InputStream#readAllBytes, but I scrolled through them until I noticed that, so I suggest to ignore these for now.

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Mar 16, 2026

There were other instances that could be replaced with InputStream#readAllBytes(),

I revisited the code section where the method was inlined and rewrote some of the usages as simplified ARM blocks, using readAllBytes(), write(bytes) and transferTo(). This removed about 700 lines.

I am not really expecting anyone to review this via github this since the changeset is now larger. Might be easier via IDE. I will take another good look myself before merging.

@mbien mbien force-pushed the use-transferto branch 3 times, most recently from cf8afa3 to d2a9dc8 Compare March 17, 2026 02:13
motivation:

 - JDK's InputStream implementation of transferTo() is somewhat
   similar to FileUtil.copy() (the buffer is a little bit smaller)
 - subclasses like BufferedInputStream, FileInputStream and others
   have specialized implementations

changes:

 - deprecated FileUtil.copy() and replaced usage with transferTo()
 - bumped enterprise/web.jsf.navigation, enterprise/web.jsf,
   enterprise/websvc.utilities and groovy/groovy.samples to release 17
 - bumped remaining rust cluster to release 21
 - some sections were further simplified after inlining (ARM,
   readAllBytes() or write() conversions)
@mbien mbien force-pushed the use-transferto branch 2 times, most recently from 2c882f2 to 3909ded Compare March 18, 2026 02:22
@mbien
Copy link
Copy Markdown
Member Author

mbien commented Mar 18, 2026

looked through it again. will merge once CI is done.

@mbien mbien changed the title Use InputStream.transferTo() instead of FileUtil.copy() Use InputStream.transferTo() instead of FileUtil.copy() and simplify usages Mar 18, 2026
@mbien mbien merged commit 8c58a9d into apache:master Mar 18, 2026
76 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:all-tests [ci] enable all tests Code cleanup Label for cleanup done on the Netbeans IDE performance tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants