ammachado opened a new pull request, #28649:
URL: https://github.com/apache/camel/pull/28649

   # Description
   
   [CAMEL-26390](https://issues.apache.org/jira/browse/CAMEL-26390), tier 1 
item #5 of [CAMEL-25132](https://issues.apache.org/jira/browse/CAMEL-25132).
   
   `IOConverter.toString(InputStream, Exchange)` went through an 
`InputStreamReader`, a `BufferedReader` and a `StringBuilder`. 
`InputStreamCache`, the default in-memory stream cache, takes the same path, so 
every String view of an HTTP, JMS or file stream body paid for these buffers. 
This change reads the bytes and decodes them at once with `new 
String(in.readAllBytes(), charset)`, using the charset of the exchange as 
before, and closes the stream in a `finally` as `IOHelper.toString` did.
   
   Behavior kept: malformed input is replaced with U+FFFD by both 
`InputStreamReader` and `new String`, neither strips a BOM, and both read from 
the current position of the stream. The charset is resolved before reading, as 
before.
   
   Measured locally (JDK 25 on macOS, single thread, 200k calls after 200k 
warm-up calls, `ThreadMXBean` allocated bytes) on a 1 KB body:
   
   | | ns/op | bytes/op |
   |---|---|---|
   | before | 877 | 29,136 |
   | after | 141 | 2,115 |
   
   New tests in `IOConverterTest` that pin the behavior (they pass before and 
after the change):
   - the exchange charset is used (UTF-8 and UTF-16), with multi-byte 
characters at every offset in a text longer than the reader buffers, and the 
stream is closed;
   - malformed UTF-8 is replaced with U+FFFD;
   - reading starts at the current position of the stream.
   
   Verified: 401 tests in camel-core (`IOConverterTest`, `NIOConverterTest`, 
`JaxpTest`, `*StreamCach*Test`, `*Converter*Test`, `ConvertBody*Test`). The 2 
skipped tests are `@Disabled` on main. The generated 
`CamelBaseBulkConverterLoader` is unchanged because the signature is the same.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     Not from the root folder: I built and installed the changed module 
(camel-base), ran `mvn formatter:format impsort:sort` on the changed modules, 
and `git status` was clean afterwards.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   The code and this description were written with Claude Code (Claude Opus 
5.5) and reviewed by me.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code) on behalf of 
Adriano Machado (@ammachado)
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to