@Override public String toString() { return "RubyFile(" + openFile.getPath() + ", " + openFile.getMode() + ')'; }
@Override public String toString() { return "RubyFile(" + openFile.getPath() + ", " + openFile.getMode() + ')'; }
private IRubyObject closeHalf(ThreadContext context, int closeHalf) { OpenFile fptr; int otherHalf = closeHalf == OpenFile.READABLE ? OpenFile.WRITABLE : OpenFile.READABLE; fptr = getOpenFileChecked(); if ((fptr.getMode() & otherHalf) == 0) { // shutdown fully return rbIoClose(context); } // shutdown half int how = closeHalf == OpenFile.READABLE ? 0 : 1; shutdownInternal(context, fptr, how); return context.nil; }
private IRubyObject closeHalf(ThreadContext context, int closeHalf) { OpenFile fptr; int otherHalf = closeHalf == OpenFile.READABLE ? OpenFile.WRITABLE : OpenFile.READABLE; fptr = getOpenFileChecked(); if ((fptr.getMode() & otherHalf) == 0) { // shutdown fully return rbIoClose(context); } // shutdown half int how = closeHalf == OpenFile.READABLE ? 0 : 1; shutdownInternal(context, fptr, how); return context.nil; }
final long getSize(ThreadContext context) { OpenFile fptr = getOpenFileChecked(); if ((fptr.getMode() & OpenFile.WRITABLE) != 0) { flushRaw(context, false); } return fptr.posix.size(fptr.fd()); }
final long getSize(ThreadContext context) { OpenFile fptr = getOpenFileChecked(); if ((fptr.getMode() & OpenFile.WRITABLE) != 0) { flushRaw(context, false); } return fptr.posix.size(fptr.fd()); }
private void trySelectWrite(ThreadContext context, Map<Character,Integer> attachment, RubyIO ioObj) throws IOException { if (!(ioObj.getChannel() instanceof SelectableChannel) || !registerSelect(context, getSelector(context, (SelectableChannel)ioObj.getChannel()), attachment, ioObj, SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT)) { selectedReads++; if ((ioObj.getOpenFile().getMode() & OpenFile.WRITABLE) != 0) { getUnselectableWrites()[(Integer)attachment.get('w')] = true; } } }
private void trySelectWrite(ThreadContext context, Map<Character,Integer> attachment, RubyIO ioObj) throws IOException { if (!(ioObj.getChannel() instanceof SelectableChannel) || !registerSelect(context, getSelector(context, (SelectableChannel)ioObj.getChannel()), attachment, ioObj, SelectionKey.OP_WRITE | SelectionKey.OP_CONNECT)) { selectedReads++; if ((ioObj.getOpenFile().getMode() & OpenFile.WRITABLE) != 0) { getUnselectableWrites()[(Integer)attachment.get('w')] = true; } } }
private void trySelectRead(ThreadContext context, Map<Character,Integer> attachment, RubyIO ioObj) throws IOException { if (ioObj.getChannel() instanceof SelectableChannel && registerSelect(context, getSelector(context, (SelectableChannel)ioObj.getChannel()), attachment, ioObj, SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) { selectedReads++; if (ioObj.writeDataBuffered()) { getPendingReads()[(Integer)attachment.get('r')] = true; } } else { if ((ioObj.getOpenFile().getMode() & OpenFile.READABLE) != 0) { getUnselectableReads()[(Integer)attachment.get('r')] = true; } } }
private void trySelectRead(ThreadContext context, Map<Character,Integer> attachment, RubyIO ioObj) throws IOException { if (ioObj.getChannel() instanceof SelectableChannel && registerSelect(context, getSelector(context, (SelectableChannel)ioObj.getChannel()), attachment, ioObj, SelectionKey.OP_READ | SelectionKey.OP_ACCEPT)) { selectedReads++; if (ioObj.writeDataBuffered()) { getPendingReads()[(Integer)attachment.get('r')] = true; } } else { if ((ioObj.getOpenFile().getMode() & OpenFile.READABLE) != 0) { getUnselectableReads()[(Integer)attachment.get('r')] = true; } } }
@JRubyMethod(name = {"path", "to_path"}) public IRubyObject path(ThreadContext context) { if ((openFile.getMode() & OpenFile.TMPFILE) != 0) { throw context.runtime.newIOError("File is unnamed (TMPFILE?)"); } final String path = getPath(); if (path != null) { RubyString newPath = context.runtime.newString(path); newPath.setTaint(true); return newPath; } return context.nil; }
@JRubyMethod(name = {"path", "to_path"}) public IRubyObject path(ThreadContext context) { if ((openFile.getMode() & OpenFile.TMPFILE) != 0) { throw context.runtime.newIOError("File is unnamed (TMPFILE?)"); } final String path = getPath(); if (path != null) { RubyString newPath = context.runtime.newString(path); newPath.setTaint(true); return newPath; } return context.nil; }
@Override public String toString() { try { return "RubyFile(" + path + ", " + openFile.getMode() + ", " + getRuntime().getFileno(openFile.getMainStreamSafe().getDescriptor()) + ")"; } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } }
@Override public String toString() { try { return "RubyFile(" + path + ", " + openFile.getMode() + ", " + getRuntime().getFileno(openFile.getMainStreamSafe().getDescriptor()) + ")"; } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } }
@Override public String toString() { try { return "RubyIO(" + openFile.getMode() + ", " + getRuntime().getFileno(openFile.getMainStreamSafe().getDescriptor()) + ")"; } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } }
@Override public String toString() { try { return "RubyIO(" + openFile.getMode() + ", " + getRuntime().getFileno(openFile.getMainStreamSafe().getDescriptor()) + ")"; } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } }
/** Returns the current sync mode. * * MRI: rb_io_sync * * @return the current sync mode. */ @JRubyMethod public RubyBoolean sync(ThreadContext context) { Ruby runtime = context.runtime; OpenFile fptr; RubyIO io = GetWriteIO(); fptr = io.getOpenFileChecked(); fptr.lock(); try { return (fptr.getMode() & OpenFile.SYNC) != 0 ? runtime.getTrue() : runtime.getFalse(); } finally { fptr.unlock(); } }
/** Returns the current sync mode. * * MRI: rb_io_sync * * @return the current sync mode. */ @JRubyMethod public RubyBoolean sync(ThreadContext context) { Ruby runtime = context.runtime; OpenFile fptr; RubyIO io = GetWriteIO(); fptr = io.getOpenFileChecked(); fptr.lock(); try { return (fptr.getMode() & OpenFile.SYNC) != 0 ? runtime.getTrue() : runtime.getFalse(); } finally { fptr.unlock(); } }
@JRubyMethod(name = "size", compat = RUBY1_9) public IRubyObject size(ThreadContext context) { Ruby runtime = context.runtime; if ((openFile.getMode() & OpenFile.WRITABLE) != 0) flush(); // FIXME: jnr-posix is calling _osf_close + throwing random native exceptions with weird paths. // Once these are fixed remove this full file stat path and go back to faster one. if (Platform.IS_WINDOWS) return runtime.newFileStat(path, false).size(); try { FileDescriptor fd = getOpenFileChecked().getMainStreamSafe().getDescriptor().getFileDescriptor(); FileStat stat = runtime.getPosix().fstat(fd); if (stat == null) throw runtime.newErrnoEACCESError(path); return runtime.newFixnum(stat.st_size()); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }
@JRubyMethod(name = "size", compat = RUBY1_9) public IRubyObject size(ThreadContext context) { Ruby runtime = context.runtime; if ((openFile.getMode() & OpenFile.WRITABLE) != 0) flush(); // FIXME: jnr-posix is calling _osf_close + throwing random native exceptions with weird paths. // Once these are fixed remove this full file stat path and go back to faster one. if (Platform.IS_WINDOWS) return runtime.newFileStat(path, false).size(); try { FileDescriptor fd = getOpenFileChecked().getMainStreamSafe().getDescriptor().getFileDescriptor(); FileStat stat = runtime.getPosix().fstat(fd); if (stat == null) throw runtime.newErrnoEACCESError(path); return runtime.newFixnum(stat.st_size()); } catch (BadDescriptorException e) { throw runtime.newErrnoEBADFError(); } }