Skip to content

GH-3549: Leverage JDK11 readNBytes#3550

Closed
Fokko wants to merge 3 commits intoapache:masterfrom
Fokko:fd-readnbytes
Closed

GH-3549: Leverage JDK11 readNBytes#3550
Fokko wants to merge 3 commits intoapache:masterfrom
Fokko:fd-readnbytes

Conversation

@Fokko
Copy link
Copy Markdown
Contributor

@Fokko Fokko commented May 6, 2026

Introduced in JDK11 and is more efficient.

Closes #3549

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@Fokko Fokko force-pushed the fd-readnbytes branch from 28800db to d87f0e2 Compare May 6, 2026 21:31
Introduced in JDK11 and is more efficient.

Closes apache#3549
@Fokko Fokko force-pushed the fd-readnbytes branch from d87f0e2 to 2aa6f06 Compare May 7, 2026 12:35
LOG.debug("read all {} bytes", byteCount);
byte[] buf = new byte[byteCount];
new DataInputStream(in).readFully(buf);
byte[] buf = in.readNBytes(byteCount);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hadn't noticed this before. Doesn't look like anything in the JDK has actually subclassed it ... that is there's no AFAIK there's no faster native code version. That's probably because java.nio is the way to go there

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it is nice to avoid the wrapper DataInputStream here. The biggest win here is in writeAllTo where we don't allocate all the bytes directly into memory, but respecting byteCount.

Copy link
Copy Markdown
Contributor

@steveloughran steveloughran left a comment

Choose a reason for hiding this comment

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

commented

@Fokko
Copy link
Copy Markdown
Contributor Author

Fokko commented May 10, 2026

There seems to be an issue with NonBlockedDecompressorStream reads, which renders this PR more-or-less useless :)

@Fokko Fokko closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leverage JDK11 readNBytes

2 participants