Fix base64 support

(cherry picked from commit 5da32e3a6583493a36c87bc02c8177a7740faaf7)

# Conflicts:
#	tests/src/test/java/org/teavm/classlib/java/lang/TestResourcesSupplier.java
This commit is contained in:
Alexey Andreev 2017-05-29 23:26:34 +03:00
parent 288e3b97fe
commit c0ed3d54d7
4 changed files with 11 additions and 5 deletions

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
*
* @author Alexey Andreev
*/
public class Base64 {
public final class Base64 {
private static char[] alphabet = new char[64];
private static int[] reverse = new int[256];
@ -45,9 +45,13 @@ public class Base64 {
}
}
private Base64() {
}
public static byte[] decode(String text) {
int outputSize = ((text.length() - 1) / 4 + 1) * 3;
int i, j;
int i;
int j;
for (i = text.length() - 1; i >= 0 && text.charAt(i) == '='; --i) {
--outputSize;
}
@ -55,7 +59,7 @@ public class Base64 {
int triples = (outputSize / 3) * 3;
i = 0;
for (j = 0; i < triples;) {
for (j = 0; j < triples;) {
int a = decode(text.charAt(i++));
int b = decode(text.charAt(i++));
int c = decode(text.charAt(i++));
@ -63,7 +67,7 @@ public class Base64 {
int out = (a << 18) | (b << 12) | (c << 6) | d;
output[j++] = (byte) (out >>> 16);
output[j++] = (byte) (out >>> 8);
output[j++] = (byte) (out);
output[j++] = (byte) out;
}
int rem = output.length - j;
if (rem == 1) {

View File

@ -36,6 +36,7 @@ public class ClassLoaderTest {
assertEquals("qwerty", loadResource("6"));
assertEquals("qwertyu", loadResource("7"));
assertEquals("qwertyui", loadResource("8"));
assertEquals("qwertyuiopasdfghjklzxcvbnm", loadResource("9"));
}
@Test

View File

@ -21,7 +21,7 @@ import org.teavm.classlib.ResourceSupplierContext;
public class TestResourcesSupplier implements ResourceSupplier {
@Override
public String[] supplyResources(ResourceSupplierContext context) {
String[] result = { "1", "2", "3", "4", "5", "6", "7", "8" };
String[] result = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
for (int i = 0; i < result.length; ++i) {
result[i] = "resources-for-test/" + result[i];
}

View File

@ -0,0 +1 @@
qwertyuiopasdfghjklzxcvbnm