Package org.jruby.util.io

Examples of org.jruby.util.io.ChannelDescriptor


                } else {
                    modes = originalFile.getMainStream().getModes();
                }
            }
           
            ChannelDescriptor descriptor = originalFile.getMainStream().getDescriptor().dup();

            newFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, modes));
           
            // TODO: the rest of this...seeking to same position is unnecessary since we share a channel
            // but some of this may be needed?
View Full Code Here


        if (openFile == null) return runtime.getNil();
       
        // These would be used when we notify threads...if we notify threads
        interruptBlockingThreads();
       
        ChannelDescriptor main, pipe;
        if (openFile.getPipeStream() != null) {
            pipe = openFile.getPipeStream().getDescriptor();
        } else {
            if (openFile.getMainStream() == null) {
                return runtime.getNil();
View Full Code Here

    public static IRubyObject copy_stream(ThreadContext context, IRubyObject recv,
            IRubyObject stream1, IRubyObject stream2) throws IOException {
        RubyIO io1 = (RubyIO)stream1;
        RubyIO io2 = (RubyIO)stream2;

        ChannelDescriptor d1 = io1.openFile.getMainStream().getDescriptor();
        if (!d1.isSeekable()) {
            throw context.getRuntime().newTypeError("only supports file-to-file copy");
        }
        ChannelDescriptor d2 = io2.openFile.getMainStream().getDescriptor();
        if (!d2.isSeekable()) {
            throw context.getRuntime().newTypeError("only supports file-to-file copy");
        }

        FileChannel f1 = (FileChannel)d1.getChannel();
        FileChannel f2 = (FileChannel)d2.getChannel();

        long size = f1.size();

        f1.transferTo(f2.position(), size, f2);
View Full Code Here

    @JRubyMethod(name = "ready?")
    public static IRubyObject ready(ThreadContext context, IRubyObject obj) {
        RubyIO io = (RubyIO)obj;
        try {
            OpenFile openFile = io.getOpenFile();
            ChannelDescriptor descriptor = openFile.getMainStream().getDescriptor();
            if (!descriptor.isOpen() || !openFile.getMainStream().getModes().isReadable() || openFile.getMainStream().feof()) {
                return context.getRuntime().getFalse();
            }

            int avail = openFile.getMainStream().ready();
            if (avail > 0) {
View Full Code Here

    @JRubyMethod
    public static IRubyObject io_wait(ThreadContext context, IRubyObject obj) {
        RubyIO io = (RubyIO)obj;
        try {
            OpenFile openFile = io.getOpenFile();
            ChannelDescriptor descriptor = openFile.getMainStream().getDescriptor();
            if (openFile.getMainStream().feof()) {
                return context.getRuntime().getNil();
            }
            openFile.getMainStream().waitUntilReady();
        } catch (Exception anyEx) {
View Full Code Here

    @JRubyMethod(name = "ready?")
    public static IRubyObject ready(ThreadContext context, IRubyObject obj) {
        RubyIO io = (RubyIO)obj;
        try {
            OpenFile openFile = io.getOpenFile();
            ChannelDescriptor descriptor = openFile.getMainStreamSafe().getDescriptor();
            if (!descriptor.isOpen() || !openFile.getMainStreamSafe().getModes().isReadable() || openFile.getMainStreamSafe().feof()) {
                return context.getRuntime().getFalse();
            }

            int avail = openFile.getMainStreamSafe().ready();
            if (avail > 0) {
View Full Code Here

        }
       
        openFile = new OpenFile();
       
        try {
            openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(outputStream))));
        } catch (InvalidValueException e) {
            throw getRuntime().newErrnoEINVALError();
        }
       
        openFile.setMode(OpenFile.WRITABLE | OpenFile.APPEND);
View Full Code Here

        }
       
        openFile = new OpenFile();
       
        try {
            openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(inputStream))));
        } catch (InvalidValueException e) {
            throw getRuntime().newErrnoEINVALError();
        }
       
        openFile.setMode(OpenFile.READABLE);
View Full Code Here

        }
       
        openFile = new OpenFile();
       
        try {
            openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(channel)));
        } catch (InvalidValueException e) {
            throw getRuntime().newErrnoEINVALError();
        }
       
        openFile.setMode(openFile.getMainStream().getModes().getOpenFileFlags());
View Full Code Here

                } else {
                    // Stream-based
                    inChannel = Channels.newChannel(process.getInputStream());
                }
               
                ChannelDescriptor main = new ChannelDescriptor(
                        inChannel);
                main.setCanBeSeekable(false);
               
                openFile.setMainStream(ChannelStream.open(getRuntime(), main));
            }
           
            if (openFile.isWritable() && process.hasOutput()) {
                Channel outChannel;
                if (process.getOutput() != null) {
                    // NIO-based
                    outChannel = process.getOutput();
                } else {
                    outChannel = Channels.newChannel(process.getOutputStream());
                }

                ChannelDescriptor pipe = new ChannelDescriptor(
                        outChannel);
                pipe.setCanBeSeekable(false);
               
                if (openFile.getMainStream() != null) {
                    openFile.setPipeStream(ChannelStream.open(getRuntime(), pipe));
                } else {
                    openFile.setMainStream(ChannelStream.open(getRuntime(), pipe));
View Full Code Here

TOP

Related Classes of org.jruby.util.io.ChannelDescriptor

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.