package com.safeluck.aykj.decoder; import com.safeluck.aykj.utils.BytesUtils; import java.io.UnsupportedEncodingException; /** * Created by zhouwei on 2016/12/3. */ public class UTF8StringDecoder extends BaseDecoder { @Override public String decode(String str) { if(str==null) return null; byte[] bytes = BytesUtils.hexStringToBytes(str); try { return new String(bytes,"utf-8"); } catch (UnsupportedEncodingException e) { return null; } } @Override public String encode(String str) { try { if(str==null) return null; return BytesUtils.bytesToHexString(str.getBytes("utf-8")); } catch (UnsupportedEncodingException e) { return null; } } }