Package org.jruby

Examples of org.jruby.RubyIO$ByteListCache


        }
    }

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


    @JRubyMethod(required = 1)
    public static IRubyObject initialize(IRubyObject recv, IRubyObject io) {
        try {
            if (io instanceof RubyIO) {
                RubyIO rubyIO = (RubyIO)io;
                OpenFile of = rubyIO.getOpenFile();
                Stream stream = of.getMainStreamSafe();
                if (stream instanceof ChannelStream) {
                    ChannelStream cStream = (ChannelStream)stream;
                    if (cStream.getDescriptor().getChannel() instanceof SelectableChannel)  {
                        SelectableChannel selChannel = (SelectableChannel)cStream.getDescriptor().getChannel();
View Full Code Here

        }
       
        @JRubyMethod
        public static IRubyObject rbuf_fill(IRubyObject recv) {
            RubyString buf = (RubyString)recv.getInstanceVariables().getInstanceVariable("@rbuf");
            RubyIO io = (RubyIO)recv.getInstanceVariables().getInstanceVariable("@io");

            int timeout = RubyNumeric.fix2int(recv.getInstanceVariables().getInstanceVariable("@read_timeout")) * 1000;
            NativeImpl nim = (NativeImpl)recv.dataGetStruct();

            Selector selector = null;
            synchronized (nim.channel.blockingLock()) {
                boolean oldBlocking = nim.channel.isBlocking();

                try {
                    selector = SelectorFactory.openWithRetryFrom(recv.getRuntime(), SelectorProvider.provider());
                    nim.channel.configureBlocking(false);
                    SelectionKey key = nim.channel.register(selector, SelectionKey.OP_READ);
                    int n = selector.select(timeout);

                    if(n > 0) {
                        IRubyObject readItems = io.read(new IRubyObject[]{recv.getRuntime().newFixnum(1024*16)});
                        return buf.concat(readItems);
                    } else {
                        RubyClass exc = (RubyClass)(recv.getRuntime().getModule("Timeout").getConstant("Error"));
                        throw new RaiseException(RubyException.newException(recv.getRuntime(), exc, "execution expired"),false);
                    }
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;
        Ruby runtime = context.getRuntime();

        try {
            io.getOpenFile().checkReadable(context.getRuntime());
        } catch (IOException ex) {
            throw runtime.newIOErrorFromException(ex);
        } catch (BadDescriptorException ex) {
            throw runtime.newErrnoEBADFError();
        } catch (InvalidValueException e) {
            throw runtime.newErrnoEINVALError();
        }
       
        return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), io.getInStream());
    }
View Full Code Here

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

        try {
            io.getOpenFile().checkWritable(context.getRuntime());
        } catch (IOException ex) {
            throw runtime.newIOErrorFromException(ex);
        } catch (BadDescriptorException ex) {
            throw runtime.newErrnoEBADFError();
        } catch (InvalidValueException e) {
            throw runtime.newErrnoEINVALError();
        }
       
        return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), io.getOutStream());
    }
View Full Code Here

        return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), io.getOutStream());
    }

    @JRubyMethod
    public static IRubyObject to_channel(ThreadContext context, IRubyObject self) {
        RubyIO io = (RubyIO)self;

        return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), io.getChannel());
    }
View Full Code Here

        runtime.getGlobalVariables().set("$defout", value);
    }
   
    private void setWriterOutputStream(Writer writer) {
        try {
            RubyIO dummy_io =
                new RubyIO(runtime, new PrintStream(new WriterOutputStream(new StringWriter())));
            runtime.getGlobalVariables().set("$stderr", dummy_io); //discard unwanted warnings
            RubyIO io =
                new RubyIO(runtime, new PrintStream(new WriterOutputStream(writer)));
            io.getOpenFile().getMainStream().setSync(true);
            runtime.defineGlobalConstant("STDOUT", io);
            runtime.getGlobalVariables().set("$>", io);
            runtime.getGlobalVariables().set("$stdout", io);
            runtime.getGlobalVariables().set("$defout", io);
        } catch (UnsupportedEncodingException exp) {
View Full Code Here

        }
    }
   
    private void setErrorWriter(Writer writer) {
        try {
            RubyIO dummy_io =
                new RubyIO(runtime, new PrintStream(new WriterOutputStream(new StringWriter())));
            runtime.getGlobalVariables().set("$stderr", dummy_io); //discard unwanted warnings
            RubyIO io =
                new RubyIO(runtime, new PrintStream(new WriterOutputStream(writer)));
            io.getOpenFile().getMainStream().setSync(true);
            runtime.defineGlobalConstant("STDERR", io);
            runtime.getGlobalVariables().set("$stderr", io);
            runtime.getGlobalVariables().set("$deferr", io);
        } catch (UnsupportedEncodingException exp) {
            throw new IllegalArgumentException(exp);
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));
        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));
        runtime.getObject().storeConstant("STDERR", io);
        runtime.getGlobalVariables().alias("$deferr", "$stderr");
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyIO$ByteListCache

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.