@@ -40,6 +40,7 @@ public static String urlEncode(final String input) {
40
40
* @return the urlencoded string
41
41
*/
42
42
public static String urlEncode (final String input , final String charsetName ) {
43
+ if (input == null || input .length () == 0 ) return "" ;
43
44
try {
44
45
return URLEncoder .encode (input , charsetName );
45
46
} catch (UnsupportedEncodingException e ) {
@@ -65,6 +66,7 @@ public static String urlDecode(final String input) {
65
66
* @return the string of decode urlencoded string
66
67
*/
67
68
public static String urlDecode (final String input , final String charsetName ) {
69
+ if (input == null || input .length () == 0 ) return "" ;
68
70
try {
69
71
return URLDecoder .decode (input , charsetName );
70
72
} catch (UnsupportedEncodingException e ) {
@@ -89,6 +91,7 @@ public static byte[] base64Encode(final String input) {
89
91
* @return Base64-encode bytes
90
92
*/
91
93
public static byte [] base64Encode (final byte [] input ) {
94
+ if (input == null || input .length == 0 ) return new byte [0 ];
92
95
return Base64 .encode (input , Base64 .NO_WRAP );
93
96
}
94
97
@@ -99,6 +102,7 @@ public static byte[] base64Encode(final byte[] input) {
99
102
* @return Base64-encode string
100
103
*/
101
104
public static String base64Encode2String (final byte [] input ) {
105
+ if (input == null || input .length == 0 ) return "" ;
102
106
return Base64 .encodeToString (input , Base64 .NO_WRAP );
103
107
}
104
108
@@ -109,6 +113,7 @@ public static String base64Encode2String(final byte[] input) {
109
113
* @return the string of decode Base64-encode string
110
114
*/
111
115
public static byte [] base64Decode (final String input ) {
116
+ if (input == null || input .length () == 0 ) return new byte [0 ];
112
117
return Base64 .decode (input , Base64 .NO_WRAP );
113
118
}
114
119
@@ -119,6 +124,7 @@ public static byte[] base64Decode(final String input) {
119
124
* @return the bytes of decode Base64-encode bytes
120
125
*/
121
126
public static byte [] base64Decode (final byte [] input ) {
127
+ if (input == null || input .length == 0 ) return new byte [0 ];
122
128
return Base64 .decode (input , Base64 .NO_WRAP );
123
129
}
124
130
@@ -129,6 +135,7 @@ public static byte[] base64Decode(final byte[] input) {
129
135
* @return html-encode string
130
136
*/
131
137
public static String htmlEncode (final CharSequence input ) {
138
+ if (input == null || input .length () == 0 ) return "" ;
132
139
StringBuilder sb = new StringBuilder ();
133
140
char c ;
134
141
for (int i = 0 , len = input .length (); i < len ; i ++) {
@@ -169,6 +176,7 @@ public static String htmlEncode(final CharSequence input) {
169
176
*/
170
177
@ SuppressWarnings ("deprecation" )
171
178
public static CharSequence htmlDecode (final String input ) {
179
+ if (input == null || input .length () == 0 ) return "" ;
172
180
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
173
181
return Html .fromHtml (input , Html .FROM_HTML_MODE_LEGACY );
174
182
} else {
0 commit comments