diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java index 42d3de41be90..1c12b7842918 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java @@ -25,6 +25,7 @@ package com.oracle.svm.core.jdk; import java.io.ByteArrayInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -125,8 +126,26 @@ public static List get(String name) { public static URL createURL(String name, byte[] resourceBytes) { class Conn extends URLConnection { + + private InputStream in; + private long length = -1L; + Conn(URL url) { super(url); + + // remove "resource:" from url to get the resource name + String resName = url.toString().substring(1 + JavaNetSubstitutions.RESOURCE_PROTOCOL.length()); + if (resName.equals(name)) { + in = new ByteArrayInputStream(resourceBytes); + length = resourceBytes.length; + } else { + final List bytes = singleton().resources.get(resName); + if (bytes != null && !bytes.isEmpty()) { + byte[] resBytes = bytes.get(0); + in = new ByteArrayInputStream(resBytes); + length = resBytes.length; + } + } } @Override @@ -135,17 +154,20 @@ public void connect() throws IOException { @Override public InputStream getInputStream() throws IOException { - return new ByteArrayInputStream(resourceBytes); + if (in == null) { + throw new FileNotFoundException(url.toString()); + } + return in; } @Override public long getContentLengthLong() { - return resourceBytes.length; + return length; } } try { - return new URL("resource", null, -1, name, new URLStreamHandler() { + return new URL(JavaNetSubstitutions.RESOURCE_PROTOCOL, null, -1, name, new URLStreamHandler() { @Override protected URLConnection openConnection(URL u) throws IOException { return new Conn(u);