Package org.jruby.util.io

Examples of org.jruby.util.io.OpenFile$BufreadArg


    protected void initSocket(Ruby runtime, ChannelDescriptor descriptor) {
        // make sure descriptor is registered
        registerDescriptor(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 {
            return RubyString.newString(context.getRuntime(), openFile.getMainStream().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

       
        return this;
    }
   
    private void sysopenInternal(String path, ModeFlags modes, int perm) throws InvalidValueException {
        openFile = new OpenFile();
       
        openFile.setPath(path);
        openFile.setMode(modes.getOpenFileFlags());
       
        ChannelDescriptor descriptor = sysopen(path, modes, perm);
View Full Code Here

       
        registerDescriptor(descriptor);
    }
   
    private 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

     */
    @JRubyMethod(name = "ungetc", required = 1)
    public IRubyObject ungetc(IRubyObject number) {
        int ch = RubyNumeric.fix2int(number);
       
        OpenFile myOpenFile = getOpenFileChecked();
       
        if (!myOpenFile.isReadBuffered()) {
            throw getRuntime().newIOError("unread stream");
        }
       
        try {
            myOpenFile.checkReadable(getRuntime());
            myOpenFile.setReadBuffered();

            if (myOpenFile.getMainStream().ungetc(ch) == -1 && ch != -1) {
                throw getRuntime().newIOError("ungetc failed");
            }
        } catch (PipeException ex) {
            throw getRuntime().newErrnoEPIPEError();
        } catch (InvalidValueException ex) {
View Full Code Here

               
                buffer = str.getByteList();
                buffer.length(0);
            }
           
            OpenFile myOpenFile = getOpenFileChecked();
           
            myOpenFile.checkReadable(getRuntime());
           
            if (myOpenFile.getMainStream().readDataBuffered()) {
                throw getRuntime().newIOError("sysread for buffered IO");
            }
           
            // TODO: Ruby locks the string here
           
            context.getThread().beforeBlockingCall();
            myOpenFile.checkClosed(getRuntime());
           
            // TODO: Ruby re-checks that the buffer string hasn't been modified
           
            int bytesRead = myOpenFile.getMainStream().getDescriptor().read(len, str.getByteList());
           
            // TODO: Ruby unlocks the string here
           
            // TODO: Ruby truncates string to specific size here, but our bytelist should handle this already?
           
View Full Code Here

    }
   
    @JRubyMethod(name = "read")
    public IRubyObject read(ThreadContext context) {
        Ruby runtime = context.getRuntime();
        OpenFile myOpenFile = getOpenFileChecked();
       
        try {
            myOpenFile.checkReadable(runtime);
            myOpenFile.setReadBuffered();

            return readAll(getRuntime().getNil());
        } catch (PipeException ex) {
            throw getRuntime().newErrnoEPIPEError();
        } catch (InvalidValueException ex) {
View Full Code Here

    public IRubyObject read(ThreadContext context, IRubyObject arg0) {
        if (arg0.isNil()) {
            return read(context);
        }
       
        OpenFile myOpenFile = getOpenFileChecked();
       
        int length = RubyNumeric.num2int(arg0);
       
        if (length < 0) {
            throw getRuntime().newArgumentError("negative length " + length + " given");
View Full Code Here

        return readNotAll(context, myOpenFile, length, str);
    }
   
    @JRubyMethod(name = "read")
    public IRubyObject read(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
        OpenFile myOpenFile = getOpenFileChecked();
       
        if (arg0.isNil()) {
            try {
                myOpenFile.checkReadable(getRuntime());
                myOpenFile.setReadBuffered();

                return readAll(arg1);
            } catch (PipeException ex) {
                throw getRuntime().newErrnoEPIPEError();
            } catch (InvalidValueException ex) {
View Full Code Here

    @JRubyMethod(name = "each_byte", frame = true)
    public IRubyObject each_byte(ThreadContext context, Block block) {
        Ruby runtime = context.getRuntime();
       
      try {
            OpenFile myOpenFile = getOpenFileChecked();
           
            while (true) {
                myOpenFile.checkReadable(runtime);
                myOpenFile.setReadBuffered();

                // TODO: READ_CHECK from MRI
               
                int c = myOpenFile.getMainStream().fgetc();
               
                if (c == -1) {
                    // TODO: check for error, clear it, and wait until readable before trying once more
//                    if (ferror(f)) {
//                        clearerr(f);
View Full Code Here

TOP

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

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.