MCPcopy Create free account
hub / github.com/apache/paimon-trino / EncodingUtils

Class EncodingUtils

src/main/java/org/apache/paimon/trino/EncodingUtils.java:28–51  ·  view source on GitHub ↗

Utils for encoding.

Source from the content-addressed store, hash-verified

26
27/** Utils for encoding. */
28public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected