Package org.jruby.util.io

Examples of org.jruby.util.io.ModeFlags


        runtime.checkSafeString(filename);
       
        path = adjustRootPathOnWindows(runtime, filename.getUnicodeValue(), runtime.getCurrentDirectory());
       
        String modeString;
        ModeFlags modes;
        int perm;
       
        try {
            if ((args.length > 1 && args[1] instanceof RubyFixnum) || (args.length > 2 && !args[2].isNil())) {
                modes = parseModes(args[1]);
View Full Code Here


    // TODO: This is also defined in the MetaClass too...Consolidate somewhere.
    private static ModeFlags getModes(Ruby runtime, IRubyObject object) throws InvalidValueException {
        if (object instanceof RubyString) {
            return getIOModes(runtime, ((RubyString) object).toString());
        } else if (object instanceof RubyFixnum) {
            return new ModeFlags(((RubyFixnum) object).getLongValue());
        }

        throw runtime.newTypeError("Invalid type for modes");
    }
View Full Code Here

    public FileDescriptorIO(Ruby runtime, RubyClass klass) {
        super(runtime, klass);
    }
    public FileDescriptorIO(Ruby runtime, IRubyObject fd) {
        super(runtime, runtime.fastGetModule("FFI").fastGetClass(CLASS_NAME));
        ModeFlags modes;
        try {
            modes = new ModeFlags(ModeFlags.RDWR);
            openFile.setMainStream(ChannelStream.open(getRuntime(),
                    new ChannelDescriptor(new FileDescriptorByteChannel(getRuntime(), RubyNumeric.fix2int(fd)),
                    modes)));
            openFile.setPipeStream(openFile.getMainStreamSafe());
            openFile.setMode(modes.getOpenFileFlags());
            openFile.getMainStreamSafe().setSync(true);
        } catch (BadDescriptorException e) {
            throw runtime.newErrnoEBADFError();
        } catch (InvalidValueException ex) {
            throw new RuntimeException(ex);
View Full Code Here

    @JRubyMethod(visibility = Visibility.PRIVATE)
    public IRubyObject initialize(ThreadContext context) {
        try {
            DatagramChannel channel = DatagramChannel.open();
            initSocket(context.getRuntime(), new ChannelDescriptor(channel, new ModeFlags(ModeFlags.RDWR)));
        } catch (org.jruby.util.io.InvalidValueException ex) {
            throw context.getRuntime().newErrnoEINVALError();
        } catch (ConnectException e) {
            throw context.getRuntime().newErrnoECONNREFUSEDError();
        } catch (UnknownHostException e) {
View Full Code Here

        return context.getRuntime().newFixnum(0);
    }

    protected void init_sock(Ruby runtime) {
        try {
            ModeFlags modes = new ModeFlags(ModeFlags.RDWR);
            openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(new UnixDomainSocketChannel(runtime, fd), modes)));
            openFile.setPipeStream(openFile.getMainStreamSafe());
            openFile.setMode(modes.getOpenFileFlags());
            openFile.getMainStreamSafe().setSync(true);
        } catch (BadDescriptorException e) {
            throw runtime.newErrnoEBADFError();
        } catch (InvalidValueException ive) {
            throw runtime.newErrnoEINVALError();
View Full Code Here

                throw sockerr(context.getRuntime(), "initialize: name or service not known");
            } finally {
                // only try to set blocking back if we succeeded to finish connecting
                if (success) channel.configureBlocking(true);
            }
            initSocket(context.getRuntime(), new ChannelDescriptor(channel, new ModeFlags(ModeFlags.RDWR)));
        } catch (InvalidValueException ex) {
            throw context.getRuntime().newErrnoEINVALError();
        } catch (ClosedChannelException cce) {
            throw context.getRuntime().newErrnoECONNREFUSEDError();
        } catch(IOException e) {
View Full Code Here

        super(runtime, klass);
    }

    public FileDescriptorIO(Ruby runtime, IRubyObject fd) {
        super(runtime, runtime.getModule("FFI").getClass(CLASS_NAME));
        ModeFlags modes;
        try {
            modes = newModeFlags(runtime, ModeFlags.RDWR);
            int fileno = RubyNumeric.fix2int(fd);
            jnr.posix.FileStat stat = runtime.getPosix().fstat(fileno);
            java.nio.channels.ByteChannel channel;

            if (stat.isSocket()) {
                channel = new jnr.enxio.channels.NativeSocketChannel(fileno);
            } else if (stat.isBlockDev() || stat.isCharDev()) {
                channel = new jnr.enxio.channels.NativeDeviceChannel(fileno);
            } else {
                channel = new FileDescriptorByteChannel(runtime, fileno);
            }

            openFile.setMainStream(ChannelStream.open(getRuntime(), new ChannelDescriptor(channel, modes, FileDescriptorHelper.wrap(fileno))));
            openFile.setPipeStream(openFile.getMainStreamSafe());
            openFile.setMode(modes.getOpenFileFlags());
            openFile.getMainStreamSafe().setSync(true);
        } catch (BadDescriptorException e) {
            throw runtime.newErrnoEBADFError();
        }
    }
View Full Code Here

        return newModeFlags(runtime, (int) mode);
    }

    public static ModeFlags newModeFlags(Ruby runtime, int mode) {
        try {
            return new ModeFlags(mode);
        } catch (InvalidValueException ive) {
            throw runtime.newErrnoEINVALError();
        }
    }
View Full Code Here

        }
    }

    public static ModeFlags newModeFlags(Ruby runtime, String mode) {
        try {
            return new ModeFlags(mode);
        } catch (InvalidValueException ive) {
            // This is used by File and StringIO, which seem to want an ArgumentError instead of EINVAL
            throw runtime.newArgumentError("illegal access mode " + mode);
        }
    }
View Full Code Here

        return newIOOptions(runtime, (int) mode);
    }

    public static IOOptions newIOOptions(Ruby runtime, int mode) {
        try {
            ModeFlags modeFlags = new ModeFlags(mode);
            return new IOOptions(modeFlags, EncodingOption.getEncodingNoOption(runtime, modeFlags));
        } catch (InvalidValueException ive) {
            throw runtime.newErrnoEINVALError();
        }
    }
View Full Code Here

TOP

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

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.