@@ -13,64 +13,65 @@ public class StringUtils {
1313 private static final char [] DIGITS = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
1414
1515 public static String join (Object [] array , String separator ) {
16- if (array == null ) {
17- return null ;
18- }
19- int arraySize = array .length ;
20- StringBuilder buffer = new StringBuilder ();
21-
22- for (int i = 0 ; i < arraySize ; i ++) {
23- if (i > 0 ) {
24- buffer .append (separator );
25- }
26- if (array [i ] != null ) {
27- buffer .append (array [i ]);
28- }
29- }
30- return buffer .toString ();
16+ if (array == null ) {
17+ return null ;
18+ }
19+ int arraySize = array .length ;
20+ StringBuilder buffer = new StringBuilder ();
21+
22+ for (int i = 0 ; i < arraySize ; i ++) {
23+ if (i > 0 ) {
24+ buffer .append (separator );
25+ }
26+ if (array [i ] != null ) {
27+ buffer .append (array [i ]);
28+ }
29+ }
30+ return buffer .toString ();
3131 }
3232
3333 public static String md5Hex (String data ) {
34- if (data == null ) {
35- throw new IllegalArgumentException ("data must not be null" );
36- }
34+ if (data == null ) {
35+ throw new IllegalArgumentException ("data must not be null" );
36+ }
3737
38- byte [] bytes = digest ("MD5" , data );
38+ byte [] bytes = digest ("MD5" , data );
3939
40- return toHexString (bytes );
40+ return toHexString (bytes );
4141 }
4242
4343 public static String sha1Hex (String data ) {
44- if (data == null ) {
45- throw new IllegalArgumentException ("data must not be null" );
46- }
44+ if (data == null ) {
45+ throw new IllegalArgumentException ("data must not be null" );
46+ }
4747
48- byte [] bytes = digest ("SHA1" , data );
48+ byte [] bytes = digest ("SHA1" , data );
4949
50- return toHexString (bytes );
50+ return toHexString (bytes );
5151 }
5252
5353 private static String toHexString (byte [] bytes ) {
54- int l = bytes .length ;
54+ int l = bytes .length ;
5555
56- char [] out = new char [l << 1 ];
56+ char [] out = new char [l << 1 ];
5757
58- for (int i = 0 , j = 0 ; i < l ; i ++) {
59- out [j ++] = DIGITS [(0xF0 & bytes [i ]) >>> 4 ];
60- out [j ++] = DIGITS [0x0F & bytes [i ]];
61- }
58+ for (int i = 0 , j = 0 ; i < l ; i ++) {
59+ out [j ++] = DIGITS [(0xF0 & bytes [i ]) >>> 4 ];
60+ out [j ++] = DIGITS [0x0F & bytes [i ]];
61+ }
6262
63- return new String (out );
63+ return new String (out );
6464 }
6565
6666 private static byte [] digest (String algorithm , String data ) {
67- MessageDigest digest ;
68- try {
69- digest = MessageDigest .getInstance (algorithm );
70- } catch (NoSuchAlgorithmException e ) {
71- throw new RuntimeException (e );
72- }
73-
74- return digest .digest (data .getBytes ());
67+ MessageDigest digest ;
68+ try {
69+ digest = MessageDigest .getInstance (algorithm );
70+ } catch (NoSuchAlgorithmException e ) {
71+ throw new RuntimeException (e );
72+ }
73+
74+ return digest .digest (data .getBytes ());
7575 }
76- }
76+
77+ }
0 commit comments