Package org.jruby.util.io

Examples of org.jruby.util.io.OpenFile


        doNotReverseLookup = runtime.is1_9();
    }
   
    protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) {
        // continue with normal initialization
        openFile = new OpenFile();
       
        try {
            openFile.setMainStream(ChannelStream.fdopen(runtime, descriptor, new ModeFlags(ModeFlags.RDONLY)));
            openFile.setPipeStream(ChannelStream.fdopen(runtime, descriptor, new ModeFlags(ModeFlags.WRONLY)));
            openFile.getPipeStream().setSync(true);
View Full Code Here


    public IRubyObject recv(IRubyObject[] args) {
        return recv(getRuntime().getCurrentContext(), args);
    }
    @JRubyMethod(rest = true)
    public IRubyObject recv(ThreadContext context, IRubyObject[] args) {
        OpenFile openFile = getOpenFileChecked();
        try {
            context.getThread().beforeBlockingCall();
            return RubyString.newString(context.getRuntime(), openFile.getMainStreamSafe().read(RubyNumeric.fix2int(args[0])));
        } catch (BadDescriptorException e) {
            throw context.getRuntime().newErrnoEBADFError();
        } catch (EOFException e) {
            // recv returns nil on EOF
            return context.getRuntime().getNil();
View Full Code Here

    private int getFilePermissions(IRubyObject[] args) {
        return (args.length > 2 && !args[2].isNil()) ? RubyNumeric.num2int(args[2]) : 438;
    }

    protected void sysopenInternal(String path, ModeFlags modes, int perm) throws InvalidValueException {
        openFile = new OpenFile();
       
        openFile.setPath(path);
        openFile.setMode(modes.getOpenFileFlags());

        int umask = getUmaskSafe( getRuntime() );
View Full Code Here

        ChannelDescriptor descriptor = sysopen(path, modes, perm);
        openFile.setMainStream(fdopen(descriptor, modes));
    }

    protected void openInternal(String path, String modeString, ModeFlags modes) throws InvalidValueException {
        openFile = new OpenFile();

        openFile.setMode(modes.getOpenFileFlags());
        openFile.setPath(path);
        openFile.setMainStream(fopen(path, modeString));
    }
View Full Code Here

        openFile.setPath(path);
        openFile.setMainStream(fopen(path, modeString));
    }
   
    protected void openInternal(String path, String modeString) throws InvalidValueException {
        openFile = new OpenFile();

        openFile.setMode(getIOModes(getRuntime(), modeString).getOpenFileFlags());
        openFile.setPath(path);
        openFile.setMainStream(fopen(path, modeString));
    }
View Full Code Here

            throw context.getRuntime().newTypeError("wrong argument (expected FFI memory)");
        }

        Ruby runtime = context.getRuntime();
        try {
            OpenFile openFile = ((RubyIO) src).getOpenFile();
            openFile.checkClosed(runtime);
            openFile.checkReadable(runtime);

            ChannelStream stream = (ChannelStream) openFile.getMainStreamSafe();

            ByteBuffer buffer = ((AbstractMemory) dst).getMemoryIO().asByteBuffer();
            int count = RubyNumeric.num2int(rbLength);

            if (count > buffer.remaining()) {
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

            throw context.runtime.newTypeError("wrong argument (expected FFI memory)");
        }

        Ruby runtime = context.runtime;
        try {
            OpenFile openFile = ((RubyIO) src).getOpenFile();
            openFile.checkClosed(runtime);
            openFile.checkReadable(runtime);

            ChannelStream stream = (ChannelStream) openFile.getMainStreamSafe();

            ByteBuffer buffer = ((AbstractMemory) dst).getMemoryIO().asByteBuffer();
            int count = RubyNumeric.num2int(rbLength);

            if (count > buffer.remaining()) {
View Full Code Here

    // This should only be called by this and RubyFile.
    // It allows this object to be created without a IOHandler.
    public RubyIO(Ruby runtime, RubyClass type) {
        super(runtime, type);
       
        openFile = new OpenFile();
    }
View Full Code Here

        // We only want IO objects with valid streams (better to error now).
        if (outputStream == null) {
            throw runtime.newRuntimeError("Opening null stream");
        }
       
        openFile = new OpenFile();
       
        try {
            openFile.setMainStream(ChannelStream.open(runtime, new ChannelDescriptor(Channels.newChannel(outputStream)), autoclose));
        } catch (InvalidValueException e) {
            throw getRuntime().newErrnoEINVALError();
View Full Code Here

TOP

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

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.