*/
public void storeClassFile(ClassFile classFile, final File sourceFile) throws IOException {
String classFileResourceName = ClassFile.getClassFileResourceName(classFile.getThisClassName());
// Determine where to create the class file.
ResourceCreator rc;
if (this.classFileCreator != Compiler.CREATE_NEXT_TO_SOURCE_FILE) {
rc = this.classFileCreator;
} else {
// If the JAVAC option "-d" is given, place the class file next
// to the source file, irrespective of the package name.
rc = new FileResourceCreator() {
protected File getFile(String resourceName) {
return new File(
sourceFile.getParentFile(),
resourceName.substring(resourceName.lastIndexOf('/') + 1)
);
}
};
}
OutputStream os = rc.createResource(classFileResourceName);
try {
if (DEBUG) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
classFile.store(baos);
byte[] ba = baos.toByteArray();
System.out.println("*** Disassembly of class \"" + classFile.getThisClassName() + "\":");
try {
new Disassembler().disasm(new ByteArrayInputStream(ba));
System.out.flush();
} catch (IOException ex) {
throw new JaninoRuntimeException("SNO: IOException despite ByteArrayInputStream");
}
os.write(ba);
} else
{
classFile.store(os);
}
} catch (IOException ex) {
try { os.close(); } catch (IOException e) { }
os = null;
if (!rc.deleteResource(classFileResourceName)) {
throw new IOException(
"Could not delete incompletely written class file \""
+ classFileResourceName
+ "\""
);