yy1717
2020-08-21 b8b0a1e54b2d5bc78f2e3ba3561943b959db618a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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<String> {
 
    @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;
        }
    }
}