/*
* The writer is at the end of the visitor chain. Pass true to
* calculate stack size, for safety.
*/
ClassWriter writer = new ClassWriter(true);
ClassVisitor visitor = writer;
/* The enhancer is at the beginning of the visitor chain. */
visitor = new BytecodeEnhancer(visitor);
/* The reader processes the class and invokes the visitors. */
ClassReader reader = new ClassReader(bytes);
try {
/*
* Pass false for skipDebug since we are rewriting the class and
* should include all information.
*/
reader.accept(visitor, false);
return writer.toByteArray();
} catch (BytecodeEnhancer.NotPersistentException e) {
/* The class is not persistent and should not be enhanced. */
return null;
}
}