public boolean feof() throws IOException, BadDescriptorException { return stream.feof(); }
public boolean feof() throws IOException, BadDescriptorException { return stream.feof(); }
public boolean feof() throws IOException, BadDescriptorException { return stream.feof(); }
public boolean feof() throws IOException, BadDescriptorException { return stream.feof(); }
protected static boolean emptyBufferOrEOF(ByteList buffer, OpenFile myOpenFile) throws BadDescriptorException, IOException { if (buffer == null) { return true; } else if (buffer.length() == 0) { if (myOpenFile.getMainStreamSafe() == null) { return true; } if (myOpenFile.getMainStreamSafe().feof()) { return true; } } return false; }
protected static boolean emptyBufferOrEOF(ByteList buffer, OpenFile myOpenFile) throws BadDescriptorException, IOException { if (buffer == null) { return true; } else if (buffer.length() == 0) { if (myOpenFile.getMainStreamSafe() == null) { return true; } if (myOpenFile.getMainStreamSafe().feof()) { return true; } } return false; }
public void checkReadable(Ruby runtime) throws IOException, BadDescriptorException, InvalidValueException { checkClosed(runtime); if ((mode & READABLE) == 0) { throw runtime.newIOError("not opened for reading"); } if (((mode & WBUF) != 0 || (mode & (SYNCWRITE | RBUF)) == SYNCWRITE) && !mainStream.feof() && pipeStream == null) { try { // seek to force underlying buffer to flush seek(0, Stream.SEEK_CUR); } catch (PipeException p) { // ignore unseekable streams for purposes of checking readability } catch (IOException ioe) { // MRI ignores seek errors, presumably for unseekable files like // serial ports (JRUBY-2979), so we shall too. } } }
public void checkReadable(Ruby runtime) throws IOException, BadDescriptorException, InvalidValueException { checkClosed(runtime); if ((mode & READABLE) == 0) { throw runtime.newIOError("not opened for reading"); } if (((mode & WBUF) != 0 || (mode & (SYNCWRITE | RBUF)) == SYNCWRITE) && !mainStream.feof() && pipeStream == null) { try { // seek to force underlying buffer to flush seek(0, Stream.SEEK_CUR); } catch (PipeException p) { // ignore unseekable streams for purposes of checking readability } catch (IOException ioe) { // MRI ignores seek errors, presumably for unseekable files like // serial ports (JRUBY-2979), so we shall too. } } }
public void checkWritable(Ruby runtime) throws IOException, BadDescriptorException, InvalidValueException { checkClosed(runtime); if ((mode & WRITABLE) == 0) { throw runtime.newIOError("not opened for writing"); } if ((mode & RBUF) != 0 && !mainStream.feof() && pipeStream == null) { try { // seek to force read buffer to invalidate seek(0, Stream.SEEK_CUR); } catch (PipeException p) { // ignore unseekable streams for purposes of checking readability } catch (IOException ioe) { // MRI ignores seek errors, presumably for unseekable files like // serial ports (JRUBY-2979), so we shall too. } } if (pipeStream == null) { mode &= ~RBUF; } }
public void checkWritable(Ruby runtime) throws IOException, BadDescriptorException, InvalidValueException { checkClosed(runtime); if ((mode & WRITABLE) == 0) { throw runtime.newIOError("not opened for writing"); } if ((mode & RBUF) != 0 && !mainStream.feof() && pipeStream == null) { try { // seek to force read buffer to invalidate seek(0, Stream.SEEK_CUR); } catch (PipeException p) { // ignore unseekable streams for purposes of checking readability } catch (IOException ioe) { // MRI ignores seek errors, presumably for unseekable files like // serial ports (JRUBY-2979), so we shall too. } } if (pipeStream == null) { mode &= ~RBUF; } }
public ByteList fread(int number) throws IOException, BadDescriptorException, EOFException { if (number == 0) { if (stream.feof()) { return null; } else { return new ByteList(0); } } boolean eof = false; ByteList bl = new ByteList(number > ChannelStream.BUFSIZE ? ChannelStream.BUFSIZE : number); for (int i = 0; i < number; i++) { int c = fgetc(); if (c == -1) { eof = true; break; } bl.append(c); } if (eof && bl.length() == 0) { return null; } return bl; }
public ByteList fread(int number) throws IOException, BadDescriptorException, EOFException { if (number == 0) { if (stream.feof()) { return null; } else { return new ByteList(0); } } boolean eof = false; ByteList bl = new ByteList(number > ChannelStream.BUFSIZE ? ChannelStream.BUFSIZE : number); for (int i = 0; i < number; i++) { int c = fgetc(); if (c == -1) { eof = true; break; } bl.append(c); } if (eof && bl.length() == 0) { return null; } return bl; }
public ByteList fread(int number) throws IOException, BadDescriptorException, EOFException { if (number == 0) { if (stream.feof()) { return null; } else { return new ByteList(0); } } boolean eof = false; ByteList bl = new ByteList(number > ChannelStream.BUFSIZE ? ChannelStream.BUFSIZE : number); for (int i = 0; i < number; i++) { int c = fgetc(); if (c == -1) { eof = true; break; } bl.append(c); } if (eof && bl.length() == 0) { return null; } return bl; }
/** * waits until input available or timed out and returns self, or nil when EOF reached. */ @JRubyMethod public static IRubyObject io_wait(ThreadContext context, IRubyObject obj) { RubyIO io = (RubyIO)obj; try { OpenFile openFile = io.getOpenFile(); if (openFile.getMainStreamSafe().feof()) { return context.runtime.getNil(); } openFile.getMainStreamSafe().waitUntilReady(); } catch (BadDescriptorException e) { throw context.runtime.newErrnoEBADFError(); } catch (Exception anyEx) { return context.runtime.getNil(); } return obj; } }
/** * waits until input available or timed out and returns self, or nil when EOF reached. */ @JRubyMethod public static IRubyObject io_wait(ThreadContext context, IRubyObject obj) { RubyIO io = (RubyIO)obj; try { OpenFile openFile = io.getOpenFile(); if (openFile.getMainStreamSafe().feof()) { return context.runtime.getNil(); } openFile.getMainStreamSafe().waitUntilReady(); } catch (BadDescriptorException e) { throw context.runtime.newErrnoEBADFError(); } catch (Exception anyEx) { return context.runtime.getNil(); } return obj; } }
private ByteList readNotAllCommon(ThreadContext context, OpenFile myOpenFile, int length) { Ruby runtime = context.runtime; try { myOpenFile.checkReadable(runtime); myOpenFile.setReadBuffered(); if (myOpenFile.getMainStreamSafe().feof()) { return null; } // READ_CHECK from MRI io.c readCheck(myOpenFile.getMainStreamSafe()); ByteList newBuffer = fread(context.getThread(), length); return newBuffer; } catch (EOFException ex) { throw runtime.newEOFError(); } catch (InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } catch (IOException ex) { throw runtime.newIOErrorFromException(ex); } catch (BadDescriptorException ex) { throw runtime.newErrnoEBADFError(); } }
private ByteList readNotAllCommon(ThreadContext context, OpenFile myOpenFile, int length) { Ruby runtime = context.runtime; try { myOpenFile.checkReadable(runtime); myOpenFile.setReadBuffered(); if (myOpenFile.getMainStreamSafe().feof()) { return null; } // READ_CHECK from MRI io.c readCheck(myOpenFile.getMainStreamSafe()); ByteList newBuffer = fread(context.getThread(), length); return newBuffer; } catch (EOFException ex) { throw runtime.newEOFError(); } catch (InvalidValueException ex) { throw runtime.newErrnoEINVALError(); } catch (IOException ex) { throw runtime.newIOErrorFromException(ex); } catch (BadDescriptorException ex) { throw runtime.newErrnoEBADFError(); } }
/** * returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil. */ @JRubyMethod(name = "ready?") public static IRubyObject ready(ThreadContext context, IRubyObject obj) { RubyIO io = (RubyIO)obj; try { OpenFile openFile = io.getOpenFile(); ChannelDescriptor descriptor = openFile.getMainStreamSafe().getDescriptor(); if (!descriptor.isOpen() || !openFile.getMainStreamSafe().getModes().isReadable() || openFile.getMainStreamSafe().feof()) { return context.runtime.getFalse(); } int avail = openFile.getMainStreamSafe().ready(); if (avail > 0) { return context.runtime.newFixnum(avail); } } catch (BadDescriptorException e) { throw context.runtime.newErrnoEBADFError(); } catch (Exception anyEx) { return context.runtime.getFalse(); } return context.runtime.getNil(); }