Skip to content

Commit 28b0442

Browse files
committed
see 04/25 log
1 parent 2a5c5e4 commit 28b0442

22 files changed

+643
-161
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ ext {
3333
min_sdk_version = 14
3434
target_sdk_version = 27
3535

36-
version_code = 1_014_000
37-
version_name = '1.14.0'// E.g 1.9.72 => 1,009,072
36+
version_code = 1_014_001
37+
version_name = '1.14.1'// E.g 1.9.72 => 1,009,072
3838

3939
// App dependencies
4040
support_version = '27.1.0'

utilcode/README-CN.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,7 @@ isToday : 判断是否今天
633633
isLeapYear : 判断是否闰年
634634
getChineseWeek : 获取中式星期
635635
getUSWeek : 获取美式式星期
636-
getWeekIndex : 获取星期索引
637-
getWeekOfMonth : 获取月份中的第几周
638-
getWeekOfYear : 获取年份中的第几周
636+
getValueByCalendarField : 根据日历字段获取值
639637
getChineseZodiac : 获取生肖
640638
getZodiac : 获取星座
641639
```

utilcode/src/main/java/com/blankj/utilcode/util/AppUtils.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,14 @@ public static String getAppName() {
528528
* @return the application's name
529529
*/
530530
public static String getAppName(final String packageName) {
531-
if (isSpace(packageName)) return null;
531+
if (isSpace(packageName)) return "";
532532
try {
533533
PackageManager pm = Utils.getApp().getPackageManager();
534534
PackageInfo pi = pm.getPackageInfo(packageName, 0);
535535
return pi == null ? null : pi.applicationInfo.loadLabel(pm).toString();
536536
} catch (PackageManager.NameNotFoundException e) {
537537
e.printStackTrace();
538-
return null;
538+
return "";
539539
}
540540
}
541541

@@ -555,14 +555,14 @@ public static String getAppPath() {
555555
* @return the application's path
556556
*/
557557
public static String getAppPath(final String packageName) {
558-
if (isSpace(packageName)) return null;
558+
if (isSpace(packageName)) return "";
559559
try {
560560
PackageManager pm = Utils.getApp().getPackageManager();
561561
PackageInfo pi = pm.getPackageInfo(packageName, 0);
562562
return pi == null ? null : pi.applicationInfo.sourceDir;
563563
} catch (PackageManager.NameNotFoundException e) {
564564
e.printStackTrace();
565-
return null;
565+
return "";
566566
}
567567
}
568568

@@ -582,14 +582,14 @@ public static String getAppVersionName() {
582582
* @return the application's version name
583583
*/
584584
public static String getAppVersionName(final String packageName) {
585-
if (isSpace(packageName)) return null;
585+
if (isSpace(packageName)) return "";
586586
try {
587587
PackageManager pm = Utils.getApp().getPackageManager();
588588
PackageInfo pi = pm.getPackageInfo(packageName, 0);
589589
return pi == null ? null : pi.versionName;
590590
} catch (PackageManager.NameNotFoundException e) {
591591
e.printStackTrace();
592-
return null;
592+
return "";
593593
}
594594
}
595595

@@ -663,9 +663,10 @@ public static String getAppSignatureSHA1() {
663663
* @param packageName The name of the package.
664664
* @return the application's signature for SHA1 value
665665
*/
666-
public static String getAppSignatureSHA1(@NonNull final String packageName) {
666+
public static String getAppSignatureSHA1(final String packageName) {
667+
if (isSpace(packageName)) return "";
667668
Signature[] signature = getAppSignature(packageName);
668-
if (signature == null || signature.length <= 0) return null;
669+
if (signature == null || signature.length <= 0) return "";
669670
return encryptSHA1ToString(signature[0].toByteArray()).
670671
replaceAll("(?<=[0-9A-F]{2})[0-9A-F]{2}", ":$0");
671672
}
@@ -794,9 +795,9 @@ private static byte[] encryptSHA1(final byte[] data) {
794795
}
795796

796797
private static String bytes2HexString(final byte[] bytes) {
797-
if (bytes == null) return null;
798+
if (bytes == null) return "";
798799
int len = bytes.length;
799-
if (len <= 0) return null;
800+
if (len <= 0) return "";
800801
char[] ret = new char[len << 1];
801802
for (int i = 0, j = 0; i < len; i++) {
802803
ret[j++] = HEX_DIGITS[bytes[i] >>> 4 & 0x0f];

utilcode/src/main/java/com/blankj/utilcode/util/CacheUtils.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,13 @@ private static void writeFileFromBytes(final File file, final byte[] bytes) {
809809
} catch (IOException e) {
810810
e.printStackTrace();
811811
} finally {
812-
CloseUtils.closeIO(fc);
812+
try {
813+
if (fc != null) {
814+
fc.close();
815+
}
816+
} catch (IOException e) {
817+
e.printStackTrace();
818+
}
813819
}
814820
}
815821

@@ -826,7 +832,13 @@ private static byte[] readFile2Bytes(final File file) {
826832
e.printStackTrace();
827833
return null;
828834
} finally {
829-
CloseUtils.closeIO(fc);
835+
try {
836+
if (fc != null) {
837+
fc.close();
838+
}
839+
} catch (IOException e) {
840+
e.printStackTrace();
841+
}
830842
}
831843
}
832844

@@ -902,7 +914,13 @@ private static byte[] serializable2Bytes(final Serializable serializable) {
902914
e.printStackTrace();
903915
return null;
904916
} finally {
905-
CloseUtils.closeIO(oos);
917+
try {
918+
if (oos != null) {
919+
oos.close();
920+
}
921+
} catch (IOException e) {
922+
e.printStackTrace();
923+
}
906924
}
907925
}
908926

@@ -916,7 +934,13 @@ private static Object bytes2Object(final byte[] bytes) {
916934
e.printStackTrace();
917935
return null;
918936
} finally {
919-
CloseUtils.closeIO(ois);
937+
try {
938+
if (ois != null) {
939+
ois.close();
940+
}
941+
} catch (IOException e) {
942+
e.printStackTrace();
943+
}
920944
}
921945
}
922946

utilcode/src/main/java/com/blankj/utilcode/util/ConvertUtils.java

+19-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private ConvertUtils() {
4444
* @return bits
4545
*/
4646
public static String bytes2Bits(final byte[] bytes) {
47+
if (bytes == null || bytes.length == 0) return "";
4748
StringBuilder sb = new StringBuilder();
4849
for (byte aByte : bytes) {
4950
for (int j = 7; j >= 0; --j) {
@@ -120,9 +121,9 @@ public static byte[] chars2Bytes(final char[] chars) {
120121
* @return hex string
121122
*/
122123
public static String bytes2HexString(final byte[] bytes) {
123-
if (bytes == null) return null;
124+
if (bytes == null) return "";
124125
int len = bytes.length;
125-
if (len <= 0) return null;
126+
if (len <= 0) return "";
126127
char[] ret = new char[len << 1];
127128
for (int i = 0, j = 0; i < len; i++) {
128129
ret[j++] = hexDigits[bytes[i] >>> 4 & 0x0f];
@@ -312,7 +313,11 @@ public static ByteArrayOutputStream input2OutputStream(final InputStream is) {
312313
e.printStackTrace();
313314
return null;
314315
} finally {
315-
CloseUtils.closeIO(is);
316+
try {
317+
is.close();
318+
} catch (IOException e) {
319+
e.printStackTrace();
320+
}
316321
}
317322
}
318323

@@ -377,7 +382,13 @@ public static OutputStream bytes2OutputStream(final byte[] bytes) {
377382
e.printStackTrace();
378383
return null;
379384
} finally {
380-
CloseUtils.closeIO(os);
385+
try {
386+
if (os != null) {
387+
os.close();
388+
}
389+
} catch (IOException e) {
390+
e.printStackTrace();
391+
}
381392
}
382393
}
383394

@@ -389,12 +400,12 @@ public static OutputStream bytes2OutputStream(final byte[] bytes) {
389400
* @return string
390401
*/
391402
public static String inputStream2String(final InputStream is, final String charsetName) {
392-
if (is == null || isSpace(charsetName)) return null;
403+
if (is == null || isSpace(charsetName)) return "";
393404
try {
394405
return new String(inputStream2Bytes(is), charsetName);
395406
} catch (UnsupportedEncodingException e) {
396407
e.printStackTrace();
397-
return null;
408+
return "";
398409
}
399410
}
400411

@@ -423,12 +434,12 @@ public static InputStream string2InputStream(final String string, final String c
423434
* @return string
424435
*/
425436
public static String outputStream2String(final OutputStream out, final String charsetName) {
426-
if (out == null || isSpace(charsetName)) return null;
437+
if (out == null || isSpace(charsetName)) return "";
427438
try {
428439
return new String(outputStream2Bytes(out), charsetName);
429440
} catch (UnsupportedEncodingException e) {
430441
e.printStackTrace();
431-
return null;
442+
return "";
432443
}
433444
}
434445

utilcode/src/main/java/com/blankj/utilcode/util/DeviceUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ public static int getSDKVersionCode() {
7676
*/
7777
@SuppressLint("HardwareIds")
7878
public static String getAndroidID() {
79-
return Settings.Secure.getString(
79+
String id = Settings.Secure.getString(
8080
Utils.getApp().getContentResolver(),
8181
Settings.Secure.ANDROID_ID
8282
);
83+
return id == null ? "" : id;
8384
}
8485

8586
/**

utilcode/src/main/java/com/blankj/utilcode/util/EncodeUtils.java

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static String urlEncode(final String input) {
4040
* @return the urlencoded string
4141
*/
4242
public static String urlEncode(final String input, final String charsetName) {
43+
if (input == null || input.length() == 0) return "";
4344
try {
4445
return URLEncoder.encode(input, charsetName);
4546
} catch (UnsupportedEncodingException e) {
@@ -65,6 +66,7 @@ public static String urlDecode(final String input) {
6566
* @return the string of decode urlencoded string
6667
*/
6768
public static String urlDecode(final String input, final String charsetName) {
69+
if (input == null || input.length() == 0) return "";
6870
try {
6971
return URLDecoder.decode(input, charsetName);
7072
} catch (UnsupportedEncodingException e) {
@@ -89,6 +91,7 @@ public static byte[] base64Encode(final String input) {
8991
* @return Base64-encode bytes
9092
*/
9193
public static byte[] base64Encode(final byte[] input) {
94+
if (input == null || input.length == 0) return new byte[0];
9295
return Base64.encode(input, Base64.NO_WRAP);
9396
}
9497

@@ -99,6 +102,7 @@ public static byte[] base64Encode(final byte[] input) {
99102
* @return Base64-encode string
100103
*/
101104
public static String base64Encode2String(final byte[] input) {
105+
if (input == null || input.length == 0) return "";
102106
return Base64.encodeToString(input, Base64.NO_WRAP);
103107
}
104108

@@ -109,6 +113,7 @@ public static String base64Encode2String(final byte[] input) {
109113
* @return the string of decode Base64-encode string
110114
*/
111115
public static byte[] base64Decode(final String input) {
116+
if (input == null || input.length() == 0) return new byte[0];
112117
return Base64.decode(input, Base64.NO_WRAP);
113118
}
114119

@@ -119,6 +124,7 @@ public static byte[] base64Decode(final String input) {
119124
* @return the bytes of decode Base64-encode bytes
120125
*/
121126
public static byte[] base64Decode(final byte[] input) {
127+
if (input == null || input.length == 0) return new byte[0];
122128
return Base64.decode(input, Base64.NO_WRAP);
123129
}
124130

@@ -129,6 +135,7 @@ public static byte[] base64Decode(final byte[] input) {
129135
* @return html-encode string
130136
*/
131137
public static String htmlEncode(final CharSequence input) {
138+
if (input == null || input.length() == 0) return "";
132139
StringBuilder sb = new StringBuilder();
133140
char c;
134141
for (int i = 0, len = input.length(); i < len; i++) {
@@ -169,6 +176,7 @@ public static String htmlEncode(final CharSequence input) {
169176
*/
170177
@SuppressWarnings("deprecation")
171178
public static CharSequence htmlDecode(final String input) {
179+
if (input == null || input.length() == 0) return "";
172180
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
173181
return Html.fromHtml(input, Html.FROM_HTML_MODE_LEGACY);
174182
} else {

0 commit comments

Comments
 (0)