mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 20:08:40 +08:00
取消自动识别文件编码格式模块 auto-charset-jchardet
This commit is contained in:
parent
5b2de46a6e
commit
977dd7347a
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
## 2.10.0
|
||||
|
||||
### 🐣 新增功能
|
||||
@ -19,4 +17,5 @@
|
||||
4. 【all】删除 项目内存监控页面
|
||||
5. 【all】配置文件名称由 `extConfig.yml` 变更为 `application.yml`
|
||||
6. 【all】调整项目打包目录结构
|
||||
7. 【all】取消兼容低版本数据目录文件迁移(调试运行)
|
||||
7. 【all】取消兼容低版本数据目录文件迁移(调试运行)
|
||||
8. 【all】取消自动识别文件编码格式模块 `auto-charset-jchardet`
|
@ -27,7 +27,6 @@ import cn.hutool.core.io.file.Tailer;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jpom.plugin.PluginFactory;
|
||||
import io.jpom.system.ExtConfigBean;
|
||||
import io.jpom.system.JpomRuntimeException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -39,9 +38,9 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -71,17 +70,7 @@ public abstract class BaseFileTailWatcher<T> {
|
||||
|
||||
public static Charset detectorCharset(File logFile) {
|
||||
Charset detSet = ExtConfigBean.getInstance().getLogFileCharset();
|
||||
if (detSet == null) {
|
||||
try {
|
||||
String charsetName = (String) PluginFactory.getPlugin("charset-detector").execute(logFile);
|
||||
detSet = StrUtil.isEmpty(charsetName) ? CharsetUtil.CHARSET_UTF_8 : CharsetUtil.charset(charsetName);
|
||||
} catch (Exception e) {
|
||||
log.warn("自动识别文件编码格式错误:{}", e.getMessage());
|
||||
detSet = CharsetUtil.CHARSET_UTF_8;
|
||||
}
|
||||
detSet = (detSet == StandardCharsets.US_ASCII) ? CharsetUtil.CHARSET_UTF_8 : detSet;
|
||||
}
|
||||
return detSet;
|
||||
return Optional.ofNullable(detSet).orElse(CharsetUtil.CHARSET_UTF_8);
|
||||
}
|
||||
|
||||
protected void send(T session, String msg) {
|
||||
|
@ -53,12 +53,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jpom.plugins</groupId>
|
||||
<artifactId>auto-charset-jchardet</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--websocket作为客户端-->
|
||||
<dependency>
|
||||
<groupId>org.java-websocket</groupId>
|
||||
|
@ -1,114 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Code Technology Studio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>jpom-plugins-parent</artifactId>
|
||||
<groupId>io.jpom.plugins</groupId>
|
||||
<version>2.9.20</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>auto-charset-jchardet</artifactId>
|
||||
<name>plugin-auto-charset-jchardet</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 文件编码识别-->
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.jchardet</groupId>
|
||||
<artifactId>jchardet</artifactId>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jpom</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<!-- 是否指定项目classpath下的依赖 -->
|
||||
<addClasspath>true</addClasspath>
|
||||
<!-- 指定依赖的时候声明前缀 -->
|
||||
<classpathPrefix>./</classpathPrefix>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<!-- 项目版本号 -->
|
||||
<Jpom-Project-Version>${project.version}</Jpom-Project-Version>
|
||||
<!-- 打包时间 -->
|
||||
<Jpom-Timestamp>${maven.build.timestamp}</Jpom-Timestamp>
|
||||
<Jpom-Type>${project.artifactId}</Jpom-Type>
|
||||
<Implementation-URL>https://gitee.com/dromara/Jpom</Implementation-URL>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<!--这里要替换成jar包main方法所在类 -->
|
||||
</manifest>
|
||||
</archive>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<descriptors>
|
||||
<descriptor>script/release.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
|
||||
<executions>
|
||||
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- 指定在打包节点执行jar包合并操作 -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,55 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Code Technology Studio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
-->
|
||||
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">
|
||||
<id>release</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
<unpack>true</unpack>
|
||||
<scope>runtime</scope>
|
||||
<includes>
|
||||
<include>net.sourceforge.jchardet:jchardet</include>
|
||||
</includes>
|
||||
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.build.directory}/classes</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
|
||||
</assembly>
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Code Technology Studio
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.jpom.plugin;
|
||||
|
||||
import org.mozilla.intl.chardet.nsDetector;
|
||||
import org.mozilla.intl.chardet.nsICharsetDetectionObserver;
|
||||
import org.mozilla.intl.chardet.nsPSMDetector;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* 文件编码识别器
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
public class CharsetDetector implements nsICharsetDetectionObserver {
|
||||
|
||||
private boolean found = false;
|
||||
private String result;
|
||||
|
||||
public String detectChineseCharset(File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException(file.getAbsolutePath());
|
||||
}
|
||||
String[] val = detectChineseCharset(new FileInputStream(file));
|
||||
if (val == null || val.length <= 0) {
|
||||
return null;
|
||||
}
|
||||
return val[0];
|
||||
}
|
||||
|
||||
private String[] detectChineseCharset(InputStream in) throws IOException {
|
||||
// Initalize the nsDetector() ;
|
||||
nsDetector det = new nsDetector(nsPSMDetector.CHINESE);
|
||||
// Set an observer...
|
||||
// The Notify() will be called when a matching charset is found.
|
||||
det.Init(this);
|
||||
BufferedInputStream imp = new BufferedInputStream(in);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
boolean isAscii = true;
|
||||
while ((len = imp.read(buf, 0, buf.length)) != -1) {
|
||||
// Check if the stream is only ascii.
|
||||
if (isAscii) {
|
||||
isAscii = det.isAscii(buf, len);
|
||||
}
|
||||
// DoIt if non-ascii and not done yet.
|
||||
if (!isAscii) {
|
||||
if (det.DoIt(buf, len, false)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
imp.close();
|
||||
in.close();
|
||||
det.DataEnd();
|
||||
String[] prob;
|
||||
if (isAscii) {
|
||||
found = true;
|
||||
prob = new String[]{"ASCII"};
|
||||
} else if (found) {
|
||||
prob = new String[]{result};
|
||||
} else {
|
||||
prob = det.getProbableCharsets();
|
||||
}
|
||||
return prob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Notify(String charset) {
|
||||
found = true;
|
||||
result = charset;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Code Technology Studio
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package io.jpom.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author bwcx_jzy
|
||||
* @since 2021/12/24
|
||||
*/
|
||||
@PluginConfig(name = "charset-detector")
|
||||
public class DefaultFileCharsetDetectorImpl implements IDefaultPlugin {
|
||||
|
||||
@Override
|
||||
public Object execute(Object main, Map<String, Object> parameter) throws Exception {
|
||||
File file = (File) main;
|
||||
return new CharsetDetector().detectChineseCharset(file);
|
||||
}
|
||||
}
|
@ -38,7 +38,6 @@
|
||||
<module>email</module>
|
||||
<module>svn-clone</module>
|
||||
<module>maven-plugin</module>
|
||||
<module>auto-charset-jchardet</module>
|
||||
<module>db-h2</module>
|
||||
<module>docker-cli</module>
|
||||
<module>git-clone</module>
|
||||
|
Loading…
Reference in New Issue
Block a user