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 checkReopenSeek(ThreadContext context, Ruby runtime, long pos) { if (seek(context, pos, PosixShim.SEEK_SET) == -1 && errno() != null) { throw runtime.newErrnoFromErrno(errno(), getPath()); } }
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 checkReopenSeek(ThreadContext context, Ruby runtime, long pos) { if (seek(context, pos, PosixShim.SEEK_SET) == -1 && errno() != null) { throw runtime.newErrnoFromErrno(errno(), getPath()); } }
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; } }
private long doSeek(ThreadContext context, long pos, int whence) { OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, whence); if (pos < 0 && fptr.errno() != null) { throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } } finally { if (locked) fptr.unlock(); } return 0; }
private long doSeek(ThreadContext context, long pos, int whence) { OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, whence); if (pos < 0 && fptr.errno() != null) { throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } } finally { if (locked) fptr.unlock(); } return 0; }
private RubyFixnum doSeek(ThreadContext context, long offset, int whence) { OpenFile myOpenFile = getOpenFileChecked(); try { myOpenFile.seek(offset, whence); myOpenFile.getMainStreamSafe().clearerr(); } catch (BadDescriptorException ex) { throw context.runtime.newErrnoEBADFError(); } catch (InvalidValueException e) { throw context.runtime.newErrnoEINVALError(); } catch (PipeException e) { throw context.runtime.newErrnoESPIPEError(); } catch (IOException e) { throw context.runtime.newIOErrorFromException(e); } return RubyFixnum.zero(context.runtime); }
private RubyFixnum doSeek(ThreadContext context, long offset, int whence) { OpenFile myOpenFile = getOpenFileChecked(); try { myOpenFile.seek(offset, whence); myOpenFile.getMainStreamSafe().clearerr(); } catch (BadDescriptorException ex) { throw context.runtime.newErrnoEBADFError(); } catch (InvalidValueException e) { throw context.runtime.newErrnoEINVALError(); } catch (PipeException e) { throw context.runtime.newErrnoESPIPEError(); } catch (IOException e) { throw context.runtime.newIOErrorFromException(e); } return RubyFixnum.zero(context.runtime); }
@JRubyMethod(name = "pos=", required = 1) public RubyFixnum pos_set(ThreadContext context, IRubyObject offset) { OpenFile fptr; long pos; pos = offset.convertToInteger().getLongValue(); fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, PosixShim.SEEK_SET); if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } finally { if (locked) fptr.unlock(); } return context.runtime.newFixnum(pos); }
@JRubyMethod(name = "pos=", required = 1) public RubyFixnum pos_set(ThreadContext context, IRubyObject offset) { OpenFile fptr; long pos; pos = offset.convertToInteger().getLongValue(); fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { pos = fptr.seek(context, pos, PosixShim.SEEK_SET); if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } finally { if (locked) fptr.unlock(); } return context.runtime.newFixnum(pos); }
@JRubyMethod public RubyFixnum rewind(ThreadContext context) { Ruby runtime = context.runtime; OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { if (fptr.seek(context, 0L, 0) == -1 && fptr.errno() != null) { throw runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } if (RubyArgsFile.ArgsFileData.getArgsFileData(runtime).isCurrentFile(this)) { runtime.setCurrentLine(runtime.getCurrentLine() - fptr.getLineNumber()); } fptr.setLineNumber(0); if (fptr.readconv != null) { fptr.clearReadConversion(); } } finally { if (locked) fptr.unlock(); } return RubyFixnum.zero(runtime); }
@JRubyMethod public RubyFixnum rewind(ThreadContext context) { Ruby runtime = context.runtime; OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { if (fptr.seek(context, 0L, 0) == -1 && fptr.errno() != null) { throw runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); } if (RubyArgsFile.ArgsFileData.getArgsFileData(runtime).isCurrentFile(this)) { runtime.setCurrentLine(runtime.getCurrentLine() - fptr.getLineNumber()); } fptr.setLineNumber(0); if (fptr.readconv != null) { fptr.clearReadConversion(); } } finally { if (locked) fptr.unlock(); } return RubyFixnum.zero(runtime); }
pos = orig.tell(context); if (pos == -1) fptr.seek(context, pos, PosixShim.SEEK_SET); } finally { if (locked2) fptr.unlock();
pos = orig.tell(context); if (pos == -1) fptr.seek(context, pos, PosixShim.SEEK_SET); } finally { if (locked2) fptr.unlock();