Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<aspose-cad.version>23.7</aspose-cad.version>
<bcprov-jdk15on.version>1.70</bcprov-jdk15on.version>
<juniversalchardet.version>1.0.3</juniversalchardet.version>
<icu4j.version>70.1</icu4j.version>

<commons-cli.version>1.5.0</commons-cli.version>
<commons-net.version>3.9.0</commons-net.version>
Expand Down
5 changes: 5 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
<artifactId>juniversalchardet</artifactId>
<version>${juniversalchardet.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>${icu4j.version}</version>
</dependency>

<!-- 解压(rar)-->
<dependency>
Expand Down
11 changes: 10 additions & 1 deletion server/src/main/java/cn/keking/utils/EncodingDetects.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cn.keking.utils;

import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch;
import org.mozilla.universalchardet.UniversalDetector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -44,7 +46,14 @@ public static String getJavaEncode(byte[] content) {
detector.dataEnd();
String charsetName = detector.getDetectedCharset();
if (charsetName == null) {
charsetName = Charset.defaultCharset().name();
CharsetDetector cd = new CharsetDetector();
cd.setText(content);
CharsetMatch cm = cd.detect();
if (cm != null) {
charsetName = cm.getName();
} else {
charsetName = Charset.defaultCharset().name();
}
}
return charsetName;
}
Expand Down