<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<br>
<br>
<div class="moz-cite-prefix">On 29/06/2025 17:03, wenshao wrote:<br>
</div>
<blockquote type="cite" cite="mid:8ea2a983-2f06-405b-8bdc-6ede6bb64ef9.shaojin.wensj@alibaba-inc.com">
<div class="__aliyun_email_body_block">
<div style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun">
<div style="clear: both;"><span>BufferedWriter ->
OutputStreamWriter -> StreamEncoder</span>
<div style="clear: both;"><br>
</div>
<div style="clear: both;">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. </div>
<div style="clear: both;"><br>
</div>
<div style="clear: both;"><span style="color: rgb(0, 0, 0); font-family: Tahoma, Arial, STHeitiSC-Light, SimSun; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">LATIN1
(byte[]) -> UTF16 (char[]) -> UTF8 (byte[])</span></div>
<div style="clear: both;"><span style="color: rgb(0, 0, 0); font-family: Tahoma, Arial, STHeitiSC-Light, SimSun; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;"><br>
</span></div>
<div style="clear: both;">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.</div>
<span>
<div style="clear: both;"><span><br>
</span></div>
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.</span></div>
<br>
</div>
</div>
</blockquote>
I see you've already proposed a PR. Most of this code goes back to
JDK 1.4 so we need to be very careful, any changes will require a
lot of Reviewer cycles.<br>
<br>
Have you surveyed the tests to ensure that there are good tests with
different charsets and usage patterns? I think we need to be
confidence in the tests before touching anything.<br>
<br>
-Alan<br>
</body>
</html>