int read = 0;
while ((read = in.read(buf)) != -1) {
baos.write(buf, 0, read);
}
buf = baos.toByteArray();
JRubyClassLoader jcl = runtime.getJRubyClassLoader();
ClassReader cr = new ClassReader(buf);
String className = cr.getClassName().replace('/', '.');
Class clazz = null;
try {
clazz = jcl.loadClass(className);
} catch (ClassNotFoundException cnfe) {
clazz = jcl.defineClass(className, buf);
}
// if it's a compiled JRuby script, instantiate and run it
if (Script.class.isAssignableFrom(clazz)) {
Script script = (Script)clazz.newInstance();