FileInputStream classInStream = null;
ClassWriter writer = null;
try {
//read in the class
classInStream = new FileInputStream(arg);
ClassReader reader = new ClassReader(classInStream);
//make a ClassWriter constructed with the reader for speed
//since we are mostly just copying
//we just need to override the visit method so we can add
//the synthetic modifier, otherwise we use the methods in
//a standard writer
writer = new ClassWriter(reader, 0) {
@Override
public void visit(int version, int access, String name, String signature,
String superName, String[] interfaces)
{
super.visit(version, access | Opcodes.ACC_SYNTHETIC, name, signature, superName,
interfaces);
}
};
//call accept on the reader to start the visits
//using the writer we created as the visitor
reader.accept(writer, 0);
} finally {
//close the InputStream if it is hanging around
if (classInStream != null) classInStream.close();
}
FileOutputStream classOutStream = null;