fix: #I7VP0I 检测文件编码时尝试所有可能顺序
This commit is contained in:
parent
c4b998100e
commit
f7505f6063
@ -36,10 +36,12 @@ public class EncodingDetector {
|
|||||||
CharsetDetector charsetDetector = new CharsetDetector();
|
CharsetDetector charsetDetector = new CharsetDetector();
|
||||||
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
|
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
|
||||||
charsetDetector.setText(inputStream);
|
charsetDetector.setText(inputStream);
|
||||||
CharsetMatch match = charsetDetector.detect();
|
CharsetMatch[] matchList = charsetDetector.detectAll();
|
||||||
LOG.debug("{} : {}", match.getName(), match.getConfidence());
|
for (CharsetMatch match : matchList) {
|
||||||
if (match.getConfidence() > 50) {
|
LOG.debug("{} : {}", match.getName(), match.getConfidence());
|
||||||
return match.getName();
|
if (match.getConfidence() > 50) {
|
||||||
|
return match.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("", e);
|
LOG.error("", e);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user