1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18 import static java.net.URLDecoder.decode;
19 import static java.net.URLEncoder.encode;
20 import static org.kuali.common.util.base.Exceptions.illegalState;
21 import static org.kuali.common.util.base.Precondition.checkNotNull;
22
23 import java.io.UnsupportedEncodingException;
24
25 public final class Encodings {
26
27 private Encodings() {
28 }
29
30 public static final String UTF8 = "UTF-8";
31 public static final String ASCII = "US-ASCII";
32
33 public static final String encodeUTF8(String text) {
34 try {
35 return encode(checkNotNull(text, "text"), UTF8);
36 } catch (UnsupportedEncodingException e) {
37 throw illegalState(e);
38 }
39 }
40
41 public static final String decodeUTF8(String text) {
42 try {
43 return decode(checkNotNull(text, "text"), UTF8);
44 } catch (UnsupportedEncodingException e) {
45 throw illegalState(e);
46 }
47 }
48
49 }