Java Code Examples for cn.hutool.core.util.CharsetUtil#charset()

The following examples show how to use cn.hutool.core.util.CharsetUtil#charset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileTailWatcherRun.java    From Jpom with MIT License 5 votes vote down vote up
FileTailWatcherRun(File file, LineHandler lineHandler) throws IOException {
    this.lineHandler = lineHandler;
    this.randomFile = new RandomAccessFile(file, FileMode.r.name());
    Charset detSet = ExtConfigBean.getInstance().getLogFileCharset();
    if (detSet == null) {
        detSet = CharsetUtil.charset(new CharsetDetector().detectChineseCharset(file));
        detSet = (detSet == StandardCharsets.US_ASCII) ? CharsetUtil.CHARSET_UTF_8 : detSet;
    }
    this.charset = detSet;
    if (file.length() > 0) {
        // 开始读取
        this.startRead();
    }
}
 
Example 2
Source File: ExtConfigBean.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 单例
 *
 * @return this
 */
public static ExtConfigBean getInstance() {
    if (extConfigBean == null) {
        extConfigBean = SpringUtil.getBean(ExtConfigBean.class);
        // 读取配置的编码格式
        if (StrUtil.isNotBlank(extConfigBean.logFileCharset)) {
            try {
                extConfigBean.logFileCharsets = CharsetUtil.charset(extConfigBean.logFileCharset);
            } catch (Exception ignored) {
            }
        }
    }
    return extConfigBean;
}