Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert fix for 2291 #3

Merged
merged 1 commit into from
Jun 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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;
Expand Down Expand Up @@ -126,26 +125,8 @@ public static List<byte[]> 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<byte[]> bytes = singleton().resources.get(resName);
if (bytes != null && !bytes.isEmpty()) {
byte[] resBytes = bytes.get(0);
in = new ByteArrayInputStream(resBytes);
length = resBytes.length;
}
}
}

@Override
Expand All @@ -154,20 +135,17 @@ public void connect() throws IOException {

@Override
public InputStream getInputStream() throws IOException {
if (in == null) {
throw new FileNotFoundException(url.toString());
}
return in;
return new ByteArrayInputStream(resourceBytes);
}

@Override
public long getContentLengthLong() {
return length;
return resourceBytes.length;
}
}

try {
return new URL(JavaNetSubstitutions.RESOURCE_PROTOCOL, null, -1, name, new URLStreamHandler() {
return new URL("resource", null, -1, name, new URLStreamHandler() {
@Override
protected URLConnection openConnection(URL u) throws IOException {
return new Conn(u);
Expand Down