提交 34797957 编写于 作者: C cmj

see 09/13 log

上级 aba4264f
......@@ -37,12 +37,12 @@ public class ConvertUtils {
* @return 16进制大写字符串
*/
public static String bytes2HexString(byte[] bytes) {
char[] res = new char[bytes.length << 1];
char[] ret = new char[bytes.length << 1];
for (int i = 0, j = 0; i < bytes.length; i++) {
res[j++] = hexDigits[bytes[i] >>> 4 & 0x0f];
res[j++] = hexDigits[bytes[i] & 0x0f];
ret[j++] = hexDigits[bytes[i] >>> 4 & 0x0f];
ret[j++] = hexDigits[bytes[i] & 0x0f];
}
return new String(res);
return new String(ret);
}
/**
......@@ -59,11 +59,11 @@ public class ConvertUtils {
throw new IllegalArgumentException("长度不是偶数");
}
char[] hexBytes = hexString.toUpperCase().toCharArray();
byte[] res = new byte[len >>> 1];
byte[] ret = new byte[len >>> 1];
for (int i = 0; i < len; i += 2) {
res[i >> 1] = (byte) (hex2Dec(hexBytes[i]) << 4 | hex2Dec(hexBytes[i + 1]));
ret[i >> 1] = (byte) (hex2Dec(hexBytes[i]) << 4 | hex2Dec(hexBytes[i + 1]));
}
return res;
return ret;
}
/**
......@@ -308,12 +308,12 @@ public class ConvertUtils {
/**
* bitmap转drawable
*
* @param resources resources对象
* @param bitmap bitmap对象
* @param res resources对象
* @param bitmap bitmap对象
* @return drawable对象
*/
public static Drawable bitmap2Drawable(Resources resources, Bitmap bitmap) {
return bitmap == null ? null : new BitmapDrawable(resources, bitmap);
public static Drawable bitmap2Drawable(Resources res, Bitmap bitmap) {
return bitmap == null ? null : new BitmapDrawable(res, bitmap);
}
/**
......@@ -330,12 +330,12 @@ public class ConvertUtils {
/**
* byteArr转drawable
*
* @param resources resources对象
* @param bytes 字节数组
* @param res resources对象
* @param bytes 字节数组
* @return drawable对象
*/
public static Drawable bytes2Drawable(Resources resources, byte[] bytes) {
return bitmap2Drawable(resources, bytes2Bitmap(bytes));
public static Drawable bytes2Drawable(Resources res, byte[] bytes) {
return bitmap2Drawable(res, bytes2Bitmap(bytes));
}
/**
......
......@@ -319,10 +319,10 @@ public class EncryptUtils {
* @return 文件的MD5校验码
*/
public static byte[] encryptMD5File(File file) {
FileInputStream in = null;
FileInputStream fis = null;
try {
in = new FileInputStream(file);
FileChannel channel = in.getChannel();
fis = new FileInputStream(file);
FileChannel channel = fis.getChannel();
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(buffer);
......@@ -330,12 +330,7 @@ public class EncryptUtils {
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {
}
}
FileUtils.closeIO(fis);
}
return null;
}
......
package com.blankj.utilcode.utils;
import java.util.regex.Pattern;
import static com.blankj.utilcode.utils.ConstUtils.*;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/8/2
* desc : 正则相关工具类
* </pre>
*/
public class RegularUtils {
private RegularUtils() {
throw new UnsupportedOperationException("u can't fuck me...");
}
/**
* If u want more please visit http://toutiao.com/i6231678548520731137/
*/
/**
* 验证手机号(简单)
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isMobileSimple(String string) {
return isMatch(REGEX_MOBILE_SIMPLE, string);
}
/**
* 验证手机号(精确)
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isMobileExact(String string) {
return isMatch(REGEX_MOBILE_EXACT, string);
}
/**
* 验证电话号码
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isTel(String string) {
return isMatch(REGEX_TEL, string);
}
/**
* 验证身份证号码15位
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isIDCard15(String string) {
return isMatch(REGEX_IDCARD15, string);
}
/**
* 验证身份证号码18位
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isIDCard18(String string) {
return isMatch(REGEX_IDCARD18, string);
}
/**
* 验证邮箱
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isEmail(String string) {
return isMatch(REGEX_EMAIL, string);
}
/**
* 验证URL
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isURL(String string) {
return isMatch(REGEX_URL, string);
}
/**
* 验证汉字
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isChz(String string) {
return isMatch(REGEX_CHZ, string);
}
/**
* 验证用户名
* <p>取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位</p>
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isUsername(String string) {
return isMatch(REGEX_USERNAME, string);
}
/**
* 验证yyyy-MM-dd格式的日期校验,已考虑平闰年
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isDate(String string) {
return isMatch(REGEX_DATE, string);
}
/**
* 验证IP地址
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isIP(String string) {
return isMatch(REGEX_IP, string);
}
/**
* string是否匹配regex
*
* @param regex 正则表达式字符串
* @param string 要匹配的字符串
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isMatch(String regex, String string) {
return !StringUtils.isEmpty(string) && Pattern.matches(regex, string);
}
package com.blankj.utilcode.utils;
import java.util.regex.Pattern;
import static com.blankj.utilcode.utils.ConstUtils.*;
/**
* <pre>
* author: Blankj
* blog : http://blankj.com
* time : 2016/8/2
* desc : 正则相关工具类
* </pre>
*/
public class RegexUtils {
private RegexUtils() {
throw new UnsupportedOperationException("u can't fuck me...");
}
/**
* If u want more please visit http://toutiao.com/i6231678548520731137/
*/
/**
* 验证手机号(简单)
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isMobileSimple(String string) {
return isMatch(REGEX_MOBILE_SIMPLE, string);
}
/**
* 验证手机号(精确)
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isMobileExact(String string) {
return isMatch(REGEX_MOBILE_EXACT, string);
}
/**
* 验证电话号码
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isTel(String string) {
return isMatch(REGEX_TEL, string);
}
/**
* 验证身份证号码15位
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isIDCard15(String string) {
return isMatch(REGEX_IDCARD15, string);
}
/**
* 验证身份证号码18位
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isIDCard18(String string) {
return isMatch(REGEX_IDCARD18, string);
}
/**
* 验证邮箱
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isEmail(String string) {
return isMatch(REGEX_EMAIL, string);
}
/**
* 验证URL
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isURL(String string) {
return isMatch(REGEX_URL, string);
}
/**
* 验证汉字
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isChz(String string) {
return isMatch(REGEX_CHZ, string);
}
/**
* 验证用户名
* <p>取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位</p>
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isUsername(String string) {
return isMatch(REGEX_USERNAME, string);
}
/**
* 验证yyyy-MM-dd格式的日期校验,已考虑平闰年
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isDate(String string) {
return isMatch(REGEX_DATE, string);
}
/**
* 验证IP地址
*
* @param string 待验证文本
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isIP(String string) {
return isMatch(REGEX_IP, string);
}
/**
* string是否匹配regex
*
* @param regex 正则表达式字符串
* @param string 要匹配的字符串
* @return {@code true}: 匹配<br>{@code false}: 不匹配
*/
public static boolean isMatch(String regex, String string) {
return !StringUtils.isEmpty(string) && Pattern.matches(regex, string);
}
}
\ No newline at end of file
......@@ -39,6 +39,12 @@ public class ImageUtilsTest {
@Test
public void testBytes2Bitmap() throws Exception {
int a = 15, b = a;
int i = 1;
while ((a >>= 1) >= 2 && (b >>= 1) >= 2) {
i <<= 1;
System.out.println(a + ", " + b + ", "+i);
}
}
@Test
......
......@@ -2,7 +2,7 @@ package com.blankj.utilcode.utils;
import org.junit.Test;
import static com.blankj.utilcode.utils.RegularUtils.*;
import static com.blankj.utilcode.utils.RegexUtils.*;
import static com.google.common.truth.Truth.assertThat;
/**
......@@ -13,7 +13,7 @@ import static com.google.common.truth.Truth.assertThat;
* desc : RegularUtils单元测试
* </pre>
*/
public class RegularUtilsTest {
public class RegexUtilsTest {
@Test
public void testIsMobileSimple() throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册