/**
 * 
 */
package cn.strong.fastdfs.utils;

import io.netty.buffer.ByteBuf;

import java.nio.charset.Charset;

/**
 * 工具类
 * 
 * @author liulongbiao
 *
 */
public class Utils {

	private Utils() {
		super();
	}

	/**
	 * 给 ByteBuf 写入定长字符串
	 * <p>
	 * 若字符串长度大于定长，则截取定长字节；若小于定长，则补零
	 * 
	 * @param buf
	 * @param content
	 * @param length
	 */
	public static void writeFixLength(ByteBuf buf, String content, int length, Charset charset) {
		byte[] bytes = content.getBytes(charset);
		int blen = bytes.length;
		int wlen = blen > length ? length : blen;
		buf.writeBytes(bytes, 0, wlen);
		if (wlen < length) {
			buf.writeZero(length - wlen);
		}
	}

	/**
	 * 读取固定长度的字符串(修剪掉补零的字节)
	 * 
	 * @param in
	 * @param length
	 * @return
	 */
	public static String readString(ByteBuf in, int length, Charset charset) {
		return in.readBytes(length).toString(charset).trim();
	}

	/**
	 * 判断字符串为空
	 * 
	 * @param content
	 * @return
	 */
	public static boolean isEmpty(String content) {
		return content == null || content.isEmpty();
	}

	/**
	 * 获取文件扩展名
	 * 
	 * @param filename
	 * @return
	 */
	public static String getFileExt(String filename) {
		if (filename == null) {
			return "";
		}
		int idx = filename.lastIndexOf('.');
		return idx == -1 ? "" : filename.substring(idx + 1).toLowerCase();
	}
}

@@ -50,65 +50,194 @@
 ort 
-io.netty.buffer.ByteBuf;%0A%0Aimport java.nio.charset.Charset
+static java.nio.charset.StandardCharsets.UTF_8;%0Aimport io.netty.buffer.ByteBuf;%0Aimport io.netty.channel.Channel;%0A%0Aimport java.nio.charset.Charset;%0A%0Aimport cn.strong.fastdfs.client.Consts
 ;%0A%0A/
@@ -1417,11 +1417,298 @@
 se();%0A%09%7D
+%0A%0A%09/**%0A%09 * %E8%8E%B7%E5%8F%96 channel %E4%B8%AD%E7%9A%84 Charset %E5%B1%9E%E6%80%A7%0A%09 * %0A%09 * @param ch%0A%09 * @return%0A%09 */%0A%09public static Charset ensureGetCharset(Channel ch) %7B%0A%09%09Charset charset = ch.attr(Consts.CHARSET).get();%0A%09%09if (charset == null) %7B%0A%09%09%09charset = UTF_8;%0A%09%09%09ch.attr(Consts.CHARSET).set(charset);%0A%09%09%7D%0A%09%09return charset;%0A%09%7D
 %0A%7D%0A

add ensureGetCharset