fix: 将解决并发问题的方式由锁改为局部变量

pull/241/head
“yaya” 1 year ago
parent 42cf6b2955
commit 3e08deb50e

@ -16,7 +16,6 @@ import java.nio.file.Files;
* @description:
*/
public class EncodingDetects {
private static UniversalDetector detector = new UniversalDetector(null);
private static final int DEFAULT_LENGTH = 4096;
private static final int LIMIT = 50;
private static final Logger logger = LoggerFactory.getLogger(EncodingDetects.class);
@ -40,13 +39,10 @@ public class EncodingDetects {
if (content != null && content.length <= LIMIT) {
return SimpleEncodingDetects.getJavaEncode(content);
}
String charsetName;
synchronized (EncodingDetects.class) {
detector.reset();
UniversalDetector detector = new UniversalDetector(null);
detector.handleData(content, 0, content.length);
detector.dataEnd();
charsetName = detector.getDetectedCharset();
}
String charsetName = detector.getDetectedCharset();
if (charsetName == null) {
charsetName = Charset.defaultCharset().name();
}

Loading…
Cancel
Save