Example usage for com.google.common.io Resources toByteArray

List of usage examples for com.google.common.io Resources toByteArray

Introduction

In this page you can find the example usage for com.google.common.io Resources toByteArray.

Prototype

public static byte[] toByteArray(URL url) throws IOException 

Source Link

Document

Reads all bytes from a URL into a byte array.

Usage

From source file:org.glowroot.agent.weaving.ClassAnalyzer.java

private static List<AnalyzedMethodKey> getNonAbstractMethods(String className, @Nullable ClassLoader loader)
        throws ClassNotFoundException, IOException {
    String path = ClassNames.toInternalName(className) + ".class";
    URL url;/* www  .  ja v  a2  s . c  o m*/
    if (loader == null) {
        // null loader means the bootstrap class loader
        url = ClassLoader.getSystemResource(path);
    } else {
        url = loader.getResource(path);
    }
    if (url == null) {
        // what follows is just a best attempt in the sort-of-rare case when a custom class
        // loader does not expose .class file contents via getResource(), e.g.
        // org.codehaus.groovy.runtime.callsite.CallSiteClassLoader
        return getNonAbstractMethodsPlanB(className, loader);
    }
    byte[] bytes = Resources.toByteArray(url);
    NonAbstractMethodClassVisitor accv = new NonAbstractMethodClassVisitor();
    new ClassReader(bytes).accept(accv, ClassReader.SKIP_FRAMES + ClassReader.SKIP_CODE);
    return accv.analyzedMethodKeys;
}