Skip to content

Commit

Permalink
Slightly faster Base64 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
blootsvoets committed Jun 23, 2020
1 parent 70e51d2 commit 8136c94
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion radar-commons/src/main/java/org/radarbase/util/Base64.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.radarbase.util;

import static java.nio.charset.StandardCharsets.UTF_8; // Since Android API 19

/**
* This class consists exclusively of static methods for obtaining
* encoders and decoders for the Base64 encoding scheme. The
Expand Down Expand Up @@ -134,7 +136,7 @@ public String encode(byte[] src) {
dst[dstP] = '=';
}

return new String(dst);
return new String(dst, UTF_8);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void encoderTest() {
java.util.Base64.Encoder javaEncoder = java.util.Base64.getEncoder();

ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i = 0; i < 2_000; i++) {
for (int i = 0; i < 2_000; i += 7) {
byte[] src = new byte[i];
random.nextBytes(src);
String actual = encoder.encode(src);
Expand Down

0 comments on commit 8136c94

Please sign in to comment.