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

The following examples show how to use cn.hutool.core.util.CharsetUtil#convert() . 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 6 votes vote down vote up
/**
 * 读取文件内容
 *
 * @throws IOException IO
 */
private void read() throws IOException {
    final long currentLength = randomFile.length();
    final long position = randomFile.getFilePointer();
    if (0 == currentLength || currentLength == position) {
        // 内容长度不变时忽略此次
        return;
    } else if (currentLength < position) {
        // 如果内容变短,说明文件做了删改,回到内容末尾
        randomFile.seek(currentLength);
        return;
    }
    String tmp;
    while ((tmp = randomFile.readLine()) != null) {
        tmp = CharsetUtil.convert(tmp, CharsetUtil.CHARSET_ISO_8859_1, charset);
        limitQueue.offer(tmp);
        lineHandler.handle(tmp);
    }
    // 记录当前读到的位置
    this.randomFile.seek(currentLength);
}
 
Example 2
Source File: BaseAgentController.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 获取server 端操作人
 *
 * @param request req
 * @return name
 */
private static String getUserName(HttpServletRequest request) {
    String name = ServletUtil.getHeaderIgnoreCase(request, ConfigBean.JPOM_SERVER_USER_NAME);
    name = CharsetUtil.convert(name, CharsetUtil.CHARSET_ISO_8859_1, CharsetUtil.CHARSET_UTF_8);
    name = StrUtil.emptyToDefault(name, StrUtil.DASHED);
    return URLUtil.decode(name, CharsetUtil.CHARSET_UTF_8);
}
 
Example 3
Source File: FileTailWatcherRun.java    From Jpom with MIT License 5 votes vote down vote up
private void readLine() throws IOException {
    String line = randomFile.readLine();
    if (line != null) {
        line = CharsetUtil.convert(line, CharsetUtil.CHARSET_ISO_8859_1, charset);
        limitQueue.offerFirst(line);
    }
}
 
Example 4
Source File: ServletUtils.java    From yue-library with Apache License 2.0 3 votes vote down vote up
/**
 * 获得请求header中的信息
 * 
 * @param name 头信息的KEY
 * @param charset 字符集
 * @return header值
 * @since 4.6.2
 */
public static String getHeader(String name, Charset charset) {
	final String header = getRequest().getHeader(name);
	if (null != header) {
		return CharsetUtil.convert(header, CharsetUtil.CHARSET_ISO_8859_1, charset);
	}
	return null;
}