UUID 压缩为22位
2015-09-15 12:10
483 查看
public class Generator { private static char[] BASE64 = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789".toCharArray(); public static String generateUUID() { UUID uuid = UUID.randomUUID(); char[] chs = new char[22]; long most = uuid.getMostSignificantBits(); long least = uuid.getLeastSignificantBits(); int high = (int)((most >> 13) ^ (least >> 31)) & 0x3c; int k = chs.length - 1; for(int i = 0; i < 10; i++, least >>>= 6) { chs[k--] = BASE64[(int)(least & 0x3f)]; } chs[k--] = BASE64[(int)((least & 0x3f) | (most & 0x30))]; most >>>= 2; for(int i = 0; i < 10; i++, most >>>= 6) { chs[k--] = BASE64[(int)(most & 0x3f)]; } chs[k--] = BASE64[(int)(high | most)]; return new String(chs); } }
相关文章推荐
- 【异常处理】Incorrect string value: '\xF0\x90\x8D\x83...' for column... Emoji表情字符过滤的Java实现
- iOS UI基础知识
- 1007. Maximum Subsequence Sum (25)
- treeviewhelper用法,找child的UIElement
- UIpanel之修改 clipping size 数值
- Xamarin.IOS UIAlertController 自定义字体
- UIButton
- [转载] ZooKeeper实现分布式队列Queue
- easy ui datagrid 增,删,改,查等基本操作
- ueditor编辑器 提交表单
- ue标签不见了,如何解决?
- iOS真机UI调试利器——Reveal
- 关于easyUI在子页面增加显示tabs的一个问题
- 关于easyui的窗口和tab页面不执行js说明
- VirtualBox: Effective UID is not root (euid=1000 egid=100 uid=1000 gid=100)
- Android Studio - 详解build.gradle
- (素材源码)猫猫学IOS(三十五)UI之Quartz2D仿真支付宝手势解锁_代理获得密码。
- ueditor上传图片中文文件名失败的解决办法
- UIImageView和UIButton的区别
- iOS-禁用UINavigationController中的轻扫回退的手势