@@ -13,64 +13,65 @@ public class StringUtils {
13
13
private static final char [] DIGITS = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
14
14
15
15
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 ();
31
31
}
32
32
33
33
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
+ }
37
37
38
- byte [] bytes = digest ("MD5" , data );
38
+ byte [] bytes = digest ("MD5" , data );
39
39
40
- return toHexString (bytes );
40
+ return toHexString (bytes );
41
41
}
42
42
43
43
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
+ }
47
47
48
- byte [] bytes = digest ("SHA1" , data );
48
+ byte [] bytes = digest ("SHA1" , data );
49
49
50
- return toHexString (bytes );
50
+ return toHexString (bytes );
51
51
}
52
52
53
53
private static String toHexString (byte [] bytes ) {
54
- int l = bytes .length ;
54
+ int l = bytes .length ;
55
55
56
- char [] out = new char [l << 1 ];
56
+ char [] out = new char [l << 1 ];
57
57
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
+ }
62
62
63
- return new String (out );
63
+ return new String (out );
64
64
}
65
65
66
66
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 ());
75
75
}
76
- }
76
+
77
+ }
0 commit comments