Package org.jruby.util.io

Examples of org.jruby.util.io.Stream


            // FIXME we should probably still be dyncalling 'write' here
            RubyIO io = (RubyIO)maybeIO;
            try {
                OpenFile myOpenFile = io.getOpenFileChecked();
                myOpenFile.checkWritable(context.runtime);
                Stream writeStream = myOpenFile.getWriteStream();
                writeStream.fputc(c);
                if (myOpenFile.isSync()) myOpenFile.fflush(writeStream);
            } catch (IOException ex) {
                throw context.runtime.newIOErrorFromException(ex);
            } catch (BadDescriptorException e) {
                throw context.runtime.newErrnoEBADFError();
View Full Code Here


        try {
            OpenFile myOpenFile = getOpenFileChecked();
           
            myOpenFile.checkWritable(runtime);
       
            Stream writeStream = myOpenFile.getWriteStream();

            writeStream.fflush();
            writeStream.sync();

        } catch (InvalidValueException ex) {
            throw runtime.newErrnoEINVALError();
        } catch (IOException e) {
            throw runtime.newIOErrorFromException(e);
View Full Code Here

       
        if (!runtime.is1_9()) return super.inspect();
        OpenFile openFile = getOpenFile();
        if (openFile == null) return super.inspect();
       
        Stream stream = openFile.getMainStream();
        String className = getMetaClass().getRealClass().getName();
        String path = openFile.getPath();
        String status = "";
       
        if (path == null) {
            if (stream == null) {
                path = "";
                status = "(closed)";
            } else {
                path = "fd " + runtime.getFileno(stream.getDescriptor());
            }
        } else if (!openFile.isOpen()) {
            status = " (closed)";
        }
       
View Full Code Here

            OpenFile myOpenFile = getOpenFileChecked();

            myOpenFile.checkReadable(context.runtime);
            myOpenFile.setReadBuffered();

            Stream stream = myOpenFile.getMainStreamSafe();
           
            readCheck(stream);
            waitReadable(stream);
            stream.clearerr();
           
            int c = stream.fgetc();
       
            if (c == -1) {
                // CRuby checks ferror(f) and retry getc for non-blocking IO
                // read. We checks readability first if possible so retry should
                // not be needed I believe.
View Full Code Here

            OpenFile myOpenFile = getOpenFileChecked();

            myOpenFile.checkReadable(getRuntime());
            myOpenFile.setReadBuffered();

            Stream stream = myOpenFile.getMainStreamSafe();
           
            readCheck(stream);
            waitReadable(stream);
            stream.clearerr();
           
            return myOpenFile.getMainStreamSafe().fgetc();
        } catch (InvalidValueException ex) {
            throw getRuntime().newErrnoEINVALError();
        } catch (BadDescriptorException e) {
View Full Code Here

            } else {
                RubyThread thread = runtime.getCurrentContext().getThread();
                try {
                    while (true) {
                        // TODO: ruby locks the string here
                        Stream stream = openFile.getMainStreamSafe();
                        readCheck(stream);
                        openFile.checkReadable(runtime);
                        ByteList read = fread(thread, ChannelStream.BUFSIZE);
                           
                        // TODO: Ruby unlocks the string here
View Full Code Here

        return buf;
    }

    // implements io_fread in io.c
    private ByteList fread(RubyThread thread, int length) throws IOException, BadDescriptorException {
        Stream stream = openFile.getMainStreamSafe();
        int rest = length;
        waitReadable(stream);
        ByteList buf = blockingFRead(stream, thread, length);
        if (buf != null) {
            rest -= buf.length();
        }
        while (rest > 0) {
            waitReadable(stream);
            openFile.checkClosed(getRuntime());
            stream.clearerr();
            ByteList newBuffer = blockingFRead(stream, thread, rest);
            if (newBuffer == null) {
                // means EOF
                break;
            }
View Full Code Here

    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

TOP

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

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.