try {
if (runtime.getSafeLevel() >= 4 && isTaint()) {
throw runtime.newSecurityError("Insecure: can't close");
}
OpenFile myOpenFile = getOpenFileChecked();
if (myOpenFile.getPipeStream() == null && myOpenFile.isWritable()) {
throw runtime.newIOError("closing non-duplex IO for reading");
}
if (myOpenFile.getPipeStream() == null) {
close();
} else{
myOpenFile.getMainStream().fclose();
myOpenFile.setMode(myOpenFile.getMode() & ~OpenFile.READABLE);
myOpenFile.setMainStream(myOpenFile.getPipeStream());
myOpenFile.setPipeStream(null);
// TODO
// n is result of fclose; but perhaps having a SysError below is enough?
// if (n != 0) rb_sys_fail(fptr->path);
}
} catch (IOException ioe) {