fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.nio.ByteBuffer;
  8. import java.nio.LongBuffer;
  9. import java.util.UUID;
  10.  
  11. import java.util.Base64;
  12.  
  13.  
  14. /* Name of the class has to be "Main" only if the class is public. */
  15. class Ideone
  16. {
  17.  
  18. private static byte[] getByteArray(UUID uuid) {
  19. byte[] byteArray = new byte[(Long.SIZE / Byte.SIZE) * 2];
  20. ByteBuffer buffer = ByteBuffer.wrap(byteArray);
  21. LongBuffer longBuffer = buffer.asLongBuffer();
  22. longBuffer.put(new long[]{uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()});
  23. return byteArray;
  24. }
  25.  
  26. /* public static String generateKeyUsingUniqueId(UUID uuid) {
  27.   byte[] byteArray = getByteArray(uuid);
  28.   byte[] encodedArray = BASE64.encode(byteArray);
  29.   String key = new String(encodedArray);
  30.   return key;
  31.   } */
  32.  
  33. public static String getId(UUID uuid) {
  34. byte[] uuidBytes = getByteArray(uuid);
  35. return Base64.getEncoder().encodeToString(uuidBytes);
  36. }
  37.  
  38.  
  39.  
  40. public static void main (String[] args) throws java.lang.Exception
  41. {
  42. UUID u = UUID.fromString("070b9a90-3c33-4111-9f59-fbf44a283be6");
  43. System.out.println(getId(u));
  44. }
  45. }
Success #stdin #stdout 0.08s 47468KB
stdin
Standard input is empty
stdout
BwuakDwzQRGfWfv0Sig75g==