Package org.jruby.util.io

Examples of org.jruby.util.io.ChannelDescriptor


            perms = RubyNumeric.fix2int(permsInt);
        }

        int fileno = -1;
        try {
            ChannelDescriptor descriptor =
                ChannelDescriptor.open(runtime.getCurrentDirectory(),
                                       path, modes.getModeFlags(), perms, runtime.getPosix(),
                                       runtime.getJRubyClassLoader());
            // always a new fileno, so ok to use internal only
            fileno = descriptor.getFileno();
        }
        catch (FileNotFoundException fnfe) {
            throw runtime.newErrnoENOENTError(path);
        } catch (DirectoryAsFileException dafe) {
            throw runtime.newErrnoEISDirError(path);
View Full Code Here


                } else {
                    modes = newIOOptions(runtime, originalFile.getMainStreamSafe().getModes());
                }
            }
           
            ChannelDescriptor descriptor = originalFile.getMainStreamSafe().getDescriptor().dup();

            newFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, modes.getModeFlags()));

            newFile.getMainStream().setSync(originalFile.getMainStreamSafe().isSync());
            if (originalFile.getMainStreamSafe().isBinmode()) newFile.getMainStream().setBinmode();
View Full Code Here

    }

    // mri: read_all
    protected ByteList readAllCommon(Ruby runtime) throws BadDescriptorException, EOFException, IOException {
        ByteList buf = null;
        ChannelDescriptor descriptor = openFile.getMainStreamSafe().getDescriptor();
        try {
            // ChannelStream#readall knows what size should be allocated at first. Just use it.
            if (descriptor.isSeekable() && descriptor.getChannel() instanceof FileChannel) {
                buf = openFile.getMainStreamSafe().readall();
            } else {
                RubyThread thread = runtime.getCurrentContext().getThread();
                try {
                    while (true) {
View Full Code Here

                io2 = (RubyIO) arg2;
            } else {
                throw runtime.newTypeError("Should be String or IO");
            }

            ChannelDescriptor d1 = io1.openFile.getMainStreamSafe().getDescriptor();
            ChannelDescriptor d2 = io2.openFile.getMainStreamSafe().getDescriptor();

            if (!d1.isReadable()) throw runtime.newIOError("from IO is not readable");
            if (!d2.isWritable()) throw runtime.newIOError("from IO is not writable");

            try {
                long size = 0;
                if (!d1.isSeekable()) {
                    if (!d2.isSeekable()) {
                        throw context.runtime.newTypeError("only supports to file or from file copy");
                    } else {
                        ReadableByteChannel from = (ReadableByteChannel)d1.getChannel();
                        FileChannel to = (FileChannel)d2.getChannel();

                        size = transfer(from, to);
                    }
                } else {
                    FileChannel from = (FileChannel)d1.getChannel();
                    WritableByteChannel to = (WritableByteChannel)d2.getChannel();

                    size = transfer(from, to);
                }

                return context.runtime.newFixnum(size);
View Full Code Here

    public IRubyObject initialize(ThreadContext context) {
        Ruby runtime = context.runtime;

        try {
            DatagramChannel channel = DatagramChannel.open();
            initSocket(runtime, new ChannelDescriptor(channel, newModeFlags(runtime, ModeFlags.RDWR)));

        } catch (ConnectException e) {
            throw runtime.newErrnoECONNREFUSEDError();

        } catch (UnknownHostException e) {
View Full Code Here

    }

    private InputStream wrapJRubyNormalizedInputStream(String file) throws IOException {
        Ruby runtime = Ruby.getGlobalRuntime();
        try {
            ChannelDescriptor descriptor = ChannelDescriptor.open(runtime.getCurrentDirectory(), file, new ModeFlags(ModeFlags.RDONLY));
            return ChannelStream.open(runtime, descriptor).newInputStream();
        } catch (NoSuchMethodError nsme) {
            return new BufferedInputStream(new FileInputStream(file));
        } catch (FileExistsException fee) {
            // should not happen because ModeFlag does not contain CREAT.
View Full Code Here

        Ruby runtime = context.runtime;

        if (fd instanceof RubyFixnum) {
            int intFD = (int)((RubyFixnum)fd).getLongValue();

            ChannelDescriptor descriptor = ChannelDescriptor.getDescriptorByFileno(intFD);

            if (descriptor == null) {
                throw runtime.newErrnoEBADFError();
            }
View Full Code Here

    public IRubyObject initialize(ThreadContext context, IRubyObject domain, IRubyObject type, IRubyObject protocol) {
        Ruby runtime = context.runtime;

        initFieldsFromArgs(runtime, domain, type, protocol);

        ChannelDescriptor descriptor = initChannel(runtime);

        initSocket(runtime, descriptor);

        return this;
    }
View Full Code Here

    public IRubyObject initialize19(ThreadContext context, IRubyObject domain, IRubyObject type) {
        Ruby runtime = context.runtime;

        initFieldsFromArgs(runtime, domain, type);

        ChannelDescriptor descriptor = initChannel(runtime);

        initSocket(runtime, descriptor);

        return this;
    }
View Full Code Here

    public IRubyObject initialize19(ThreadContext context, IRubyObject domain, IRubyObject type, IRubyObject protocol) {
        Ruby runtime = context.runtime;

        initFieldsFromArgs(runtime, domain, type, protocol);

        ChannelDescriptor descriptor = initChannel(runtime);

        initSocket(runtime, descriptor);

        return this;
    }
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.