org.apache.bcel.util.ClassLoaderRepository Java Examples

The following examples show how to use org.apache.bcel.util.ClassLoaderRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Encoder.java    From javasdk with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * get hvm invoke payload.
 *
 * @param bean invoke bean
 * @return payload
 */
public static String encodeInvokeBeanJava(BaseInvoke bean) {
    try {
        //1. get the bean class bytes
        ClassLoaderRepository repository = new ClassLoaderRepository(Thread.currentThread().getContextClassLoader());
        JavaClass beanClass = repository.loadClass(bean.getClass());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        beanClass.dump(baos);
        byte[] clazz = baos.toByteArray();
        if (clazz.length > 0xffff) {
            throw new IOException("the bean class is too large"); // 64k
        }
        //2. get the bean class name
        byte[] clzName = bean.getClass().getCanonicalName().getBytes(Utils.DEFAULT_CHARSET);
        if (clzName.length > 0xffff) {
            throw new IOException("the bean class name is too large"); // 64k
        }
        //3. get the bin of bean
        Gson gson = new Gson();
        byte[] beanBin = gson.toJson(bean).getBytes(Utils.DEFAULT_CHARSET);
        //4. accumulate: | class length(4B) | name length(2B) | class | class name | bin |
        //               | len(txHash)      | len("__txHash__")| txHash | "__txHash__" | bin |
        StringBuilder sb = new StringBuilder();
        sb.append(ByteUtil.toHex(ByteUtil.intToByteArray(clazz.length)));
        sb.append(ByteUtil.toHex(ByteUtil.shortToBytes((short) clzName.length)));

        sb.append(ByteUtil.toHex(clazz));
        sb.append(ByteUtil.toHex(clzName));
        sb.append(ByteUtil.toHex(beanBin));
        return sb.toString();
    } catch (ClassNotFoundException | IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #2
Source File: AllocationInstrumenterVerifier.java    From allocation-instrumenter with Apache License 2.0 5 votes vote down vote up
/**
 * Given a list of fully-qualified (dotted) classnames, instrument each using the
 * AllocationInstrumenter and verify each with BCEL's JustIce verifier.
 */
public static final void main(String[] args) {
  InstrumentingClassLoader loader =
      new InstrumentingClassLoader(
          AllocationInstrumenterVerifier.class.getName().replace('.', '/'),
          "dummyRecorder",
          AllocationInstrumenterVerifier.class.getClassLoader());
  Repository.setRepository(new ClassLoaderRepository(loader));
  Verifier.main(args);
}
 
Example #3
Source File: ClassFileSetCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Stores the class loader and makes it the Repository's class loader.
 * @param aClassLoader class loader to resolve classes with.
 */
public void setClassLoader(ClassLoader aClassLoader)
{
    Repository.setRepository(new ClassLoaderRepository(aClassLoader));
    mClassLoader = aClassLoader;
}
 
Example #4
Source File: ClassFileSetCheck.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Stores the class loader and makes it the Repository's class loader.
 * @param aClassLoader class loader to resolve classes with.
 */
public void setClassLoader(ClassLoader aClassLoader)
{
    Repository.setRepository(new ClassLoaderRepository(aClassLoader));
    mClassLoader = aClassLoader;
}