use of sun.misc.Resource in project jdk8u_jdk by JetBrains.
the class SystemClassLoaderAction method getBootstrapResource.
/**
* Find resources from the VM's built-in classloader.
*/
private static URL getBootstrapResource(String name) {
URLClassPath ucp = getBootstrapClassPath();
Resource res = ucp.getResource(name);
return res != null ? res.getURL() : null;
}
use of sun.misc.Resource in project quasar by puniverse.
the class QuasarURLClassLoader method instrument.
private Resource instrument(final String className, final Resource res) {
final ClassLoader parent = this;
return new Resource() {
private byte[] instrumented;
@Override
public synchronized byte[] getBytes() throws IOException {
if (instrumented == null) {
final byte[] bytes;
ByteBuffer bb = res.getByteBuffer();
if (bb != null) {
final int size = bb.remaining();
bytes = new byte[size];
bb.get(bytes);
} else
bytes = res.getBytes();
try {
this.instrumented = instrumentor.instrumentClass(parent, className, bytes);
} catch (Exception ex) {
if (MethodDatabase.isProblematicClass(className))
instrumentor.log(LogLevel.INFO, "Skipping problematic class instrumentation %s - %s %s", className, ex, Arrays.toString(ex.getStackTrace()));
else
instrumentor.error("Unable to instrument " + className, ex);
instrumented = bytes;
}
}
return instrumented;
}
@Override
public ByteBuffer getByteBuffer() throws IOException {
return null;
}
@Override
public InputStream getInputStream() throws IOException {
throw new AssertionError();
}
@Override
public String getName() {
return res.getName();
}
@Override
public URL getURL() {
return res.getURL();
}
@Override
public URL getCodeSourceURL() {
return res.getCodeSourceURL();
}
@Override
public int getContentLength() throws IOException {
return res.getContentLength();
}
@Override
public Manifest getManifest() throws IOException {
return res.getManifest();
}
@Override
public Certificate[] getCertificates() {
return res.getCertificates();
}
@Override
public CodeSigner[] getCodeSigners() {
return res.getCodeSigners();
}
};
}
use of sun.misc.Resource in project quasar by puniverse.
the class QuasarURLClassLoaderHelper method instrument.
private Resource instrument(final String className, final Resource res) {
return new Resource() {
private byte[] instrumented;
@Override
public synchronized byte[] getBytes() throws IOException {
if (instrumented == null) {
final byte[] bytes;
ByteBuffer bb = res.getByteBuffer();
if (bb != null) {
final int size = bb.remaining();
bytes = new byte[size];
bb.get(bytes);
} else
bytes = res.getBytes();
try {
this.instrumented = instrumentor.instrumentClass(cl, className, bytes);
} catch (Exception ex) {
if (MethodDatabase.isProblematicClass(className))
instrumentor.log(LogLevel.INFO, "Skipping problematic class instrumentation %s - %s %s", className, ex, Arrays.toString(ex.getStackTrace()));
else
instrumentor.error("Unable to instrument " + className, ex);
instrumented = bytes;
}
}
return instrumented;
}
@Override
public ByteBuffer getByteBuffer() throws IOException {
return null;
}
@Override
public InputStream getInputStream() throws IOException {
throw new AssertionError();
}
@Override
public String getName() {
return res.getName();
}
@Override
public URL getURL() {
return res.getURL();
}
@Override
public URL getCodeSourceURL() {
return res.getCodeSourceURL();
}
@Override
public int getContentLength() throws IOException {
return res.getContentLength();
}
@Override
public Manifest getManifest() throws IOException {
return res.getManifest();
}
@Override
public Certificate[] getCertificates() {
return res.getCertificates();
}
@Override
public CodeSigner[] getCodeSigners() {
return res.getCodeSigners();
}
};
}
use of sun.misc.Resource in project intellij-community by JetBrains.
the class SystemClassLoaderAction method getBootstrapResource.
/**
* Find resources from the VM's built-in classloader.
*/
private static URL getBootstrapResource(String name) {
URLClassPath ucp = getBootstrapClassPath();
Resource res = ucp.getResource(name);
return res != null ? res.getURL() : null;
}
use of sun.misc.Resource in project jdk8u_jdk by JetBrains.
the class FactoryURLClassLoader method findClass.
/**
* Finds and loads the class with the specified name from the URL search
* path. Any URLs referring to JAR files are loaded and opened as needed
* until the class is found.
*
* @param name the name of the class
* @return the resulting class
* @exception ClassNotFoundException if the class could not be found,
* or if the loader is closed.
* @exception NullPointerException if {@code name} is {@code null}.
*/
protected Class<?> findClass(final String name) throws ClassNotFoundException {
final Class<?> result;
try {
result = AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
try {
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
return null;
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
if (result == null) {
throw new ClassNotFoundException(name);
}
return result;
}
Aggregations