package cn.huntor.ucm.hbase.utils;
importorg.apache.commons.codec.binary.Base64;
import java.nio.ByteBuffer;
import java.util.UUID;
public class UuidUtils {
publicstatic String uuid() {
UUIDuuid = UUID.randomUUID();
returnuuid.toString();
}
publicstatic String base64Uuid() {
UUIDuuid = UUID.randomUUID();
returnbase64Uuid(uuid);
}
protectedstatic String base64Uuid(UUID uuid) {
ByteBufferbb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
returnBase64.encodeBase64URLSafeString(bb.array());
}
publicstatic String encodeBase64Uuid(String uuidString) {
UUIDuuid = UUID.fromString(uuidString);
returnbase64Uuid(uuid);
}
publicstatic String decodeBase64Uuid(String compressedUuid) {
byte[]byUuid = Base64.decodeBase64(compressedUuid);
ByteBufferbb = ByteBuffer.wrap(byUuid);
UUIDuuid = new UUID(bb.getLong(), bb.getLong());
returnuuid.toString();
}
publicstatic String base58Uuid() {
UUIDuuid = UUID.randomUUID();
returnbase58Uuid(uuid);
}
protectedstatic String base58Uuid(UUID uuid) {
ByteBufferbb = ByteBuffer.wrap(new byte[16]);
bb.putLong(uuid.getMostSignificantBits());
bb.putLong(uuid.getLeastSignificantBits());
returnBase58.encode(bb.array());
}
publicstatic String encodeBase58Uuid(String uuidString) {
UUIDuuid = UUID.fromString(uuidString);
returnbase58Uuid(uuid);
}
publicstatic String decodeBase58Uuid(String base58uuid) {
byte[]byUuid = Base58.decode(base58uuid);
ByteBufferbb = ByteBuffer.wrap(byUuid);
UUIDuuid = new UUID(bb.getLong(), bb.getLong());
returnuuid.toString();
}
publicstatic void main(String[] args) {
System.out.println(UuidUtils.base58Uuid());
System.out.println(UuidUtils.base58Uuid());
System.out.println(UuidUtils.base58Uuid());
}
}