annotate src/goodjava/util/GoodUtils.java @ 1719:2f3a8f16f583

add regex.split
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 25 Jul 2022 14:31:48 -0600
parents 1cc6c7fa803d
children 2f4c99c02436
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1583
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.util;
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.io.UnsupportedEncodingException;
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.util.Base64;
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 public final class GoodUtils {
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 public static byte[] getBytes(String s,String charsetName) {
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 try {
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 return s.getBytes(charsetName);
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 } catch(UnsupportedEncodingException e) {
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 throw new RuntimeException(e);
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 }
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 }
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 public static String base64Encode(String s) {
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 return Base64.getEncoder().encodeToString(getBytes(s,"UTF-8"));
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 }
1cc6c7fa803d mail work
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 }