public static IRubyObject putc(ThreadContext context, IRubyObject maybeIO, IRubyObject object) { int c = RubyNumeric.num2chr(object); if (maybeIO instanceof RubyIO) { // FIXME we should probably still be dyncalling 'write' here RubyIO io = (RubyIO)maybeIO; try { OpenFile myOpenFile = io.getOpenFileChecked(); myOpenFile.checkWritable(context.runtime); Stream writeStream = myOpenFile.getWriteStream(); writeStream.fputc(c); if (myOpenFile.isSync()) myOpenFile.fflush(writeStream); } catch (IOException ex) { throw context.runtime.newIOErrorFromException(ex); } catch (BadDescriptorException e) { throw context.runtime.newErrnoEBADFError(); } catch (InvalidValueException ex) { throw context.runtime.newErrnoEINVALError(); } } else { maybeIO.callMethod(context, "write", RubyString.newStringNoCopy(context.runtime, new byte[] {(byte)c})); } return object; }
public static IRubyObject putc(ThreadContext context, IRubyObject maybeIO, IRubyObject object) { int c = RubyNumeric.num2chr(object); if (maybeIO instanceof RubyIO) { // FIXME we should probably still be dyncalling 'write' here RubyIO io = (RubyIO)maybeIO; try { OpenFile myOpenFile = io.getOpenFileChecked(); myOpenFile.checkWritable(context.runtime); Stream writeStream = myOpenFile.getWriteStream(); writeStream.fputc(c); if (myOpenFile.isSync()) myOpenFile.fflush(writeStream); } catch (IOException ex) { throw context.runtime.newIOErrorFromException(ex); } catch (BadDescriptorException e) { throw context.runtime.newErrnoEBADFError(); } catch (InvalidValueException ex) { throw context.runtime.newErrnoEINVALError(); } } else { maybeIO.callMethod(context, "write", RubyString.newStringNoCopy(context.runtime, new byte[] {(byte)c})); } return object; }