Created
April 2, 2010 19:42
-
-
Save mojavelinux/353601 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ClassLoader cl = new SecureClassLoader() { | |
@Override | |
protected URL findResource(final String name) { | |
final Asset a = archive.get(name); | |
if (a == null) { | |
return null; | |
} | |
try { | |
return new URL(null, "archive:/" + name, new URLStreamHandler() { | |
@Override | |
protected java.net.URLConnection openConnection(URL u) throws java.io.IOException { | |
return new URLConnection(u) { | |
@Override | |
public void connect() throws IOException { | |
} | |
@Override | |
public InputStream getInputStream() | |
throws IOException { | |
return a.openStream(); | |
} | |
}; | |
} | |
; | |
}); | |
} catch (Exception e) { | |
return null; | |
} | |
} | |
@Override | |
protected Enumeration<URL> findResources(String name) throws IOException { | |
Iterator<URL> it = new ArrayList<URL>(0).iterator(); | |
URL resource = findResource(name); | |
if (resource != null) { | |
it = Arrays.asList(resource).iterator(); | |
} | |
final Iterator<URL> i = it; | |
return new Enumeration<URL>() { | |
@Override | |
public boolean hasMoreElements() { | |
return i.hasNext(); | |
} | |
@Override | |
public URL nextElement() { | |
return i.next(); | |
} | |
}; | |
} | |
}; | |
Thread.currentThread().setContextClassLoader(cl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment