I want to take type UUID
and output it in a Base64
encoded format, however given the input methods on Base64
and outputs on UUID
how to accomplish this doesn't seem obvious.
update though not an explicit requirement for my use case, it would be nice to know if the method used uses the raw UUID (the 128 bits that a UUID actually is) of the UUID, as the standard hex encoding does.
First, convert your UUID to a byte buffer for consumption by a Base64
encoder:
ByteBuffer uuidBytes = ByteBuffer.wrap(new byte[16]);
uuidBytes.putLong(uuid.getMostSignificantBits());
uuidBytes.putLong(uuid.getLeastSignificantBits());
Then encode that using the encoder:
byte[] encoded = encoder.encode(uuidBytes);
Alternatively, you can get a Base64-encoded string like this:
String encoded = encoder.encodeToString(uuidBytes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With