mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
JS: fix ClassLoader.getResourceBundle for non-existent resources
This commit is contained in:
parent
39cdf3bfed
commit
25b298b1d0
|
@ -17,15 +17,12 @@ package org.teavm.classlib.java.lang;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import org.teavm.classlib.impl.Base64;
|
||||
import org.teavm.backend.javascript.spi.InjectedBy;
|
||||
import org.teavm.classlib.impl.Base64;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSIndexer;
|
||||
import org.teavm.jso.JSObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Alexey Andreev
|
||||
*/
|
||||
public abstract class TClassLoader extends TObject {
|
||||
private TClassLoader parent;
|
||||
private static TSystemClassLoader systemClassLoader = new TSystemClassLoader();
|
||||
|
@ -51,15 +48,19 @@ public abstract class TClassLoader extends TObject {
|
|||
if (resources == null) {
|
||||
resources = supplyResources();
|
||||
}
|
||||
String data = resources.getResource(name);
|
||||
return data == null ? null : new ByteArrayInputStream(Base64.decode(data));
|
||||
JSObject data = resources.getResource(name);
|
||||
String dataString = resourceToString(data);
|
||||
return dataString == null ? null : new ByteArrayInputStream(Base64.decode(dataString));
|
||||
}
|
||||
|
||||
@JSBody(params = "resource", script = "return resource !== null && resource !== void 0 ? resource : null;")
|
||||
private static native String resourceToString(JSObject resource);
|
||||
|
||||
@InjectedBy(ClassLoaderNativeGenerator.class)
|
||||
private static native ResourceContainer supplyResources();
|
||||
|
||||
interface ResourceContainer extends JSObject {
|
||||
@JSIndexer
|
||||
String getResource(String name);
|
||||
JSObject getResource(String name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.teavm.classlib.java.lang;
|
|||
import static org.junit.Assert.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -37,6 +38,12 @@ public class ClassLoaderTest {
|
|||
assertEquals("qwertyui", loadResource("8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNullForNonExistentResource() {
|
||||
InputStream input = ClassLoader.getSystemClassLoader().getResourceAsStream("non-existent-resource.txt");
|
||||
assertNull(input);
|
||||
}
|
||||
|
||||
private static String loadResource(String name) {
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream(
|
||||
|
|
Loading…
Reference in New Issue
Block a user