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

Merge pull request !28 from songdragon/fix-I7VP0I
This commit is contained in:
Luke 2023-08-24 13:38:41 +00:00 committed by Gitee
commit cda1f95b75
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -36,10 +36,12 @@ public class EncodingDetector {
CharsetDetector charsetDetector = new CharsetDetector();
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
charsetDetector.setText(inputStream);
CharsetMatch match = charsetDetector.detect();
LOG.debug("{} : {}", match.getName(), match.getConfidence());
if (match.getConfidence() > 50) {
return match.getName();
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);