Skip to content

Fix HttpSender.Response.getBody() InputStream performance and EOF handling#6381

Merged
pstreef merged 1 commit intomainfrom
fix/httpsender-response-bulk-read
Dec 4, 2025
Merged

Fix HttpSender.Response.getBody() InputStream performance and EOF handling#6381
pstreef merged 1 commit intomainfrom
fix/httpsender-response-bulk-read

Conversation

@pstreef
Copy link
Copy Markdown
Contributor

@pstreef pstreef commented Dec 4, 2025

Problem

  • Same issue as Fix RemoteArchive performance by adding bulk read methods #6377: the HttpSender.Response.getBody() method returns an anonymous InputStream wrapper that only overrides the single-byte read() method. When consumers call the bulk read(byte[], int, int) method, Java's default InputStream implementation falls back to calling read() one byte at a time in a loop, resulting in extremely poor performance.

Additionally, the single-byte read() method incorrectly returns 0 when the body is null, but per the InputStream contract, -1 should be returned to indicate end of stream.

Solution

  • Add read(byte[] b, int off, int len) override to delegate bulk reads to the underlying stream
  • Fix EOF return value from 0 to -1 per the InputStream contract

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Dec 4, 2025
@pstreef pstreef marked this pull request as ready for review December 4, 2025 21:55
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Dec 4, 2025
@pstreef pstreef merged commit 0624256 into main Dec 4, 2025
1 of 2 checks passed
@pstreef pstreef deleted the fix/httpsender-response-bulk-read branch December 4, 2025 21:59
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants