// check arguments
affirm(inClassFile, "Illegal argument: inClassFile == null.");
affirm(outClassFile, "Illegal argument: outClassFile == null.");
// parse class
final ClassFile cf;
final Controller cc;
try {
// create class file
final DataInputStream dis = new DataInputStream(inClassFile);
final boolean allowJDK12ClassFiles = true;
cf = new ClassFile(dis, allowJDK12ClassFiles);
//@lars: do not close the input stream
//dis.close();
// create class control
cc = new Controller(cf, env);
// get real class name
final String className = cf.classNameString();
} catch (ClassFormatError ex) {
throw new EnhancerUserException(
getI18N("enhancer.class_format_error"),
ex);
}
// enhance class
cc.enhanceClass();
if (env.errorCount() > 0) {
// retrieve error messages
env.getErrorWriter().flush();
throw new EnhancerUserException(env.getLastErrorMessage());
}
affirm(env.errorCount() == 0);
// write class
boolean changed = cc.updated();
try {
if (changed) {
env.message("writing enhanced class " + cf.userClassName()
+ " to output stream");
} else {
env.message("no changes to class " + cf.userClassName());
}
outClassFile.setClassName(cf.userClassName());
final DataOutputStream dos
= new DataOutputStream(outClassFile.getStream());
cf.write(dos);
dos.flush();
} catch (IOException ex) {
throw new EnhancerUserException(
getI18N("enhancer.io_error_while_writing_stream"),
ex);