File dir = env instanceof File ? (File) env : null;
final File classFile = new File(dir, filename);
// find the error stream
HeaderPrintWriter errorStream = Monitor.getStream();
try {
FileOutputStream fis;
try {
fis = AccessController.doPrivileged(
new PrivilegedExceptionAction<FileOutputStream>() {
public FileOutputStream run() throws IOException {
return new FileOutputStream(classFile);
}
});
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getCause();
}
fis.write(bytecode.getArray(),
bytecode.getOffset(), bytecode.getLength());
fis.flush();
if (t!=null) {
errorStream.printlnWithHeader(MessageService.getTextMessage(MessageId.CM_WROTE_CLASS_FILE, fullyQualifiedName, classFile, t));
}
fis.close();
} catch (IOException e) {
if (SanityManager.DEBUG)
SanityManager.THROWASSERT("Unable to write .class file", e);