Package org.jruby

Examples of org.jruby.RubyIO


    /**
     * waits until input available or timed out and returns self, or nil when EOF reached.
     */
    @JRubyMethod
    public static IRubyObject io_wait(ThreadContext context, IRubyObject obj) {
        RubyIO io = (RubyIO)obj;
        try {
            OpenFile openFile = io.getOpenFile();
            if (openFile.getMainStreamSafe().feof()) {
                return context.getRuntime().getNil();
            }
            openFile.getMainStreamSafe().waitUntilReady();
        } catch (BadDescriptorException e) {
View Full Code Here


     * @see #hookIntoRuntime(Ruby)
     */
    public void hookIntoRuntimeWithStreams(final Ruby runtime) {
        hookIntoRuntime(runtime);

        RubyIO in = new RubyIO(runtime, getInputStream());
        runtime.getGlobalVariables().set("$stdin", in);

        RubyIO out = new RubyIO(runtime, getOutputStream());
        runtime.getGlobalVariables().set("$stdout", out);
        runtime.getGlobalVariables().set("$stderr", out);
    }
View Full Code Here

    public void testPrintErrorWithStringBacktrace() throws Exception {
        testPrintErrorWithBacktrace("\"abc\"");
    }
   
    private void testPrintErrorWithBacktrace(String backtrace) throws Exception {
        RubyIO oldStderr = (RubyIO)runtime.getGlobalVariables().get("$stderr");
        try {
            ByteArrayOutputStream stderrOutput = new ByteArrayOutputStream();
            RubyIO newStderr = new RubyIO(runtime, stderrOutput);
            runtime.getGlobalVariables().set("$stderr", newStderr);
           
            try {
                eval("class MyError < StandardError ; def backtrace ; " + backtrace + " ; end ; end ; raise MyError.new ");
                fail("Expected MyError to be raised");
View Full Code Here

     * @return the value printed out on  stdout and stderr by
     **/
    protected String eval(String script) throws Exception {
        ByteArrayOutputStream result = new ByteArrayOutputStream();
        out = new PrintStream(result);
        RubyIO lStream = new RubyIO(runtime, out);
        runtime.getGlobalVariables().set("$stdout", lStream);
        runtime.getGlobalVariables().set("$>", lStream);
        runtime.getGlobalVariables().set("$stderr", lStream);
       
        runtime.runNormally(
View Full Code Here

            }
        }
        map.put(AttributeName.READER, reader);
        InputStream istream = new ReaderInputStream(reader);
        Ruby runtime = provider.getRuntime();
        RubyIO io = new RubyIO(runtime, istream);
        io.getOpenFile().getMainStream().setSync(true);
        runtime.defineVariable(new InputGlobalVariable(runtime, "$stdin", io));
        runtime.getObject().getConstantMapForWrite().put("STDIN", io);
    }
View Full Code Here

    private void setOutputStream(PrintStream pstream) {
        if (pstream == null) {
            return;
        }
        Ruby runtime = provider.getRuntime();
        RubyIO io = new RubyIO(runtime, pstream);
        io.getOpenFile().getMainStream().setSync(true);
        runtime.defineVariable(new OutputGlobalVariable(runtime, "$stdout", io));
        runtime.getObject().getConstantMapForWrite().put("STDOUT", io);
        runtime.getGlobalVariables().alias("$>", "$stdout");
        runtime.getGlobalVariables().alias("$defout", "$stdout");
    }
View Full Code Here

    private void setErrorStream(PrintStream error) {
        if (error == null) {
            return;
        }
        Ruby runtime = provider.getRuntime();
        RubyIO io = new RubyIO(runtime, error);
        io.getOpenFile().getMainStream().setSync(true);
        runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", io));
        runtime.getObject().getConstantMapForWrite().put("STDERR", io);
        runtime.getGlobalVariables().alias("$deferr", "$stderr");
    }
View Full Code Here

                // clear reference; we aren't going to do anything
                readArray = null;
            } else {
                readIOs = new RubyIO[readSize];
                for (int i = 0; i < readSize; i++) {
                    RubyIO ioObj = saveReadIO(i, context);
                    saveReadBlocking(ioObj, i);
                    saveBufferedRead(ioObj, i);
                    trySelectRead(context, i, ioObj);
                }
            }
View Full Code Here

        }
    }

    private RubyIO saveReadIO(int i, ThreadContext context) {
        IRubyObject obj = readArray.eltOk(i);
        RubyIO ioObj = RubyIO.convertToIO(context, obj);
        readIOs[i] = ioObj;
        return ioObj;
    }
View Full Code Here

                // clear reference; we aren't going to do anything
                writeArray = null;
            } else {
                writeIOs = new RubyIO[writeSize];
                for (int i = 0; i < writeSize; i++) {
                    RubyIO ioObj = saveWriteIO(i, context);
                    saveWriteBlocking(ioObj, i);
                    trySelectWrite(context, i, ioObj);
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.jruby.RubyIO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.