<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><div  style="clear: both;"><span ><br ></span></div><div  style="clear: both;"><span >-</span></div><div  style="clear: both;"><span >Shaojin Wen</span></div></div></div>