mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
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:
parent
288e3b97fe
commit
c0ed3d54d7
|
@ -21,7 +21,7 @@ import java.util.Arrays;
|
||||||
*
|
*
|
||||||
* @author Alexey Andreev
|
* @author Alexey Andreev
|
||||||
*/
|
*/
|
||||||
public class Base64 {
|
public final class Base64 {
|
||||||
private static char[] alphabet = new char[64];
|
private static char[] alphabet = new char[64];
|
||||||
private static int[] reverse = new int[256];
|
private static int[] reverse = new int[256];
|
||||||
|
|
||||||
|
@ -45,9 +45,13 @@ public class Base64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Base64() {
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] decode(String text) {
|
public static byte[] decode(String text) {
|
||||||
int outputSize = ((text.length() - 1) / 4 + 1) * 3;
|
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) {
|
for (i = text.length() - 1; i >= 0 && text.charAt(i) == '='; --i) {
|
||||||
--outputSize;
|
--outputSize;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +59,7 @@ public class Base64 {
|
||||||
|
|
||||||
int triples = (outputSize / 3) * 3;
|
int triples = (outputSize / 3) * 3;
|
||||||
i = 0;
|
i = 0;
|
||||||
for (j = 0; i < triples;) {
|
for (j = 0; j < triples;) {
|
||||||
int a = decode(text.charAt(i++));
|
int a = decode(text.charAt(i++));
|
||||||
int b = decode(text.charAt(i++));
|
int b = decode(text.charAt(i++));
|
||||||
int c = 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;
|
int out = (a << 18) | (b << 12) | (c << 6) | d;
|
||||||
output[j++] = (byte) (out >>> 16);
|
output[j++] = (byte) (out >>> 16);
|
||||||
output[j++] = (byte) (out >>> 8);
|
output[j++] = (byte) (out >>> 8);
|
||||||
output[j++] = (byte) (out);
|
output[j++] = (byte) out;
|
||||||
}
|
}
|
||||||
int rem = output.length - j;
|
int rem = output.length - j;
|
||||||
if (rem == 1) {
|
if (rem == 1) {
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class ClassLoaderTest {
|
||||||
assertEquals("qwerty", loadResource("6"));
|
assertEquals("qwerty", loadResource("6"));
|
||||||
assertEquals("qwertyu", loadResource("7"));
|
assertEquals("qwertyu", loadResource("7"));
|
||||||
assertEquals("qwertyui", loadResource("8"));
|
assertEquals("qwertyui", loadResource("8"));
|
||||||
|
assertEquals("qwertyuiopasdfghjklzxcvbnm", loadResource("9"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -21,7 +21,7 @@ import org.teavm.classlib.ResourceSupplierContext;
|
||||||
public class TestResourcesSupplier implements ResourceSupplier {
|
public class TestResourcesSupplier implements ResourceSupplier {
|
||||||
@Override
|
@Override
|
||||||
public String[] supplyResources(ResourceSupplierContext context) {
|
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) {
|
for (int i = 0; i < result.length; ++i) {
|
||||||
result[i] = "resources-for-test/" + result[i];
|
result[i] = "resources-for-test/" + result[i];
|
||||||
}
|
}
|
||||||
|
|
1
tests/src/test/resources/resources-for-test/9
Normal file
1
tests/src/test/resources/resources-for-test/9
Normal file
|
@ -0,0 +1 @@
|
||||||
|
qwertyuiopasdfghjklzxcvbnm
|
Loading…
Reference in New Issue
Block a user