• StringUtil


    import java.util.Random;
    import java.util.UUID;

    import org.apache.commons.codec.binary.Base64;
    import org.apache.commons.lang3.Validate;

    public class StringUtil {

    public final static String EMPTY = "";

    public final static boolean isEmpty(String s) {
    return s == null || s.trim().equals(EMPTY);
    }

    public final static String vague(String s, int begin, int end) {
    if (isEmpty(s)) {
    return s;
    }

    if (s.length() <= begin + end) {
    return s;
    }
    char[] chars = s.toCharArray();
    for (int i = begin; i < chars.length - end; i++) {
    chars[i] = '*';
    }

    return new String(chars);
    }

    public final static String uuid() {
    String uuid = UUID.randomUUID().toString().replace("-", "");
    return uuid;
    }

    // public final static String myuid() {
    // UUID uuid = Generators.timeBasedGenerator().generate();
    // long mostSigBits = uuid.getMostSignificantBits();
    // long leastSigBits = uuid.getLeastSignificantBits();
    // return (
    // digits(mostSigBits, 4) +
    // digits(mostSigBits >> 16, 4) +
    // digits(mostSigBits >> 32, 8) +
    // digits(leastSigBits >> 48, 4) +
    // digits(leastSigBits, 12)
    // );
    // }

    public final static boolean in(String param, String... factor) {
    if (null != factor && factor.length != 0) {
    for (String f : factor) {
    if (param.equals(f)) {
    return true;
    }
    }
    }
    return false;
    }

    private static final Random random = new Random();

    public static String random(int bytesLength) {
    Validate.isTrue(bytesLength > 0, "numBytes argument must be a positive integer (1 or larger)", bytesLength);
    byte[] bytes = new byte[bytesLength];
    random.nextBytes(bytes);
    String s = encodeBase64(bytes);
    return s;
    }

    public static String encodeBase64(byte[] bytes) {
    return Base64.encodeBase64String(bytes);
    }

    public static byte[] decodeBase64(String cipher) {
    return Base64.decodeBase64(cipher);
    }

    }

  • 相关阅读:
    Docker基本命令及工作原理
    Docker安装
    linux命令
    MTPuTTy使用
    SpringBoot--swagger搭建、配置及使用
    idea使用技巧
    Idea插件
    IDEA开发工具使用 git 创建项目、拉取分支、合并分支
    git命令
    javbus爬虫-老司机你值得拥有
  • 原文地址:https://www.cnblogs.com/lize1215/p/8548473.html
Copyright © 2020-2023  润新知