RFR: 8361018: Re-examine buffering and encoding conversion in BufferedWriter [v3]

Shaojin Wen swen at openjdk.org
Mon Jun 30 18:26:56 UTC 2025


> BufferedWriter -> OutputStreamWriter -> StreamEncoder
> 
> In this call chain, BufferedWriter has a char[] buffer, and StreamEncoder has a ByteBuffer. There are two layers of cache here, or the BufferedWriter layer can be removed. And when charset is UTF8, if the content of write(String) is LATIN1, a conversion from LATIN1 to UTF16 and then to LATIN1 will occur here.
> 
> LATIN1 -> UTF16 -> UTF8
> 
> We can improve BufferedWriter. When the parameter Writer instanceof OutputStreamWriter is passed in, remove the cache and call it directly. In addition, improve write(String) in StreamEncoder to avoid unnecessary encoding conversion.

Shaojin Wen has updated the pull request incrementally with three additional commits since the last revision:

 - bug fix for encodeUTF8
 - bug fix for encodeUTF8
 - bug fix for encodeUTF8

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/26022/files
  - new: https://git.openjdk.org/jdk/pull/26022/files/e1e9e25b..f4f97c26

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=26022&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=26022&range=01-02

  Stats: 8 lines in 1 file changed: 3 ins; 0 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/26022.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26022/head:pull/26022

PR: https://git.openjdk.org/jdk/pull/26022


More information about the nio-dev mailing list