CommonFunctionUtils中的内置函数

函数 参数说明 函数说明
public static boolean isArray(Object object) object:需要判断的对象 判断object是否是数组
public static boolean isPrimitiveArray(Object object) object:需要判断的对象 判断object是否是基础数据类型的数组
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2) byte_1:需要合并的第一个字节数组
byte_2:需要合并的第二个字节数组
合并两个字节数组,合并之后byte_1在前,byte_2在后
public static int bytesToInt(byte[] bytes) bytes:需要转成int的字节数组,长度需要小于或等于4 将字节数组转成int,字节数组的高位是整型的低字节位
public static int byteToShort(byte[] bytes) bytes:需要转成short的字节数组,长度为2 将字节数组转成short,字节数组的高位是short的低字节位
public static byte[] int2bytes(int i, int n) i:需要转换的int
n:字节数组的长度
将整形转换成长度为n的字节数组
public static byte[] intToBytes(int i) i:需要转换的int 将整形转换成长度为4的字节数组
public static String parseByte2HexStr(byte[] bytes) bytes:需要转换的字节数组 将字节数组转换成十六进制字符串
public static String caculateMd5(String filepath) filepath:需要MD5的文件的路径 计算文件的MD5值
public static byte[] parseHexStr2Byte(String hexStr) hexStr:需要转换的十六进制的字符串 将十六进制字符串转换成字节数组
public static byte[] shortToByte(int number) number:需要转换的number 将short转换成字节数组
public static byte[] decryptBASE64(String base64str) base64str:需要解密的base64字符串 将base64字符串解密成字节数组
public static String decryptStr(String base64str, Key key) base64str:需要解密的base64字符串
key:解密需要的密钥
将base64字符串通过密钥解密成明文字符串
public static String encryptBASE64(byte[] bytes) bytes:需要加密的字节数组 将字节数组加密成base64字符串
public static String encryptcommonBASE64(byte[] bytes) bytes:需要加密的字节数组 将字节数组加密成base64字符串
public static byte[] decodeBase64(String base64str) base64str:需要解密的base64字符串 将base64字符串解密成字节数组
public static byte[] encryptHMAC(byte[] bytes, String key) bytes:需要加密的字节数组
key:生成密钥的key
将字节数组通过HMAC加密
public static byte[] encryptMD5(byte[] bytes) bytes:需要加密的字节数组 将字节数组通过MD5加密
public static String encryptMD5(String str) str:需要加密的字符串 将明文字符串通过MD5加密
public static byte[] encryptSHA(byte[] bytes) bytes:需要加密的字节数组 将字节数组通过SHA加密
public static byte[] encryptSHA1(String str) str:需要加密的字符串 将明文字符串通过SHA-1加密
public static String encryptStr(String str, Key key) str:需要加密的字符串
key:生成密钥的key
将明文字符串通过DES加密
public static String initMacKey() 初始化HMAC密钥
public static Key setKey(String strKey) strKey:生成key的参数 生成key
public static void zipFile(String sourceDirectory, String zipFile,boolean pathStyle) sourceDirectory:需要压缩的文件夹
zipFile:压缩完成后的zip文件
pathStyle:是否要目录
将文件夹中文件压缩成zip文件
public static void zipFile(String[] paths, String zipFile) paths:需要被压缩的文件目录集合
zipFile:压缩完成后的zip文件
将文件夹中文件压缩成zip文件
public static void zipFile(String sourceDirectory, String zipFile, boolean pathStyle, boolean iscontaincurrent) sourceDirectory:需要压缩的文件夹
zipFile:压缩完成后的zip文件
pathStyle:是否要目录
iscontaincurrent:是否创建待压缩目录
将文件夹中文件压缩成zip文件
public static void tarFile(String sourceDirectory, String tarFile,boolean pathStyle) sourceDirectory:需要压缩的文件夹
tarFile:压缩完成后的tar文件
pathStyle:是否要目录
将文件夹中文件压缩成tar文件
public static void tarFile(String sourceDirectory, String tarFile, boolean pathStyle, boolean iscontainCurrent) sourceDirectory:需要压缩的文件夹
tarFile:压缩完成后的tar文件
pathStyle:是否要目录
iscontainCurrent:是否创建待压缩目录
将文件夹中文件压缩成tar文件
public static void unzipFile(String zipFileName, String targetDirectory) zipFileName:需要解压的zip文件
targetDirectory:被解压到目标文件夹
将zip文件解压到目标文件夹
public static void untarFile(String tarFileName, String targetDirectory) tarFileName:需要解压的tar文件
targetDirectory:被解压到目标文件夹
将tar文件解压到目标文件夹
public static void untarFile(String tarFileName, String targetDirectory,String case_convert) tarFileName:需要解压的tar文件
targetDirectory:被解压到目标文件夹
case_convert:文件目录大小写 ,upper(大写) lower(小写)
将tar文件解压到目标文件夹
public static Date parseDate(Date date, String parsePattern) date:时间
parsePattern:时间格式
时间格式化
public static int compareDate(Date firstDate, Date secondDate) firstDate:需要比较的第一个时间
secondDate:需要比较的第二个时间
比较两个时间。如果相等,返回值为0 ;如果前一个时间比较早,返回值小于0; 如果前一个时间比较晚,返回值大于0
public static final Date dateAdd(Date paramDate, int paramInt1, int paramInt2) paramDate:原始时间
paramInt1:增加的字段类型(0-毫秒,1-秒,2-分钟,3-小时,4-天,5-月,6-年)
paramInt2:增加的值
增加时间
public static int getDayOfWeek(String year, String month, String day) year:年的字符串,如1990
month:月份的字符串,如1
day:代表天的字符串,如1
获取当期日期是星期几的数字。1表示星期天、2表示星期一、3表示星期二、4表示星期三、5表示星期四、6表示星期五、7表示星期六
public static boolean isDateValid(String cron) cron:时间表达式的字符串 判断时间表达式是否正确
public static String formatNow() 格式化当前时间(yyyy-MM-dd HH:mm:ss,SSS)
public static String formatNow(String pattern) pattern:时间格式字符串,如yyyy-MM-dd HH:mm:ss 格式化当前时间为指定格式
public static String format(Date date) date:需要被格式化的时间 将指定时间格式化(yyyy-MM-dd HH:mm:ss,SSS)
public static String format(Date date, String pattern) date:需要被格式化的时间
pattern:时间格式字符串,如yyyy-MM-dd HH:mm:ss
格式化date为指定格式
public static String format(XMLGregorianCalendar xgc, String pattern) xgc:XML时间
pattern:时间格式字符串,如yyyy-MM-dd HH:mm:ss
格式化XML时间为指定格式
public static XMLGregorianCalendar parseXMLGregorianCalendar(String time, String pattern) time:时间字符串
pattern:时间格式字符串,如yyyy-MM-dd HH:mm:ss
指定格式的日期转化为XML时间
public static XMLGregorianCalendar parseXMLGregorianCalendar(Date date) date:需要转换的时间 Date转化为XML时间
public static Date formatAndParseDate(Date date, String pattern) date:需要转换的时间
pattern:需要被转成的时间格式字符串
将时间转成指定的时间格式
public static XMLGregorianCalendar parseXMLGregorianCalendar(String time) time:需要转换的时间字符串 将时间字符串转换为XML时间
public static Date parseDate(XMLGregorianCalendar xgc) xgc:需要转换的XML时间 将XML时间转换成Date
public static String parseAndFormatDate(String date, String parsePattern, String formatPattern) date:需要转换的时间
parsePattern:date的时间格式字符串
formatPattern:被转成的时间的格式字符串
将时间字符串转换成指定格式的时间字符串
public static final Timestamp time2(String pattern, String time) pattern:时间格式字符串,如yyyy-MM-dd HH:mm:ss
time:需要转换的时间字符串
将时间字符串转换成时间戳
public static boolean copyFile(String resFilePath, String distFolder) resFilePath:源文件
distFolder:目标文件夹
将源文件复制到目标文件夹中
public static boolean deleteFile(String targetPath) targetPath:需要被删除的文件 删除指定文件
public static File[] fileLastModifiedSort(String directory) directory:指定文件夹 按照文件最后的修改时间排序
public static List getFileNamesByRegex(String path, String regex) path:指定的文件夹
regex:文件名的正则表达式
获取指定目录下符合正则表达式的文件
public static String html2Xml(String htmlStr) htmlStr:html字符串 html字符串转换成xml字符串
public static final String str8(Number paramNumber) paramNumber:待转换的数字 将数字转换为字符串,不够8位前面补0
public static final String str(Number paramNumber, String paramString) paramNumber:待转换的数字
paramString:数字格式
将数字转换成指定格式的字符串
public static final String cat(String paramString1, String paramString2) paramString1:字符串1
paramString2:字符串2
先去掉两个字符串头尾的空格,再合并成一个字符串
public static final String cat1(String paramString1, String paramString2) paramString1:字符串1
paramString2:字符串2
先去掉两个字符串头尾的空格,再合并成一个字符串,两个字符串之间增加一个换行符\r
public static final String trim(String paramString) paramString:字符串 去掉字符串头尾空格
public static final String trim4(String paramString1, String paramString2, String paramString3) paramString1:待处理的字符串
paramString2:源码字符集
paramString3:转码字符集
字符串paramString1转码后去除头尾空格
public static final int length(String paramString) paramString:字符串 获取字符串的长度
public static final int length(String paramString, String encode) paramString:字符串
encode:字符集
获取字符串的长度
public static final int size1(Object obj) obj可以为字节数组,字符串,Map,List 获取obj的长度
public static final int size2(Object obj, String encode) obj可以为字节数组,字符串,Map,List
encode:当obj为字符串时,指定的字符集
获取obj的长度
public static final String substr(String paramString, int from, int to) paramString:待截取的字符串
from:截取的起始位置
to:截取的截止位置
说明:如果from大于字符串的长度,则返回null;如果to大于字符串长度,则截取到字符串末尾
字符串截取
public static final String substr1(String paramString, int from) paramString:待截取的字符串
from:截取的起始位置,截取到字符串的最后
字符串截取
public static final Number number1(String paramString) paramString:待转换的字符串 字符串转换为数字,数字格式为 #,##0.##
public static final Number number2(String paramString1, String paramString2) paramString1:待转换的字符串
paramString2:指定的数字格式
字符串转换为指定格式的数字
public static Date parseDate(String date, String parsePattern) date:时间字符串
parsePattern:指定的时间格式
字符串转化为Date类型
public static double accurateDivide(double dividend, double divisor, int digits) dividend:被除数
divisor:除数
digits:小数点位数
除法运算,保留指定小数点(四舍五入)
public static String accurateDivide(String dividend, String divisor, int digits) dividend:被除数字符串
divisor:除数字符串
digits:小数点位数
除法运算,保留指定小数点(四舍五入)
public static String decimalFormat(String decimal) decimal:需要转换的数字字符串 将数字字符串格式化,保留两位小数点(四舍五入)
public static String decimalFormat(Object decimal, int num) decimal:需要转换的数字字符串
num:保留的小数位数
将数字字符串格式化,保留指定位数小数点(四舍五入)
public static String formatAmt(String amt, int dot) amt:需要处理的数字字符串
dot:小数点位数
先将amt小数点处理成指定位数,不够补零,多余指定位数的四舍五入。然后去掉小数点
public static int getMax(int[] values) values:int的数组 获取int数组中最大的值
public static double round(double v, int scale) v:需要处理的数字
scale:保留的小数点位数
将double类似数字四舍五入保留指定小数点位数
public static String getPropertyValue(String propertyFile, String propertyName) propertyFile:配置文件
propertyName:属性名
获取指定配置文件中指定属性值(支持多种格式的配置文件)
public static Properties getProperties(String propertyFile, String encoding) propertyFile:配置文件
encoding:字符集
获取指定配置文件的配置(支持多种格式的配置文件)
public static Properties getProperties(String propertyFile) propertyFile:配置文件 获取指定配置文件的配置(支持多种格式的配置文件),默认字符集GBK
public synchronized static boolean setPropertyValue(String propertyFile, String propertyName, String propertyValue) propertyFile:配置文件
propertyName:属性名
propertyValue:属性值
设置配置文件中的属性值
public static String bytesToString(byte[] bytes, String encoding) bytes:字节数组 字节数组转字符串
public static String fillWithChar(Object obj, String chars,String direct,int totalLen) obj:需要被填充的原对象
chars:填充的字符串
direct:填充的方向(left-填充到左边,right-填充到右边)
totalLen:填充后总长度
数据填充到指定长度(1.如果obj是带有小数点,则先格式化,再去掉小数点,最后填充到指定长度2.如果数据长度大于指定长度,则不进行操作,数据长度为原来长度)
public static String formatDouble(double db) db:需要转换的double类型数据 将double类型数据转换为字符串
public static String formatDouble(double db, String pattern) db:需要转换的double类型数据
pattern:转换的格式
将double类型数据转换为指定格式的字符串
public static byte[] getBytes(String srcStr, String encoding) srcStr:需要转换的字符串
encoding:字符集
将字符串转换为字节数组
public static boolean isEmpty(String content) content:需要判断的字符串 判断字符串是否为空
public static List match(String pattern, String target) pattern:正则表达式
target:原字符串
根据正则表达式匹配出相应内容
public static String[] split(String regex, String s) regex:正则表达式
s:原字符串
根据正则切割字符串
public static String toHexString(String s) s:需要转换的字符串 将字符串转换为十六进制字符串
public static int getArrayLen(Object obj) obj:数组或者集合 获取数组或者集合的长度
public static void touch(Object obj) obj:文件路径的字符串或者File对象 创建或者更新文件
public static void listFiles(String root, List listFiles, String flg) root:文件夹路径
listFiles:接收结果数据
flg:flg="path" 获取文件路径;flg="name" 获取文件名;flg="file" 获取文件对象
获取指定文件夹下所有的(包括子目录)的文件路径或者文件名或者文件对象
public static void sleep(long time) time:休眠的毫秒数 线程休眠一段时间
public static void close() 将线程状态设置为中断
public static Date now() 获取当前时间
public static Date now(String pattern) pattern:时间格式字符串 按指定时间格式获取当前时间
public static String getRootPath() 获取项目根路径
public static String toJson(Object obj) obj:需要处理的object对象 将object转换为json字符串
public static Object fromJson(String json, String jsontype) json:json字符串
jsontype:可以传list或者map或者类的全路径
将json串转化为list或者map或者其他实体对象
public static Class getClass(String classname) classname:类的全路径名 获取类的class
public static String bytes2Str(byte[] bytes, String encoding) bytes:字节数组
encoding:字符集
字节数组转成字符串
public static String bytes2Str(byte[] bytes) bytes:字节数组 字节数组转成字符串,默认字符集UTF-8
public static String catLine(Object... obj) obj:需要拼接的内容 将参数拼接成多行
public static String getenv(String name) name:系统属性名 获取指定系统属性的值
public static boolean isWeekend(String year, String month, String day) year:年
month:月
day:日
判断某一天是否为周六或者周天
public static String formatMinutesLater(String pattern, int min) pattern:指定时间格式
min:分钟数
按指定格式格式化几分钟后的时间
public static String leftStr(String source, String encode, int maxByteLen, int flag) source:原始字符串
encode:字符集
maxByteLen:截取的字节数
flag:表示处理汉字的方式。1表示遇到半个汉字时补全,-1表示遇到半个汉字时舍弃
字符串按照字节数截取
public static String getFilePath(String filepth) filepth:文件路径 判断给定路径下的文件是否存在,存在返回文件路径,否则返回空
public static URL getCommonURL(String relativePath) relativePath:相对路径 获取相对路径的URL
public static String formatHexString(byte[] bytes) bytes:字节数组 字节数组转换为字符串
public static String localIp() 获取本地ip
public static String ASCIItoString(String str) str:ASCII字符串 ASCII转字符串
public static String toASCII(String str) str:源字符串 字符串转ASCII
public static boolean isDigit(String s) s:字符串 判断字符串是否为数字
public static Double multiply(String a, String b) a:第一个数字字符串
b:第二个数字字符串
乘法运算
public static Double divide(String a, String b) a:第一个数字字符串
b:第二个数字字符串
除法运算(a÷b)
public static Double add(String a, String b) a:第一个数字字符串
b:第二个数字字符串
加法运算
public static Double subtract(String a, String b) a:第一个数字字符串
b:第二个数字字符串
减法运算(a-b)
public static Double multiply(Double a, Double b) a:第一个数字
b:第二个数字
乘法运算
public static Double divide(Double a, Double b) a:第一个数字
b:第二个数字
除法运算(a÷b)
public static Double add(Double a, Double b) a:第一个数字
b:第二个数字
加法运算
public static Double subtract(Double a, Double b) a:第一个数字
b:第二个数字
减法运算(a-b)
public static File file(String path) path:文件路径 根据文件路径创建文件对象
public static String decodeURL(String path) path:url地址 解码url地址
public static boolean isValidDate(String str, String pattern) str:源字符串
pattern:时间格式
判断字符串是否是指定格式的时间串
public static void createBlockingQueue(String key, int capacity, boolean fair) key:队列的key
capacity:队列的容量
fair:阻塞队列中创建锁的参数
创建阻塞队列
public static Object takeFromBlockingQueue(String key) key:队列的key 从阻塞队列中拿数据
public static boolean put2BlockingQueue(String key, Object obj) key:队列的key
obj:将要放到队列里的数据
向阻塞队列中添加数据
public static void writeFile(Object content, String path, boolean append, String encode) content:待写入文件的内容,可以是字节数组或者字符串
path:文件路径
append:是否追加写到文件末尾
encode:文件内容编码
将内容写到文件中

results matching ""

    No results matching ""