UUIDUtils.java 980 B

1234567891011121314151617181920212223242526272829
  1. package com.yaozhitech.spring5.common.util;
  2. import java.util.UUID;
  3. /**
  4. * Created by ace on 2017/9/27.
  5. */
  6. public class UUIDUtils {
  7. public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f",
  8. "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
  9. "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
  10. "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
  11. "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
  12. "W", "X", "Y", "Z" };
  13. public static String generateShortUuid() {
  14. StringBuffer shortBuffer = new StringBuffer();
  15. String uuid = UUID.randomUUID().toString().replace("-", "");
  16. for (int i = 0; i < 8; i++) {
  17. String str = uuid.substring(i * 4, i * 4 + 4);
  18. int x = Integer.parseInt(str, 16);
  19. shortBuffer.append(chars[x % 0x3E]);
  20. }
  21. return shortBuffer.toString();
  22. }
  23. }