fix: #I7VP0I 检测文件编码时尝试所有可能顺序

This commit is contained in:
songdragon 2023-08-24 18:01:58 +08:00
parent c4b998100e
commit f7505f6063

View File

@ -36,11 +36,13 @@ public class EncodingDetector {
CharsetDetector charsetDetector = new CharsetDetector();
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
charsetDetector.setText(inputStream);
CharsetMatch match = charsetDetector.detect();
CharsetMatch[] matchList = charsetDetector.detectAll();
for (CharsetMatch match : matchList) {
LOG.debug("{} : {}", match.getName(), match.getConfidence());
if (match.getConfidence() > 50) {
return match.getName();
}
}
} catch (Exception e) {
LOG.error("", e);
}