Package org.jruby

Examples of org.jruby.RubyIO$Ruby19POpen


    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


    }   

    @JRubyMethod(required = 1, visibility = Visibility.PRIVATE)
    public static IRubyObject initialize(IRubyObject recv, IRubyObject io) {
        if (io instanceof RubyIO) {
            RubyIO rubyIO = (RubyIO)io;
            OpenFile of = rubyIO.getOpenFile();
            if (of.selectChannel() != null)  {
                SelectableChannel selChannel = of.selectChannel();

                ((RubyObject)recv).extend(
                        new IRubyObject[]{((RubyModule)recv.getRuntime().getModule("Net").getConstant("BufferedIO")).getConstant("NativeImplementation")});
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().setSync(true);
        runtime.defineVariable(new InputGlobalVariable(runtime, "$stdin", io), GlobalVariable.Scope.GLOBAL);
        runtime.getObject().storeConstant("STDIN", io);
    }
View Full Code Here

            }
        }
        map.put(AttributeName.WRITER, writer);
       
        Ruby runtime = container.getProvider().getRuntime();
        RubyIO io = getRubyIO(runtime, writer);
        runtime.defineVariable(new OutputGlobalVariable(runtime, "$stdout", io), GlobalVariable.Scope.GLOBAL);
        runtime.getObject().storeConstant("STDOUT", io);
        runtime.getGlobalVariables().alias("$>", "$stdout");
        runtime.getGlobalVariables().alias("$defout", "$stdout");
    }
View Full Code Here

            }
        }
        map.put(AttributeName.ERROR_WRITER, writer);
       
        Ruby runtime = container.getProvider().getRuntime();
        RubyIO io = getRubyIO(runtime, writer);
        runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", io), GlobalVariable.Scope. GLOBAL);
        runtime.getObject().storeConstant("STDERR", io);
        runtime.getGlobalVariables().alias("$deferr", "$stderr");
    }
View Full Code Here

        runtime.getGlobalVariables().alias("$deferr", "$stderr");
    }
   
    private static RubyIO getRubyIO(Ruby runtime, Writer writer) throws IOException, BadDescriptorException {
        PrintStream pstream = new PrintStream(new WriterOutputStream(writer), true);
        RubyIO io = new RubyIO(runtime, pstream, false);
        boolean locked = io.getOpenFile().lock();
        try {
            io.getOpenFile().setSync(true);
            io.getOpenFile().io_fflush(runtime.getCurrentContext());
            return io;
        } finally {
            if (locked) io.getOpenFile().unlock();
        }
    }
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().setSync(true);
        runtime.defineVariable(new OutputGlobalVariable(runtime, "$stdout", io), GlobalVariable.Scope.GLOBAL);
        runtime.getObject().storeConstant("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().setSync(true);
        runtime.defineVariable(new OutputGlobalVariable(runtime, "$stderr", io), GlobalVariable.Scope.GLOBAL);
        runtime.getObject().storeConstant("STDERR", io);
        runtime.getGlobalVariables().alias("$deferr", "$stderr");
    }
View Full Code Here

    // IOInput/OutputStream or is smart about the kind of IO-like object
    // it's being used against.
   
    @JRubyMethod
    public static IRubyObject to_inputstream(ThreadContext context, IRubyObject self) {
        RubyIO io = (RubyIO)self;

        io.getOpenFile().checkReadable(context);

        return JavaUtil.convertJavaToUsableRubyObject(context.runtime, io.getInStream());
    }
View Full Code Here

        return JavaUtil.convertJavaToUsableRubyObject(context.runtime, io.getInStream());
    }
   
    @JRubyMethod
    public static IRubyObject to_outputstream(ThreadContext context, IRubyObject self) {
        RubyIO io = (RubyIO)self;

        io.getOpenFile().checkWritable(context);

        return JavaUtil.convertJavaToUsableRubyObject(context.runtime, io.getOutStream());
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyIO$Ruby19POpen

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.