Repository navigation
CAMEL-26390: camel-core - IOConverter: convert an InputStream to String without the BufferedReader/StringBuilder chain - #28649
Conversation
…ng without the BufferedReader/StringBuilder chain IOConverter.toString(InputStream, Exchange) went through an InputStreamReader, a BufferedReader and a StringBuilder, which allocate about 29 KB of buffers per call. InputStreamCache, the default in-memory stream cache, takes the same path, so every String view of a stream body paid this. Read the bytes and decode them at once with the charset of the exchange instead, and close the stream as before. Measured locally on a 1 KB body (JDK 25 on macOS, single thread, after warm-up): 877 ns and 29,136 B per call before, 141 ns and 2,115 B after. Part of CAMEL-25132 (tier 1, item apache#5). _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._ Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔁 5 tests passed only after a retry on JDK 21 (5 retried attempts) Recovered flaky tests on JDK 21 (5)
🔬 Scalpel shadow comparison — Scalpel: 570 of 708 tested, 27 compile-only — current: 571 all testedMaveniverse Scalpel detected 570 affected modules (current approach: 571). Skip-tests mode would test 570 modules (2 direct + 568 downstream), skip tests for 27 (generated code, meta-modules) Modules only in current approach (1)
Modules Scalpel would test (570)
Modules with tests skipped (27)
Build reactor — dependencies compiled but only changed modules were tested (2 modules, 7.6s total)Total reactor time: 7.6s
Top 20 slowest modules:
|
davsclaus
left a comment
There was a problem hiding this comment.
The charset is resolved before reading with the same ExchangeHelper.getCharset as before, the stream is closed in finally, and malformed-input replacement and BOM handling are the same as InputStreamReader. LGTM.
Nit: IOConverterTest.java:311 has a literal U+FFFD in the string; \uFFFD is clearer and safe against source-encoding mishaps.
Reviewed with Claude Code on behalf of @davsclaus. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.
Description
CAMEL-26390, tier 1 item #5 of CAMEL-25132.
IOConverter.toString(InputStream, Exchange)went through anInputStreamReader, aBufferedReaderand aStringBuilder.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 withnew String(in.readAllBytes(), charset), using the charset of the exchange as before, and closes the stream in afinallyasIOHelper.toStringdid.Behavior kept: malformed input is replaced with U+FFFD by both
InputStreamReaderandnew 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,
ThreadMXBeanallocated bytes) on a 1 KB body:New tests in
IOConverterTestthat pin the behavior (they pass before and after the change):Verified: 401 tests in camel-core (
IOConverterTest,NIOConverterTest,JaxpTest,*StreamCach*Test,*Converter*Test,ConvertBody*Test). The 2 skipped tests are@Disabledon main. The generatedCamelBaseBulkConverterLoaderis unchanged because the signature is the same.Target
mainbranch)Tracking
Apache Camel coding standards and style
I checked that each commit in the pull request has a meaningful subject line and body.
I have run
mvn clean install -DskipTestslocally 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:sorton the changed modules, andgit statuswas clean afterwards.AI-assisted contributions
Co-authored-bytrailers) 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 on behalf of Adriano Machado (@ammachado)
This was generated by an AI agent and may contain inaccuracies. Please verify before relying on it.