提交 34797957 编写于 作者: C cmj

see 09/13 log

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