com.github.dennisit.vplus.data.utils._$ Maven / Gradle / Ivy
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 ([email protected] & www.dreamlu.net).
*
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/lgpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.dennisit.vplus.data.utils;
import com.alibaba.fastjson.JSON;
import lombok.experimental.UtilityClass;
import org.apache.commons.codec.Charsets;
import org.apache.commons.io.IOUtils;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.PatternMatchUtils;
import org.springframework.web.method.HandlerMethod;
import java.io.Closeable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.function.Supplier;
import static com.github.dennisit.vplus.data.utils.DateTimeUtils.DATE_FORMATTER;
/**
* 工具包集合,工具类快捷方式
*
* @author L.cm
*/
@Deprecated
@UtilityClass
public class _$ {
/**
* 断言,必须不能为 null
*
* public Foo(Bar bar) {
* this.bar = $.requireNotNull(bar);
* }
*
*
* @param obj the object reference to check for nullity
* @param the type of the reference
* @return {@code obj} if not {@code null}
* @throws NullPointerException if {@code obj} is {@code null}
*/
public static T requireNotNull(T obj) {
return Objects.requireNonNull(obj);
}
/**
* 断言,必须不能为 null
*
* public Foo(Bar bar, Baz baz) {
* this.bar = $.requireNotNull(bar, "bar must not be null");
* this.baz = $.requireNotNull(baz, "baz must not be null");
* }
*
*
* @param obj the object reference to check for nullity
* @param message detail message to be used in the event that a {@code
* NullPointerException} is thrown
* @param the type of the reference
* @return {@code obj} if not {@code null}
* @throws NullPointerException if {@code obj} is {@code null}
*/
public static T requireNotNull(T obj, String message) {
return Objects.requireNonNull(obj, message);
}
/**
* 断言,必须不能为 null
*
* @param obj the object reference to check for nullity
* @param messageSupplier supplier of the detail message to be
* used in the event that a {@code NullPointerException} is thrown
* @param the type of the reference
* @return {@code obj} if not {@code null}
* @throws NullPointerException if {@code obj} is {@code null}
*/
public static T requireNotNull(T obj, Supplier messageSupplier) {
return Objects.requireNonNull(obj, messageSupplier);
}
/**
* 判断对象为true
*
* @param object 对象
* @return 对象是否为true
*/
public static boolean isTrue(@Nullable Boolean object) {
return ObjectUtils.isTrue(object);
}
/**
* 判断对象为false
*
* @param object 对象
* @return 对象是否为false
*/
public static boolean isFalse(@Nullable Boolean object) {
return ObjectUtils.isFalse(object);
}
/**
* 判断对象是否为null
*
* This method exists to be used as a
* {@link java.util.function.Predicate}, {@code context($::isNull)}
*
*
* @param obj a reference to be checked against {@code null}
* @return {@code true} if the provided reference is {@code null} otherwise
* {@code false}
* @see java.util.function.Predicate
*/
public static boolean isNull(@Nullable Object obj) {
return Objects.isNull(obj);
}
/**
* 判断对象是否 not null
*
* This method exists to be used as a
* {@link java.util.function.Predicate}, {@code context($::notNull)}
*
*
* @param obj a reference to be checked against {@code null}
* @return {@code true} if the provided reference is non-{@code null}
* otherwise {@code false}
* @see java.util.function.Predicate
*/
public static boolean isNotNull(@Nullable Object obj) {
return Objects.nonNull(obj);
}
/**
* 首字母变小写
*
* @param str 字符串
* @return {String}
*/
public static String firstCharToLower(String str) {
return StringUtils.firstCharToLowerCase(str);
}
/**
* 首字母变大写
*
* @param str 字符串
* @return {String}
*/
public static String firstCharToUpper(String str) {
return StringUtils.firstCharToUpperCase(str);
}
/**
* 判断是否为空字符串
*
* $.isBlank(null) = true
* $.isBlank("") = true
* $.isBlank(" ") = true
* $.isBlank("12345") = false
* $.isBlank(" 12345 ") = false
*
*
* @param cs the {@code CharSequence} to check (may be {@code null})
* @return {@code true} if the {@code CharSequence} is not {@code null},
* its length is greater than 0, and it does not contain whitespace only
* @see Character#isWhitespace
*/
public static boolean isBlank(@Nullable final CharSequence cs) {
return StringUtils.isBlank(cs);
}
/**
* 判断不为空字符串
*
* $.isNotBlank(null) = false
* $.isNotBlank("") = false
* $.isNotBlank(" ") = false
* $.isNotBlank("bob") = true
* $.isNotBlank(" bob ") = true
*
*
* @param cs the CharSequence to check, may be null
* @return {@code true} if the CharSequence is
* not empty and not null and not whitespace
* @see Character#isWhitespace
*/
public static boolean isNotBlank(@Nullable final CharSequence cs) {
return StringUtils.isNotBlank(cs);
}
/**
* 判断是否有任意一个 空字符串
*
* @param css CharSequence
* @return boolean
*/
public static boolean isAnyBlank(final CharSequence... css) {
return StringUtils.isAnyBlank(css);
}
/**
* 判断是否全为非空字符串
*
* @param css CharSequence
* @return boolean
*/
public static boolean isNoneBlank(final CharSequence... css) {
return StringUtils.isNoneBlank(css);
}
/**
* 判断对象是数组
*
* @param obj the object to check
* @return 是否数组
*/
public static boolean isArray(@Nullable Object obj) {
return ObjectUtils.isArray(obj);
}
/**
* 判断空对象 object、map、list、set、字符串、数组
*
* @param obj the object to check
* @return 数组是否为空
*/
public static boolean isEmpty(@Nullable Object obj) {
return ObjectUtils.isEmpty(obj);
}
/**
* 对象不为空 object、map、list、set、字符串、数组
*
* @param obj the object to check
* @return 是否不为空
*/
public static boolean isNotEmpty(@Nullable Object obj) {
return !ObjectUtils.isEmpty(obj);
}
/**
* 判断数组为空
*
* @param array the array to check
* @return 数组是否为空
*/
public static boolean isEmpty(@Nullable Object[] array) {
return ObjectUtils.isEmpty(array);
}
/**
* 判断数组不为空
*
* @param array 数组
* @return 数组是否不为空
*/
public static boolean isNotEmpty(@Nullable Object[] array) {
return ObjectUtils.isNotEmpty(array);
}
/**
* 将字符串中特定模式的字符转换成map中对应的值
*
* use: format("my name is ${name}, and i like ${like}!", {"name":"L.cm", "like": "Java"})
*
* @param message 需要转换的字符串
* @param params 转换所需的键值对集合
* @return 转换后的字符串
*/
public static String format(@Nullable String message, @Nullable Map params) {
return StringUtils.format(message, params);
}
/**
* 同 log 格式的 format 规则
*
* use: format("my name is {}, and i like {}!", "L.cm", "Java")
*
* @param message 需要转换的字符串
* @param arguments 需要替换的变量
* @return 转换后的字符串
*/
public static String format(@Nullable String message, @Nullable Object... arguments) {
return StringUtils.format(message, arguments);
}
/**
* 清理字符串,清理出某些不可见字符和一些sql特殊字符
*
* @param txt 文本
* @return {String}
*/
@Nullable
public static String cleanText(@Nullable String txt) {
return StringUtils.cleanText(txt);
}
/**
* 获取标识符,用于参数清理
*
* @param param 参数
* @return 清理后的标识符
*/
@Nullable
public static String cleanIdentifier(@Nullable String param) {
return StringUtils.cleanIdentifier(param);
}
/**
* 安全的 equals
*
* @param o1 first Object to compare
* @param o2 second Object to compare
* @return whether the given objects are equal
* @see Object#equals(Object)
* @see Arrays#equals
*/
public static boolean equalsSafe(@Nullable Object o1, @Nullable Object o2) {
return ObjectUtils.nullSafeEquals(o1, o2);
}
/**
* 对象 eq
*
* @param o1 Object
* @param o2 Object
* @return 是否eq
*/
public static boolean equals(@Nullable Object o1, @Nullable Object o2) {
return Objects.equals(o1, o2);
}
/**
* 比较两个对象是否不相等。
*
* @param o1 对象1
* @param o2 对象2
* @return 是否不eq
*/
public static boolean isNotEqual(Object o1, Object o2) {
return !Objects.equals(o1, o2);
}
/**
* 返回对象的 hashCode
*
* @param obj Object
* @return hashCode
*/
public static int hashCode(@Nullable Object obj) {
return Objects.hashCode(obj);
}
/**
* 如果对象为null,返回默认值
*
* @param object Object
* @param defaultValue 默认值
* @return Object
*/
public static Object defaultIfNull(@Nullable Object object, Object defaultValue) {
return object != null ? object : defaultValue;
}
public static String[] concat(String[] one, String[] other) {
return CollectionUtils.concat(one, other, String.class);
}
public static T[] concat(T[] one, T[] other, Class clazz) {
return CollectionUtils.concat(one, other, clazz);
}
@SafeVarargs
public static Set ofImmutableSet(E... es) {
return CollectionUtils.ofImmutableSet(es);
}
/**
* 不可变 List
*
* @param es 对象
* @param 泛型
* @return 集合
*/
@SafeVarargs
public static List ofImmutableList(E... es) {
return CollectionUtils.ofImmutableList(es);
}
/**
* 判断一个字符串是否是数字
*
* @param cs the CharSequence to check, may be null
* @return {boolean}
*/
public static boolean isNumeric(final CharSequence cs) {
return StringUtils.isNumeric(cs);
}
/**
* 强转string
*
* @param object Object
* @return String
*/
@Nullable
public static String toStr(@Nullable Object object) {
return ObjectUtils.toStr(object, null);
}
/**
* 强转string
*
* @param object Object
* @param defaultValue 默认值
* @return String
*/
@Nullable
public static String toStr(@Nullable Object object, @Nullable String defaultValue) {
return ObjectUtils.toStr(object, defaultValue);
}
/**
* 对象转为 int (支持 String 和 Number),默认: 0
*
* @param object Object
* @return int
*/
public static int toInt(@Nullable Object object) {
return ObjectUtils.toInt(object, 0);
}
/**
* 对象转为 int (支持 String 和 Number)
*
* @param object Object
* @param defaultValue 默认值
* @return int
*/
public static int toInt(@Nullable Object object, int defaultValue) {
return ObjectUtils.toInt(object, defaultValue);
}
/**
* 对象转为 long (支持 String 和 Number),默认: 0L
*
* @param object Object
* @return long
*/
public static long toLong(@Nullable Object object) {
return ObjectUtils.toLong(object, 0L);
}
/**
* 对象转为 long (支持 String 和 Number),默认: 0L
*
* @param object Object
* @param defaultValue 默认值
* @return long
*/
public static long toLong(@Nullable Object object, long defaultValue) {
return ObjectUtils.toLong(object, defaultValue);
}
/**
* 对象转为 Float
*
* @param object Object
* @return 结果
*/
public static float toFloat(@Nullable Object object) {
return ObjectUtils.toFloat(object, 0.0f);
}
/**
* 对象转为 Float
*
* @param object Object
* @param defaultValue float
* @return 结果
*/
public static float toFloat(@Nullable Object object, float defaultValue) {
return ObjectUtils.toFloat(object, defaultValue);
}
/**
* 对象转为 Double
*
* @param object Object
* @return 结果
*/
public static double toDouble(@Nullable Object object) {
return ObjectUtils.toDouble(object, 0.0d);
}
/**
* 对象转为 Double
*
* @param object Object
* @param defaultValue double
* @return 结果
*/
public static double toDouble(@Nullable Object object, double defaultValue) {
return ObjectUtils.toDouble(object, defaultValue);
}
/**
* 对象转为 Byte
*
* @param object Object
* @return 结果
*/
public static byte toByte(@Nullable Object object) {
return ObjectUtils.toByte(object, (byte) 0);
}
/**
* 对象转为 Byte
*
* @param object Object
* @param defaultValue byte
* @return 结果
*/
public static byte toByte(@Nullable Object object, byte defaultValue) {
return ObjectUtils.toByte(object, defaultValue);
}
/**
* 对象转为 Short
*
* @param object Object
* @return 结果
*/
public static short toShort(@Nullable Object object) {
return ObjectUtils.toShort(object, (short) 0);
}
/**
* 对象转为 Short
*
* @param object Object
* @param defaultValue short
* @return 结果
*/
public static short toShort(@Nullable Object object, short defaultValue) {
return ObjectUtils.toShort(object, defaultValue);
}
/**
* 对象转为 Boolean
*
* @param object Object
* @return 结果
*/
@Nullable
public static Boolean toBoolean(@Nullable Object object) {
return ObjectUtils.toBoolean(object, null);
}
/**
* 对象转为 Boolean
*
* @param object Object
* @param defaultValue 默认值
* @return 结果
*/
@Nullable
public static Boolean toBoolean(@Nullable Object object, @Nullable Boolean defaultValue) {
return ObjectUtils.toBoolean(object, defaultValue);
}
/**
* 分割 字符串
*
* @param str 字符串
* @param delimiter 分割符
* @return 字符串数组
*/
public static String[] split(@Nullable String str, @Nullable String delimiter) {
return StringUtils.delimitedListToStringArray(str, delimiter);
}
/**
* 分割 字符串 删除常见 空白符
*
* @param str 字符串
* @param delimiter 分割符
* @return 字符串数组
*/
public static String[] splitTrim(@Nullable String str, @Nullable String delimiter) {
return StringUtils.splitTrim(str, delimiter);
}
/**
* 字符串是否符合指定的 表达式
*
*
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
*
*
* @param pattern 表达式
* @param str 字符串
* @return 是否匹配
*/
public static boolean simpleMatch(@Nullable String pattern, @Nullable String str) {
return PatternMatchUtils.simpleMatch(pattern, str);
}
/**
* 字符串是否符合指定的 表达式
*
*
* pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
*
*
* @param patterns 表达式 数组
* @param str 字符串
* @return 是否匹配
*/
public static boolean simpleMatch(@Nullable String[] patterns, String str) {
return PatternMatchUtils.simpleMatch(patterns, str);
}
/**
* 生成uuid
*
* @return UUID
*/
public static String getUUID() {
return StringUtils.getUUID();
}
/**
* 转义HTML用于安全过滤
*
* @param html html
* @return {String}
*/
public static String escapeHtml(String html) {
return StringUtils.escapeHtml(html);
}
/**
* 随机数生成
*
* @param count 字符长度
* @return 随机数
*/
public static String random(int count) {
return StringUtils.random(count);
}
/**
* 随机数生成
*
* @param count 字符长度
* @param randomType 随机数类别
* @return 随机数
*/
public static String random(int count, RandomType randomType) {
return StringUtils.random(count, randomType);
}
/**
* Calculates the MD5 digest.
*
* @param data Data to digest
* @return MD5 digest as a hex array
*/
public static byte[] md5(final byte[] data) {
return DigestUtils.md5(data);
}
/**
* Calculates the MD5 digest.
*
* @param data Data to digest
* @return MD5 digest as a hex array
*/
public static byte[] md5(final String data) {
return DigestUtils.md5(data);
}
/**
* Calculates the MD5 digest and returns the value as a 32 character hex string.
*
* @param data Data to digest
* @return MD5 digest as a hex string
*/
public static String md5Hex(final String data) {
return DigestUtils.md5Hex(data);
}
/**
* Return a hexadecimal string representation of the MD5 digest of the given bytes.
*
* @param bytes the bytes to calculate the digest over
* @return a hexadecimal digest string
*/
public static String md5Hex(final byte[] bytes) {
return DigestUtils.md5Hex(bytes);
}
/**
* sha1
*
* @param data Data to digest
* @return digest as a hex array
*/
public static byte[] sha1(String data) {
return DigestUtils.sha1(data);
}
/**
* sha1
*
* @param bytes Data to digest
* @return digest as a hex array
*/
public static byte[] sha1(final byte[] bytes) {
return DigestUtils.sha1(bytes);
}
/**
* sha1Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
public static String sha1Hex(String data) {
return DigestUtils.sha1Hex(data);
}
/**
* sha1Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
public static String sha1Hex(final byte[] bytes) {
return DigestUtils.sha1Hex(bytes);
}
/**
* SHA224
*
* @param data Data to digest
* @return digest as a byte array
*/
public static byte[] sha224(String data) {
return DigestUtils.sha224(data);
}
/**
* SHA224
*
* @param bytes Data to digest
* @return digest as a byte array
*/
public static byte[] sha224(final byte[] bytes) {
return DigestUtils.sha224(bytes);
}
/**
* SHA224Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
public static String sha224Hex(String data) {
return DigestUtils.sha224Hex(data.getBytes(Charsets.UTF_8));
}
/**
* SHA224Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
public static String sha224Hex(final byte[] bytes) {
return DigestUtils.sha224Hex(bytes);
}
/**
* sha256Hex
*
* @param data Data to digest
* @return digest as a byte array
*/
public static byte[] sha256(String data) {
return DigestUtils.sha256(data);
}
/**
* sha256Hex
*
* @param bytes Data to digest
* @return digest as a byte array
*/
public static byte[] sha256(final byte[] bytes) {
return DigestUtils.sha256(bytes);
}
/**
* sha256Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
public static String sha256Hex(String data) {
return DigestUtils.sha256Hex(data);
}
/**
* sha256Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
public static String sha256Hex(final byte[] bytes) {
return DigestUtils.sha256Hex(bytes);
}
/**
* sha384
*
* @param data Data to digest
* @return digest as a byte array
*/
public static byte[] sha384(String data) {
return DigestUtils.sha384(data);
}
/**
* sha384
*
* @param bytes Data to digest
* @return digest as a byte array
*/
public static byte[] sha384(final byte[] bytes) {
return DigestUtils.sha384(bytes);
}
/**
* sha384Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
public static String sha384Hex(String data) {
return DigestUtils.sha384Hex(data);
}
/**
* sha384Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
public static String sha384Hex(final byte[] bytes) {
return DigestUtils.sha384Hex(bytes);
}
/**
* sha512Hex
*
* @param data Data to digest
* @return digest as a byte array
*/
public static byte[] sha512(String data) {
return DigestUtils.sha512(data);
}
/**
* sha512Hex
*
* @param bytes Data to digest
* @return digest as a byte array
*/
public static byte[] sha512(final byte[] bytes) {
return DigestUtils.sha512(bytes);
}
/**
* sha512Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
public static String sha512Hex(String data) {
return DigestUtils.sha512Hex(data);
}
/**
* sha512Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
public static String sha512Hex(final byte[] bytes) {
return DigestUtils.sha512Hex(bytes);
}
/**
* hmacMd5
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacMd5(String data, String key) {
return DigestUtils.hmacMd5(data, key);
}
/**
* hmacMd5
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacMd5(final byte[] bytes, String key) {
return DigestUtils.hmacMd5(bytes, key);
}
/**
* hmacMd5 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacMd5Hex(String data, String key) {
return DigestUtils.hmacMd5Hex(data, key);
}
/**
* hmacMd5 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacMd5Hex(final byte[] bytes, String key) {
return DigestUtils.hmacMd5Hex(bytes, key);
}
/**
* hmacSha1
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacSha1(String data, String key) {
return DigestUtils.hmacSha1(data, key);
}
/**
* hmacSha1
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacSha1(final byte[] bytes, String key) {
return DigestUtils.hmacSha1(bytes, key);
}
/**
* hmacSha1 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha1Hex(String data, String key) {
return DigestUtils.hmacSha1Hex(data, key);
}
/**
* hmacSha1 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha1Hex(final byte[] bytes, String key) {
return DigestUtils.hmacSha1Hex(bytes, key);
}
/**
* hmacSha224
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
public static byte[] hmacSha224(String data, String key) {
return DigestUtils.hmacSha224(data, key);
}
/**
* hmacSha224
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
public static byte[] hmacSha224(final byte[] bytes, String key) {
return DigestUtils.hmacSha224(bytes, key);
}
/**
* hmacSha224 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha224Hex(String data, String key) {
return DigestUtils.hmacSha224Hex(data, key);
}
/**
* hmacSha224 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha224Hex(final byte[] bytes, String key) {
return DigestUtils.hmacSha224Hex(bytes, key);
}
/**
* hmacSha256
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
public static byte[] hmacSha256(String data, String key) {
return DigestUtils.hmacSha256(data, key);
}
/**
* hmacSha256
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacSha256(final byte[] bytes, String key) {
return DigestUtils.hmacSha256(bytes, key);
}
/**
* hmacSha256 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
public static String hmacSha256Hex(String data, String key) {
return DigestUtils.hmacSha256Hex(data, key);
}
/**
* hmacSha256 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha256Hex(final byte[] bytes, String key) {
return DigestUtils.hmacSha256Hex(bytes, key);
}
/**
* hmacSha384
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacSha384(String data, String key) {
return DigestUtils.hmacSha384(data, key);
}
/**
* hmacSha384
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacSha384(final byte[] bytes, String key) {
return DigestUtils.hmacSha384(bytes, key);
}
/**
* hmacSha384 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha384Hex(String data, String key) {
return DigestUtils.hmacSha384Hex(data, key);
}
/**
* hmacSha384 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha384Hex(final byte[] bytes, String key) {
return DigestUtils.hmacSha384Hex(bytes, key);
}
/**
* hmacSha512
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacSha512(String data, String key) {
return DigestUtils.hmacSha512(data, key);
}
/**
* hmacSha512
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
public static byte[] hmacSha512(final byte[] bytes, String key) {
return DigestUtils.hmacSha512(bytes, key);
}
/**
* hmacSha512 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha512Hex(String data, String key) {
return DigestUtils.hmacSha512Hex(data, key);
}
/**
* hmacSha512 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
public static String hmacSha512Hex(final byte[] bytes, String key) {
return DigestUtils.hmacSha512Hex(bytes, key);
}
/**
* Base64编码
*
* @param value 字符串
* @return {String}
*/
public static String encodeBase64(String value) {
return Base64Utils.encode(value);
}
/**
* Base64编码
*
* @param value 字符串
* @param charset 字符集
* @return {String}
*/
public static String encodeBase64(String value, Charset charset) {
return Base64Utils.encode(value, charset);
}
/**
* Base64编码为URL安全
*
* @param value 字符串
* @return {String}
*/
public static String encodeBase64UrlSafe(String value) {
return Base64Utils.encodeUrlSafe(value);
}
/**
* Base64编码为URL安全
*
* @param value 字符串
* @param charset 字符集
* @return {String}
*/
public static String encodeBase64UrlSafe(String value, Charset charset) {
return Base64Utils.encodeUrlSafe(value, charset);
}
/**
* Base64解码
*
* @param value 字符串
* @return {String}
*/
public static String decodeBase64(String value) {
return Base64Utils.decode(value);
}
/**
* Base64解码
*
* @param value 字符串
* @param charset 字符集
* @return {String}
*/
public static String decodeBase64(String value, Charset charset) {
return Base64Utils.decode(value, charset);
}
/**
* Base64URL安全解码
*
* @param value 字符串
* @return {String}
*/
public static String decodeBase64UrlSafe(String value) {
return Base64Utils.decodeUrlSafe(value);
}
/**
* Base64URL安全解码
*
* @param value 字符串
* @param charset 字符集
* @return {String}
*/
public static String decodeBase64UrlSafe(String value, Charset charset) {
return Base64Utils.decodeUrlSafe(value, charset);
}
/**
* 关闭 Closeable
*
* @param closeable 自动关闭
*/
public static void closeQuietly(@Nullable Closeable closeable) {
IOUtils.closeQuietly(closeable);
}
/**
* 将对象序列化成json字符串
*
* @param object javaBean
* @return jsonString json字符串
*/
@Nullable
public static String toJson(@Nullable Object object) {
return JSON.toJSONString(object);
}
/**
* 将对象序列化成 json byte 数组
*
* @param object javaBean
* @return jsonString json字符串
*/
@Nullable
public static byte[] toJsonAsBytes(@Nullable Object object) {
return JSON.toJSONBytes(object);
}
/**
* url 编码
*
* @param source the String to be encoded
* @return the encoded String
*/
public static String urlEncode(String source) {
return UrlUtils.encode(source, Charsets.UTF_8);
}
/**
* url 编码
*
* @param source the String to be encoded
* @param charset the character encoding to encode to
* @return the encoded String
*/
public static String urlEncode(String source, Charset charset) {
return UrlUtils.encode(source, charset);
}
/**
* url 解码
*
* @param source the encoded String
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String urlDecode(String source) {
return StringUtils.uriDecode(source, Charsets.UTF_8);
}
/**
* url 解码
*
* @param source the encoded String
* @param charset the character encoding to use
* @return the decoded value
* @throws IllegalArgumentException when the given source contains invalid encoded sequences
* @see StringUtils#uriDecode(String, Charset)
* @see java.net.URLDecoder#decode(String, String)
*/
public static String urlDecode(String source, Charset charset) {
return StringUtils.uriDecode(source, charset);
}
/**
* 日期时间格式化
*
* @param date 时间
* @return 格式化后的时间
*/
public static String formatDateTime(Date date) {
return DateTimeUtils.formatDateTime(date);
}
/**
* 日期格式化
*
* @param date 时间
* @return 格式化后的时间
*/
public static String formatDate(Date date) {
return DateTimeUtils.formatDate(date);
}
/**
* 时间格式化
*
* @param date 时间
* @return 格式化后的时间
*/
public static String formatTime(Date date) {
return DateTimeUtils.formatTime(date);
}
/**
* 日期时间格式化
*
* @param temporal 时间
* @return 格式化后的时间
*/
public static String formatDateTime(TemporalAccessor temporal) {
return formatDateTime(temporal);
}
/**
* 日期时间格式化
*
* @param temporal 时间
* @return 格式化后的时间
*/
public static String formatDate(TemporalAccessor temporal) {
return formatDate(temporal);
}
/**
* 时间格式化
*
* @param temporal 时间
* @return 格式化后的时间
*/
public static String formatTime(TemporalAccessor temporal) {
return formatTime(temporal);
}
/**
* 将字符串转换为时间
*
* @param dateStr 时间字符串
* @param formatter DateTimeFormatter
* @return 时间
*/
public static LocalDateTime parseDateTime(String dateStr, DateTimeFormatter formatter) {
return parseDateTime(dateStr, formatter);
}
/**
* 将字符串转换为时间
*
* @param dateStr 时间字符串
* @return 时间
*/
public static LocalDateTime parseDateTime(String dateStr) {
return parseDateTime(dateStr);
}
/**
* 将字符串转换为时间
*
* @param dateStr 时间字符串
* @param formatter DateTimeFormatter
* @return 时间
*/
public static LocalDate parseDate(String dateStr, DateTimeFormatter formatter) {
return parseDate(dateStr, formatter);
}
/**
* 将字符串转换为日期
*
* @param dateStr 时间字符串
* @return 时间
*/
public static LocalDate parseDate(String dateStr) {
return parseDate(dateStr, DATE_FORMATTER);
}
/**
* 将字符串转换为时间
*
* @param dateStr 时间字符串
* @param formatter DateTimeFormatter
* @return 时间
*/
public static LocalTime parseTime(String dateStr, DateTimeFormatter formatter) {
return parseTime(dateStr, formatter);
}
/**
* 将字符串转换为时间
*
* @param dateStr 时间字符串
* @return 时间
*/
public static LocalTime parseTime(String dateStr) {
return parseTime(dateStr);
}
/**
* 时间比较
*
* @param startInclusive the start instant, inclusive, not null
* @param endExclusive the end instant, exclusive, not null
* @return a {@code Duration}, not null
*/
public static Duration between(Temporal startInclusive, Temporal endExclusive) {
return Duration.between(startInclusive, endExclusive);
}
/**
* 比较2个 时间差
*
* @param startDate 开始时间
* @param endDate 结束时间
* @return 时间间隔
*/
public static Duration between(Date startDate, Date endDate) {
return between(startDate, endDate);
}
/**
* 对象类型转换
*
* @param source the source object
* @param targetType the target type
* @param 泛型标记
* @return the converted value
* @throws IllegalArgumentException if targetType is {@code null},
* or sourceType is {@code null} but source is not {@code null}
*/
@Nullable
public static T convert(@Nullable Object source, Class targetType) {
return convert(source, targetType);
}
/**
* 对象类型转换
*
* @param source the source object
* @param sourceType the source type
* @param targetType the target type
* @param 泛型标记
* @return the converted value
* @throws IllegalArgumentException if targetType is {@code null},
* or sourceType is {@code null} but source is not {@code null}
*/
@Nullable
public static T convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return convert(source, sourceType, targetType);
}
/**
* 对象类型转换
*
* @param source the source object
* @param targetType the target type
* @param 泛型标记
* @return the converted value
* @throws IllegalArgumentException if targetType is {@code null},
* or sourceType is {@code null} but source is not {@code null}
*/
@Nullable
public static T convert(@Nullable Object source, TypeDescriptor targetType) {
return convert(source, targetType);
}
/**
* 获取方法参数信息
*
* @param constructor 构造器
* @param parameterIndex 参数序号
* @return {MethodParameter}
*/
public static MethodParameter getMethodParameter(Constructor> constructor, int parameterIndex) {
return ClassUtils.getMethodParameter(constructor, parameterIndex);
}
/**
* 获取方法参数信息
*
* @param method 方法
* @param parameterIndex 参数序号
* @return {MethodParameter}
*/
public static MethodParameter getMethodParameter(Method method, int parameterIndex) {
return ClassUtils.getMethodParameter(method, parameterIndex);
}
/**
* 获取Annotation注解
*
* @param annotatedElement AnnotatedElement
* @param annotationType 注解类
* @param 泛型标记
* @return {Annotation}
*/
@Nullable
public static A getAnnotation(AnnotatedElement annotatedElement, Class annotationType) {
return AnnotatedElementUtils.findMergedAnnotation(annotatedElement, annotationType);
}
/**
* 获取Annotation,先找方法,没有则再找方法上的类
*
* @param method Method
* @param annotationType 注解类
* @param 泛型标记
* @return {Annotation}
*/
@Nullable
public static A getAnnotation(Method method, Class annotationType) {
return ClassUtils.getAnnotation(method, annotationType);
}
/**
* 获取Annotation,先找HandlerMethod,没有则再找对应的类
*
* @param handlerMethod HandlerMethod
* @param annotationType 注解类
* @param 泛型标记
* @return {Annotation}
*/
@Nullable
public static A getAnnotation(HandlerMethod handlerMethod, Class annotationType) {
return ClassUtils.getAnnotation(handlerMethod, annotationType);
}
/**
* 拷贝对象,支持 Map 和 Bean
*
* @param source 源对象
* @param clazz 类名
* @param 泛型标记
* @return T
*/
@Nullable
public static T copy(@Nullable Object source, Class clazz) {
return BeanUtils.copy(source, clazz);
}
/**
* 拷贝对象,支持 Map 和 Bean
*
* @param source 源对象
* @param targetBean 需要赋值的对象
*/
public static void copy(@Nullable Object source, @Nullable Object targetBean) {
BeanUtils.copy(source, targetBean);
}
/**
* 将对象装成map形式
*
* @param bean 源对象
* @return {Map}
*/
public static Map toMap(@Nullable Object bean) {
return BeanUtils.toMap(bean);
}
}