2828import java .util .Arrays ;
2929import java .util .Random ;
3030
31+ import org .apache .commons .codec .Charsets ;
3132import org .apache .commons .codec .DecoderException ;
3233import org .apache .commons .codec .EncoderException ;
3334import org .junit .Ignore ;
@@ -127,7 +128,7 @@ public void testCodeInteger1() throws UnsupportedEncodingException {
127128 BigInteger bigInt1 = new BigInteger ("85739377120809420210425962799" + "0318636601332086981" );
128129
129130 assertEquals (encodedInt1 , new String (Base64 .encodeInteger (bigInt1 )));
130- assertEquals (bigInt1 , Base64 .decodeInteger (encodedInt1 .getBytes ("UTF-8" )));
131+ assertEquals (bigInt1 , Base64 .decodeInteger (encodedInt1 .getBytes (Charsets . UTF_8 )));
131132 }
132133
133134 @ Test
@@ -136,7 +137,7 @@ public void testCodeInteger2() throws UnsupportedEncodingException {
136137 BigInteger bigInt2 = new BigInteger ("13936727572861167254666467268" + "91466679477132949611" );
137138
138139 assertEquals (encodedInt2 , new String (Base64 .encodeInteger (bigInt2 )));
139- assertEquals (bigInt2 , Base64 .decodeInteger (encodedInt2 .getBytes ("UTF-8" )));
140+ assertEquals (bigInt2 , Base64 .decodeInteger (encodedInt2 .getBytes (Charsets . UTF_8 )));
140141 }
141142
142143 @ Test
@@ -147,7 +148,7 @@ public void testCodeInteger3() throws UnsupportedEncodingException {
147148 + "4495062430572478766856090958495998158114332651671116876320938126" );
148149
149150 assertEquals (encodedInt3 , new String (Base64 .encodeInteger (bigInt3 )));
150- assertEquals (bigInt3 , Base64 .decodeInteger (encodedInt3 .getBytes ("UTF-8" )));
151+ assertEquals (bigInt3 , Base64 .decodeInteger (encodedInt3 .getBytes (Charsets . UTF_8 )));
151152 }
152153
153154 @ Test
@@ -164,7 +165,7 @@ public void testCodeInteger4() throws UnsupportedEncodingException {
164165 + "53542091716518238707344493641683483917" );
165166
166167 assertEquals (encodedInt4 , new String (Base64 .encodeInteger (bigInt4 )));
167- assertEquals (bigInt4 , Base64 .decodeInteger (encodedInt4 .getBytes ("UTF-8" )));
168+ assertEquals (bigInt4 , Base64 .decodeInteger (encodedInt4 .getBytes (Charsets . UTF_8 )));
168169 }
169170
170171 @ Test
@@ -249,54 +250,54 @@ public void testConstructor_Int_ByteArray_Boolean_UrlSafe() {
249250 */
250251 @ Test
251252 public void testDecodePadMarkerIndex2 () throws UnsupportedEncodingException {
252- assertEquals ("A" , new String (Base64 .decodeBase64 ("QQ==" .getBytes ("UTF-8" ))));
253+ assertEquals ("A" , new String (Base64 .decodeBase64 ("QQ==" .getBytes (Charsets . UTF_8 ))));
253254 }
254255
255256 /**
256257 * Tests conditional branches for "marker1" test.
257258 */
258259 @ Test
259260 public void testDecodePadMarkerIndex3 () throws UnsupportedEncodingException {
260- assertEquals ("AA" , new String (Base64 .decodeBase64 ("QUE=" .getBytes ("UTF-8" ))));
261- assertEquals ("AAA" , new String (Base64 .decodeBase64 ("QUFB" .getBytes ("UTF-8" ))));
261+ assertEquals ("AA" , new String (Base64 .decodeBase64 ("QUE=" .getBytes (Charsets . UTF_8 ))));
262+ assertEquals ("AAA" , new String (Base64 .decodeBase64 ("QUFB" .getBytes (Charsets . UTF_8 ))));
262263 }
263264
264265 @ Test
265266 public void testDecodePadOnly () throws UnsupportedEncodingException {
266- assertEquals (0 , Base64 .decodeBase64 ("====" .getBytes ("UTF-8" )).length );
267- assertEquals ("" , new String (Base64 .decodeBase64 ("====" .getBytes ("UTF-8" ))));
267+ assertEquals (0 , Base64 .decodeBase64 ("====" .getBytes (Charsets . UTF_8 )).length );
268+ assertEquals ("" , new String (Base64 .decodeBase64 ("====" .getBytes (Charsets . UTF_8 ))));
268269 // Test truncated padding
269- assertEquals (0 , Base64 .decodeBase64 ("===" .getBytes ("UTF-8" )).length );
270- assertEquals (0 , Base64 .decodeBase64 ("==" .getBytes ("UTF-8" )).length );
271- assertEquals (0 , Base64 .decodeBase64 ("=" .getBytes ("UTF-8" )).length );
272- assertEquals (0 , Base64 .decodeBase64 ("" .getBytes ("UTF-8" )).length );
270+ assertEquals (0 , Base64 .decodeBase64 ("===" .getBytes (Charsets . UTF_8 )).length );
271+ assertEquals (0 , Base64 .decodeBase64 ("==" .getBytes (Charsets . UTF_8 )).length );
272+ assertEquals (0 , Base64 .decodeBase64 ("=" .getBytes (Charsets . UTF_8 )).length );
273+ assertEquals (0 , Base64 .decodeBase64 ("" .getBytes (Charsets . UTF_8 )).length );
273274 }
274275
275276 @ Test
276277 public void testDecodePadOnlyChunked () throws UnsupportedEncodingException {
277- assertEquals (0 , Base64 .decodeBase64 ("====\n " .getBytes ("UTF-8" )).length );
278- assertEquals ("" , new String (Base64 .decodeBase64 ("====\n " .getBytes ("UTF-8" ))));
278+ assertEquals (0 , Base64 .decodeBase64 ("====\n " .getBytes (Charsets . UTF_8 )).length );
279+ assertEquals ("" , new String (Base64 .decodeBase64 ("====\n " .getBytes (Charsets . UTF_8 ))));
279280 // Test truncated padding
280- assertEquals (0 , Base64 .decodeBase64 ("===\n " .getBytes ("UTF-8" )).length );
281- assertEquals (0 , Base64 .decodeBase64 ("==\n " .getBytes ("UTF-8" )).length );
282- assertEquals (0 , Base64 .decodeBase64 ("=\n " .getBytes ("UTF-8" )).length );
283- assertEquals (0 , Base64 .decodeBase64 ("\n " .getBytes ("UTF-8" )).length );
281+ assertEquals (0 , Base64 .decodeBase64 ("===\n " .getBytes (Charsets . UTF_8 )).length );
282+ assertEquals (0 , Base64 .decodeBase64 ("==\n " .getBytes (Charsets . UTF_8 )).length );
283+ assertEquals (0 , Base64 .decodeBase64 ("=\n " .getBytes (Charsets . UTF_8 )).length );
284+ assertEquals (0 , Base64 .decodeBase64 ("\n " .getBytes (Charsets . UTF_8 )).length );
284285 }
285286
286287 @ Test
287288 public void testDecodeWithWhitespace () throws Exception {
288289
289290 String orig = "I am a late night coder." ;
290291
291- byte [] encodedArray = Base64 .encodeBase64 (orig .getBytes ("UTF-8" ));
292+ byte [] encodedArray = Base64 .encodeBase64 (orig .getBytes (Charsets . UTF_8 ));
292293 StringBuffer intermediate = new StringBuffer (new String (encodedArray ));
293294
294295 intermediate .insert (2 , ' ' );
295296 intermediate .insert (5 , '\t' );
296297 intermediate .insert (10 , '\r' );
297298 intermediate .insert (15 , '\n' );
298299
299- byte [] encodedWithWS = intermediate .toString ().getBytes ("UTF-8" );
300+ byte [] encodedWithWS = intermediate .toString ().getBytes (Charsets . UTF_8 );
300301 byte [] decodedWithWS = Base64 .decodeBase64 (encodedWithWS );
301302
302303 String dest = new String (decodedWithWS );
@@ -373,7 +374,7 @@ private void testEncodeOverMaxSize(int maxSize) throws Exception {
373374 @ Test
374375 public void testIgnoringNonBase64InDecode () throws Exception {
375376 assertEquals ("The quick brown fox jumped over the lazy dogs." , new String (Base64
376- .decodeBase64 ("VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n \r \t %#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" .getBytes ("UTF-8" ))));
377+ .decodeBase64 ("VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n \r \t %#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" .getBytes (Charsets . UTF_8 ))));
377378 }
378379
379380 @ Test
@@ -409,37 +410,37 @@ public void testIsUrlSafe() {
409410 @ Test
410411 public void testKnownDecodings () throws UnsupportedEncodingException {
411412 assertEquals ("The quick brown fox jumped over the lazy dogs." , new String (Base64
412- .decodeBase64 ("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" .getBytes ("UTF-8" ))));
413+ .decodeBase64 ("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" .getBytes (Charsets . UTF_8 ))));
413414 assertEquals ("It was the best of times, it was the worst of times." , new String (Base64
414- .decodeBase64 ("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==" .getBytes ("UTF-8" ))));
415+ .decodeBase64 ("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==" .getBytes (Charsets . UTF_8 ))));
415416 assertEquals ("http://jakarta.apache.org/commmons" , new String (Base64
416- .decodeBase64 ("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==" .getBytes ("UTF-8" ))));
417+ .decodeBase64 ("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==" .getBytes (Charsets . UTF_8 ))));
417418 assertEquals ("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz" , new String (Base64
418- .decodeBase64 ("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==" .getBytes ("UTF-8" ))));
419+ .decodeBase64 ("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==" .getBytes (Charsets . UTF_8 ))));
419420 assertEquals ("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }" , new String (Base64 .decodeBase64 ("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0="
420- .getBytes ("UTF-8" ))));
421- assertEquals ("xyzzy!" , new String (Base64 .decodeBase64 ("eHl6enkh" .getBytes ("UTF-8" ))));
421+ .getBytes (Charsets . UTF_8 ))));
422+ assertEquals ("xyzzy!" , new String (Base64 .decodeBase64 ("eHl6enkh" .getBytes (Charsets . UTF_8 ))));
422423 }
423424
424425 @ Test
425426 public void testKnownEncodings () throws UnsupportedEncodingException {
426427 assertEquals ("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==" , new String (Base64
427- .encodeBase64 ("The quick brown fox jumped over the lazy dogs." .getBytes ("UTF-8" ))));
428+ .encodeBase64 ("The quick brown fox jumped over the lazy dogs." .getBytes (Charsets . UTF_8 ))));
428429 assertEquals (
429430 "YmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJs\r \n YWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFo\r \n IGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBi\r \n bGFoIGJsYWg=\r \n " ,
430431 new String (
431432 Base64
432433 .encodeBase64Chunked ("blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"
433- .getBytes ("UTF-8" ))));
434+ .getBytes (Charsets . UTF_8 ))));
434435 assertEquals ("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==" , new String (Base64
435- .encodeBase64 ("It was the best of times, it was the worst of times." .getBytes ("UTF-8" ))));
436+ .encodeBase64 ("It was the best of times, it was the worst of times." .getBytes (Charsets . UTF_8 ))));
436437 assertEquals ("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==" , new String (Base64
437- .encodeBase64 ("http://jakarta.apache.org/commmons" .getBytes ("UTF-8" ))));
438+ .encodeBase64 ("http://jakarta.apache.org/commmons" .getBytes (Charsets . UTF_8 ))));
438439 assertEquals ("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==" , new String (Base64
439- .encodeBase64 ("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz" .getBytes ("UTF-8" ))));
440+ .encodeBase64 ("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz" .getBytes (Charsets . UTF_8 ))));
440441 assertEquals ("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=" , new String (Base64 .encodeBase64 ("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }"
441- .getBytes ("UTF-8" ))));
442- assertEquals ("eHl6enkh" , new String (Base64 .encodeBase64 ("xyzzy!" .getBytes ("UTF-8" ))));
442+ .getBytes (Charsets . UTF_8 ))));
443+ assertEquals ("eHl6enkh" , new String (Base64 .encodeBase64 ("xyzzy!" .getBytes (Charsets . UTF_8 ))));
443444 }
444445
445446 @ Test
@@ -481,7 +482,7 @@ public void testObjectDecodeWithInvalidParameter() throws Exception {
481482 public void testObjectDecodeWithValidParameter () throws Exception {
482483
483484 String original = "Hello World!" ;
484- Object o = Base64 .encodeBase64 (original .getBytes ("UTF-8" ));
485+ Object o = Base64 .encodeBase64 (original .getBytes (Charsets . UTF_8 ));
485486
486487 Base64 b64 = new Base64 ();
487488 Object oDecoded = b64 .decode (o );
@@ -506,7 +507,7 @@ public void testObjectEncodeWithInvalidParameter() throws Exception {
506507 public void testObjectEncodeWithValidParameter () throws Exception {
507508
508509 String original = "Hello World!" ;
509- Object origObj = original .getBytes ("UTF-8" );
510+ Object origObj = original .getBytes (Charsets . UTF_8 );
510511
511512 Base64 b64 = new Base64 ();
512513 Object oEncoded = b64 .encode (origObj );
@@ -519,7 +520,7 @@ public void testObjectEncodeWithValidParameter() throws Exception {
519520 @ Test
520521 public void testObjectEncode () throws Exception {
521522 Base64 b64 = new Base64 ();
522- assertEquals ("SGVsbG8gV29ybGQ=" , new String (b64 .encode ("Hello World" .getBytes ("UTF-8" ))));
523+ assertEquals ("SGVsbG8gV29ybGQ=" , new String (b64 .encode ("Hello World" .getBytes (Charsets . UTF_8 ))));
523524 }
524525
525526 @ Test
0 commit comments