生成UUID

1 篇文章 0 订阅

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());

                  

         }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值