Guest User

Untitled

a guest
Jul 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. Replace (+, /) with (-, _)
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.util.Base64;
  5. import java.util.UUID;
  6.  
  7. class UUID22 {
  8. public static void main(String[] args) {
  9.  
  10. UUID uuid= UUID.randomUUID();
  11. byte[] src = ByteBuffer.wrap(new byte[16])
  12. .putLong(uuid.getMostSignificantBits())
  13. .putLong(uuid.getLeastSignificantBits())
  14. .array();
  15. String encoded = Base64.getEncoder().encodeToString(src).substring(0,22).replaceAll("\\+","-").replaceAll("/","_");
  16. System.out.println(encoded);
  17. }
  18. }
Add Comment
Please, Sign In to add comment