Utils for encoding.
| 26 | |
| 27 | /** Utils for encoding. */ |
| 28 | public class EncodingUtils { |
| 29 | |
| 30 | private static final Base64.Encoder BASE64_ENCODER = Base64.getUrlEncoder().withoutPadding(); |
| 31 | |
| 32 | private static final Base64.Decoder BASE64_DECODER = Base64.getUrlDecoder(); |
| 33 | |
| 34 | public static <T> String encodeObjectToString(T t) { |
| 35 | try { |
| 36 | byte[] bytes = InstantiationUtil.serializeObject(t); |
| 37 | return new String(BASE64_ENCODER.encode(bytes), UTF_8); |
| 38 | } catch (Exception e) { |
| 39 | throw new RuntimeException(e); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public static <T> T decodeStringToObject(String encodedStr) { |
| 44 | final byte[] bytes = BASE64_DECODER.decode(encodedStr.getBytes(UTF_8)); |
| 45 | try { |
| 46 | return InstantiationUtil.deserializeObject(bytes, EncodingUtils.class.getClassLoader()); |
| 47 | } catch (Exception e) { |
| 48 | throw new RuntimeException(e); |
| 49 | } |
| 50 | } |
| 51 | } |
nothing calls this directly
no outgoing calls
no test coverage detected