affirm(inByteCode, "Illegal argument: inByteCode == null.");//NOI18N
affirm(outByteCode, "Illegal argument: outByteCode == null.");//NOI18N
// parse class
final ClassFileSource cfs;
final ClassFile cf;
final ClassControl cc;
try {
// create class file source
cfs = new ClassFileSource(null, inByteCode);
// create class file
final DataInputStream dis = cfs.classFileContents();
cf = new ClassFile(dis);
//@lars: do not close the input stream
// dis.close();
// create class control
cc = new ClassControl(cfs, cf, env);
env.addClass(cc);
// get real class name
final String className = cc.className();
cfs.setExpectedClassName(className);
} catch (IOException ex) {
//@olsen: support for I18N
throw new UserException(
getI18N("enhancer.io_error_while_reading_stream"),//NOI18N
ex);
} catch (ClassFormatError ex) {
//@olsen: support for I18N
throw new UserException(
getI18N("enhancer.class_format_error"),//NOI18N
ex);
}
// enhance class
econtrol.modifyClasses();
if (env.errorCount() > 0) {
// retrieve error messages
env.getErrorWriter ().flush ();
/*
final String str = errString.getBuffer().toString();
// reset env's error writer
errString = new StringWriter();
err = new PrintWriter(errString, true);
env.setErrorWriter(err);
*/
//@olsen: support for I18N
throw new UserException(env.getLastErrorMessage ());
}
// write class
boolean changed = (cc.updated() && cc.filterRequired());
try {
if (changed)
{
env.message("writing enhanced class " + cc.userClassName()//NOI18N
+ " to output stream");//NOI18N
}
else
{
env.message("no changes on class " + cc.userClassName());
}
outByteCode.setClassName (cc.userClassName ());
final DataOutputStream dos = new DataOutputStream(outByteCode.getStream ());
cf.write(dos);
dos.flush();
} catch (IOException ex) {
//@olsen: support for I18N
throw new UserException(
getI18N("enhancer.io_error_while_writing_stream"),//NOI18N