B.A.S.E.'s BaseFileUtils is writing file using system default charset while reading it using UTF-8
3TUSK opened this issue ยท 1 comments
Synopsis
BaseFileUtils
uses potentially different charset for reading and writing files (specifically the FileUtils.writeStringToFile(file, string, Charset.defaultCharset());
part), which may cause issues when dealing with multiple languages.
BASE/src/main/java/com/teamacronymcoders/base/util/files/BaseFileUtils.java
Lines 133 to 152 in 2ef4890
Reproduction
@wormzjl has the following setup:
- He is using Windows OS with (most likely) a European locale. The exact locale is still unknown so far.
- He was editing
zh_cn.lang
using the${game_dir}/resources
folder-based resourcepack which is provided by B.A.S.E., for his items created via ContentTweaker. - He saves files using UTF-8 encoding.
- After game launches, the file becomes gibberish. It is suspected that the
fixLang
functionality is the culprit:BaseFileUtils.writeStringToFile
as shown above.
Analysis
See above. TLDR: asymmetrical I/O handling to the extent of charset.
Proposed fix
FileUtils.writeStringToFile(file, string, java.nio.charset.StandardCharsets.UTF_8);
Final words
N/A