1 package cn.home1.oss.lib.common;
2
3 import static org.apache.commons.codec.CharEncoding.UTF_8;
4
5 import lombok.SneakyThrows;
6
7 import org.apache.commons.codec.net.URLCodec;
8
9
10
11
12 public abstract class CodecUtils {
13
14 private CodecUtils() {
15 }
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public static String encodeBase64(final byte[] raw) {
32 return java.util.Base64.getEncoder().encodeToString(raw);
33 }
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 @SneakyThrows
49 public static byte[] decodeBase64(final String base64String) {
50 return java.util.Base64.getDecoder().decode(base64String);
51 }
52
53 private static final URLCodec URL_CODEC = new URLCodec(UTF_8);
54
55
56
57
58
59
60
61
62
63
64
65
66 @SneakyThrows
67 public static String urlEncode(final String text) {
68 return text != null ? URL_CODEC.encode(text) : null;
69 }
70
71 @SneakyThrows
72 public static String urlDecode(final String text) {
73 return text != null ? URL_CODEC.decode(text) : null;
74 }
75 }