@JRubyMethod(name = {"to_input_stream", "to_inputstream"}) public static IRubyObject to_inputstream(ThreadContext context, IRubyObject self) { RubyIO io = (RubyIO) self; io.getOpenFile().checkReadable(context); return JavaUtil.convertJavaToUsableRubyObject(context.runtime, io.getInStream()); }
@JRubyMethod(name = {"to_input_stream", "to_inputstream"}) public static IRubyObject to_inputstream(ThreadContext context, IRubyObject self) { RubyIO io = (RubyIO) self; io.getOpenFile().checkReadable(context); return JavaUtil.convertJavaToUsableRubyObject(context.runtime, io.getInStream()); }
@JRubyMethod(optional = 1) public static IRubyObject wait_readable(ThreadContext context, IRubyObject _io, IRubyObject[] argv) { RubyIO io = (RubyIO)_io; OpenFile fptr = io.getOpenFileChecked(); fptr.checkReadable(context); long tv = prepareTimeout(context, argv); if (fptr.readPending() != 0) return context.tru; return doWait(context, io, fptr, tv, SelectionKey.OP_READ | SelectionKey.OP_ACCEPT); }
@JRubyMethod(optional = 1) public static IRubyObject wait_readable(ThreadContext context, IRubyObject _io, IRubyObject[] argv) { RubyIO io = (RubyIO)_io; OpenFile fptr = io.getOpenFileChecked(); fptr.checkReadable(context); long tv = prepareTimeout(context, argv); if (fptr.readPending() != 0) return context.tru; return doWait(context, io, fptr, tv, SelectionKey.OP_READ | SelectionKey.OP_ACCEPT); }
@Override public <T> T toJava(Class<T> target) { if (target == java.io.InputStream.class) { getOpenFile().checkReadable(getRuntime().getCurrentContext()); return target.cast(getInStream()); } if (target == java.io.OutputStream.class) { getOpenFile().checkWritable(getRuntime().getCurrentContext()); return target.cast(getOutStream()); } return super.toJava(target); }
@Override public <T> T toJava(Class<T> target) { if (target == java.io.InputStream.class) { getOpenFile().checkReadable(getRuntime().getCurrentContext()); return target.cast(getInStream()); } if (target == java.io.OutputStream.class) { getOpenFile().checkWritable(getRuntime().getCurrentContext()); return target.cast(getOutStream()); } return super.toJava(target); }
@JRubyMethod public static IRubyObject nread(ThreadContext context, IRubyObject _io) { Ruby runtime = context.runtime; OpenFile fptr; int len; // ioctl_arg n; RubyIO io = (RubyIO)_io; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); len = fptr.readPending(); if (len > 0) return runtime.newFixnum(len); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0); // if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0); // if (n > 0) return ioctl_arg2num(n); // Because we can't get an actual system-level buffer available count, we fake it by returning 1 if ready return RubyNumeric.int2fix(runtime, fptr.readyNow(context) ? 1 : 0); }
/** * returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil. */ @JRubyMethod(name = "ready?") public static IRubyObject ready(ThreadContext context, IRubyObject _io) { RubyIO io = (RubyIO)_io; Ruby runtime = context.runtime; OpenFile fptr; // ioctl_arg n; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); if (fptr.readPending() != 0) return runtime.getTrue(); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil; // if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil; // if (n > 0) return Qtrue; return runtime.newBoolean(fptr.readyNow(context)); }
@JRubyMethod public static IRubyObject nread(ThreadContext context, IRubyObject _io) { Ruby runtime = context.runtime; OpenFile fptr; int len; // ioctl_arg n; RubyIO io = (RubyIO)_io; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); len = fptr.readPending(); if (len > 0) return runtime.newFixnum(len); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return INT2FIX(0); // if (ioctl(fptr->fd, FIONREAD, &n)) return INT2FIX(0); // if (n > 0) return ioctl_arg2num(n); // Because we can't get an actual system-level buffer available count, we fake it by returning 1 if ready return RubyNumeric.int2fix(runtime, fptr.readyNow(context) ? 1 : 0); }
/** * returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil. */ @JRubyMethod(name = "ready?") public static IRubyObject ready(ThreadContext context, IRubyObject _io) { RubyIO io = (RubyIO)_io; Ruby runtime = context.runtime; OpenFile fptr; // ioctl_arg n; fptr = io.getOpenFileChecked(); fptr.checkReadable(context); if (fptr.readPending() != 0) return runtime.getTrue(); // TODO: better effort to get available bytes from our channel // if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qnil; // if (ioctl(fptr->fd, FIONREAD, &n)) return Qnil; // if (n > 0) return Qtrue; return runtime.newBoolean(fptr.readyNow(context)); }
@JRubyMethod public static IRubyObject to_inputstream(ThreadContext context, IRubyObject self) { RubyIO io = (RubyIO)self; Ruby runtime = context.runtime; try { io.getOpenFile().checkReadable(context.runtime); } catch (IOException ex) { throw runtime.newIOErrorFromException(ex); } catch (BadDescriptorException ex) { throw runtime.newErrnoEBADFError(); } catch (InvalidValueException e) { throw runtime.newErrnoEINVALError(); } return JavaUtil.convertJavaToUsableRubyObject(context.runtime, io.getInStream()); }
@JRubyMethod public static IRubyObject to_inputstream(ThreadContext context, IRubyObject self) { RubyIO io = (RubyIO)self; Ruby runtime = context.runtime; try { io.getOpenFile().checkReadable(context.runtime); } catch (IOException ex) { throw runtime.newIOErrorFromException(ex); } catch (BadDescriptorException ex) { throw runtime.newErrnoEBADFError(); } catch (InvalidValueException e) { throw runtime.newErrnoEINVALError(); } return JavaUtil.convertJavaToUsableRubyObject(context.runtime, io.getInStream()); }
@JRubyMethod(name = "read") public IRubyObject read(ThreadContext context) { Ruby runtime = context.runtime; OpenFile myOpenFile = getOpenFileChecked(); try { myOpenFile.checkReadable(runtime); myOpenFile.setReadBuffered(); return readAll(context); } catch (InvalidValueException ex) { throw getRuntime().newErrnoEINVALError(); } catch (EOFException ex) { throw getRuntime().newEOFError(); } catch (IOException ex) { throw getRuntime().newIOErrorFromException(ex); } catch (BadDescriptorException ex) { throw getRuntime().newErrnoEBADFError(); } }
@JRubyMethod(name = "read") public IRubyObject read(ThreadContext context) { Ruby runtime = context.runtime; OpenFile myOpenFile = getOpenFileChecked(); try { myOpenFile.checkReadable(runtime); myOpenFile.setReadBuffered(); return readAll(context); } catch (InvalidValueException ex) { throw getRuntime().newErrnoEINVALError(); } catch (EOFException ex) { throw getRuntime().newEOFError(); } catch (IOException ex) { throw getRuntime().newIOErrorFromException(ex); } catch (BadDescriptorException ex) { throw getRuntime().newErrnoEBADFError(); } }
@JRubyMethod(name = "getc", compat = RUBY1_9) public IRubyObject getc19(ThreadContext context) { try { OpenFile myOpenFile = getOpenFileChecked(); myOpenFile.checkReadable(context.runtime); myOpenFile.setReadBuffered(); Stream stream = myOpenFile.getMainStreamSafe(); readCheck(stream); waitReadable(stream); stream.clearerr(); return ioGetc(context, stream); } catch (InvalidValueException ex) { throw context.runtime.newErrnoEINVALError(); } catch (BadDescriptorException e) { throw context.runtime.newErrnoEBADFError(); } catch (EOFException e) { throw context.runtime.newEOFError(); } catch (IOException e) { throw context.runtime.newIOErrorFromException(e); } }
@JRubyMethod(name = "getc", compat = RUBY1_9) public IRubyObject getc19(ThreadContext context) { try { OpenFile myOpenFile = getOpenFileChecked(); myOpenFile.checkReadable(context.runtime); myOpenFile.setReadBuffered(); Stream stream = myOpenFile.getMainStreamSafe(); readCheck(stream); waitReadable(stream); stream.clearerr(); return ioGetc(context, stream); } catch (InvalidValueException ex) { throw context.runtime.newErrnoEINVALError(); } catch (BadDescriptorException e) { throw context.runtime.newErrnoEBADFError(); } catch (EOFException e) { throw context.runtime.newEOFError(); } catch (IOException e) { throw context.runtime.newIOErrorFromException(e); } }
public void ungetcCommon(int ch) { try { OpenFile myOpenFile = getOpenFileChecked(); myOpenFile.checkReadable(getRuntime()); myOpenFile.setReadBuffered(); if (myOpenFile.getMainStreamSafe().ungetc(ch) == -1 && ch != -1) { throw getRuntime().newIOError("ungetc failed"); } } catch (InvalidValueException ex) { throw getRuntime().newErrnoEINVALError(); } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } catch (EOFException e) { throw getRuntime().newEOFError(); } catch (IOException e) { throw getRuntime().newIOErrorFromException(e); } }
public void ungetcCommon(int ch) { try { OpenFile myOpenFile = getOpenFileChecked(); myOpenFile.checkReadable(getRuntime()); myOpenFile.setReadBuffered(); if (myOpenFile.getMainStreamSafe().ungetc(ch) == -1 && ch != -1) { throw getRuntime().newIOError("ungetc failed"); } } catch (InvalidValueException ex) { throw getRuntime().newErrnoEINVALError(); } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } catch (EOFException e) { throw getRuntime().newEOFError(); } catch (IOException e) { throw getRuntime().newIOErrorFromException(e); } }
public int getcCommon() { try { OpenFile myOpenFile = getOpenFileChecked(); myOpenFile.checkReadable(getRuntime()); myOpenFile.setReadBuffered(); Stream stream = myOpenFile.getMainStreamSafe(); readCheck(stream); waitReadable(stream); stream.clearerr(); return myOpenFile.getMainStreamSafe().fgetc(); } catch (InvalidValueException ex) { throw getRuntime().newErrnoEINVALError(); } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } catch (EOFException e) { throw getRuntime().newEOFError(); } catch (IOException e) { throw getRuntime().newIOErrorFromException(e); } }
public int getcCommon() { try { OpenFile myOpenFile = getOpenFileChecked(); myOpenFile.checkReadable(getRuntime()); myOpenFile.setReadBuffered(); Stream stream = myOpenFile.getMainStreamSafe(); readCheck(stream); waitReadable(stream); stream.clearerr(); return myOpenFile.getMainStreamSafe().fgetc(); } catch (InvalidValueException ex) { throw getRuntime().newErrnoEINVALError(); } catch (BadDescriptorException e) { throw getRuntime().newErrnoEBADFError(); } catch (EOFException e) { throw getRuntime().newEOFError(); } catch (IOException e) { throw getRuntime().newIOErrorFromException(e); } }