本文整理了Java中org.jruby.Ruby.newErrnoFromErrno
方法的一些代码示例,展示了Ruby.newErrnoFromErrno
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newErrnoFromErrno
方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newErrnoFromErrno
暂无
代码示例来源:origin: org.jruby/jruby-complete
/**
* Java does not give us enough information for specific error conditions
* so we are reduced to divining them through string matches...
*
* TODO: Should ECONNABORTED get thrown earlier in the descriptor itself or is it ok to handle this late?
* TODO: Should we include this into Errno code somewhere do we can use this from other places as well?
*/
public static RaiseException newIOErrorFromException(Ruby runtime, IOException ex) {
Errno errno = errnoFromException(ex);
if (errno == null) throw runtime.newIOError(ex.getLocalizedMessage());
throw runtime.newErrnoFromErrno(errno, ex.getLocalizedMessage());
}
代码示例来源:origin: org.jruby/jruby-core
/**
* Java does not give us enough information for specific error conditions
* so we are reduced to divining them through string matches...
*
* TODO: Should ECONNABORTED get thrown earlier in the descriptor itself or is it ok to handle this late?
* TODO: Should we include this into Errno code somewhere do we can use this from other places as well?
*/
public static RaiseException newIOErrorFromException(Ruby runtime, IOException ex) {
Errno errno = errnoFromException(ex);
if (errno == null) throw runtime.newIOError(ex.getLocalizedMessage());
throw runtime.newErrnoFromErrno(errno, ex.getLocalizedMessage());
}
代码示例来源:origin: org.jruby/jruby-core
public static RubyFixnum spawn(ThreadContext context, IRubyObject[] argv) {
Ruby runtime = context.runtime;
long pid = 0;
String[] errmsg = { null };
ExecArg eargp;
IRubyObject fail_str;
eargp = execargNew(context, argv, true);
execargFixup(context, runtime, eargp);
fail_str = eargp.use_shell ? eargp.command_name : eargp.command_name;
PopenExecutor executor = new PopenExecutor();
pid = executor.spawnProcess(context, runtime, eargp, errmsg);
if (pid == -1) {
if (errmsg[0] == null) {
throw runtime.newErrnoFromErrno(executor.errno, fail_str.toString());
}
throw runtime.newErrnoFromErrno(executor.errno, errmsg[0]);
}
return runtime.newFixnum(pid);
}
代码示例来源:origin: org.jruby/jruby-complete
protected static ChannelFD sysopen(Ruby runtime, String fname, int oflags, int perm) {
ChannelFD fd;
Sysopen data = new Sysopen();
data.fname = fname;
data.oflags = oflags;
data.perm = perm;
fd = sysopenInternal(runtime, data);
if (fd == null) {
if (data.errno != null) {
throw runtime.newErrnoFromErrno(data.errno, fname);
} else {
throw runtime.newSystemCallError(fname);
}
}
return fd;
}
代码示例来源:origin: org.jruby/jruby-complete
public void checkCharReadable(ThreadContext context) {
checkClosed();
if ((mode & READABLE) == 0) {
throw runtime.newIOError("not opened for reading");
}
if (wbuf.len != 0) {
if (io_fflush(context) < 0) {
throw runtime.newErrnoFromErrno(posix.errno, "error flushing");
}
}
if (tiedIOForWriting != null) {
OpenFile wfptr;
wfptr = tiedIOForWriting.getOpenFileChecked();
if (wfptr.io_fflush(context) < 0) {
throw runtime.newErrnoFromErrno(wfptr.posix.errno, wfptr.getPath());
}
}
}
代码示例来源:origin: org.jruby/jruby-core
protected static ChannelFD sysopen(Ruby runtime, String fname, int oflags, int perm) {
ChannelFD fd;
Sysopen data = new Sysopen();
data.fname = fname;
data.oflags = oflags;
data.perm = perm;
fd = sysopenInternal(runtime, data);
if (fd == null) {
if (data.errno != null) {
throw runtime.newErrnoFromErrno(data.errno, fname);
} else {
throw runtime.newSystemCallError(fname);
}
}
return fd;
}
代码示例来源:origin: org.jruby/jruby-core
public void checkCharReadable(ThreadContext context) {
checkClosed();
if ((mode & READABLE) == 0) {
throw runtime.newIOError("not opened for reading");
}
if (wbuf.len != 0) {
if (io_fflush(context) < 0) {
throw runtime.newErrnoFromErrno(posix.errno, "error flushing");
}
}
if (tiedIOForWriting != null) {
OpenFile wfptr;
wfptr = tiedIOForWriting.getOpenFileChecked();
if (wfptr.io_fflush(context) < 0) {
throw runtime.newErrnoFromErrno(wfptr.posix.errno, wfptr.getPath());
}
}
}
代码示例来源:origin: org.jruby/jruby-core
public void checkReopenSeek(ThreadContext context, Ruby runtime, long pos) {
if (seek(context, pos, PosixShim.SEEK_SET) == -1 && errno() != null) {
throw runtime.newErrnoFromErrno(errno(), getPath());
}
}
代码示例来源:origin: org.jruby/jruby-complete
private void flushBeforeSeek(ThreadContext context) {
boolean locked = lock();
try {
if (io_fflush(context) < 0)
throw context.runtime.newErrnoFromErrno(posix.errno, "");
unread(context);
posix.errno = null;
} finally {
if (locked) unlock();
}
}
代码示例来源:origin: org.jruby/jruby-complete
public void checkReopenSeek(ThreadContext context, Ruby runtime, long pos) {
if (seek(context, pos, PosixShim.SEEK_SET) == -1 && errno() != null) {
throw runtime.newErrnoFromErrno(errno(), getPath());
}
}
代码示例来源:origin: org.jruby/jruby-core
private void flushBeforeSeek(ThreadContext context) {
boolean locked = lock();
try {
if (io_fflush(context) < 0)
throw context.runtime.newErrnoFromErrno(posix.errno, "");
unread(context);
posix.errno = null;
} finally {
if (locked) unlock();
}
}
代码示例来源:origin: org.jruby/jruby-complete
public int fread(ThreadContext context, IRubyObject str, int offset, int size) {
int len;
BufreadArg arg = new BufreadArg();
str = EncodingUtils.setStrBuf(context.runtime, str, offset + size);
ByteList strByteList = ((RubyString)str).getByteList();
arg.strPtrBytes = strByteList.unsafeBytes();
arg.strPtr = strByteList.begin() + offset;
arg.len = size;
arg.fptr = this;
// we don't support string locking
// rb_str_locktmp_ensure(str, bufread_call, (VALUE)&arg);
bufreadCall(context, arg);
len = arg.len;
// should be errno
if (len < 0) throw context.runtime.newErrnoFromErrno(posix.errno, pathv);
return len;
}
代码示例来源:origin: org.jruby/jruby-core
public int fread(ThreadContext context, IRubyObject str, int offset, int size) {
int len;
BufreadArg arg = new BufreadArg();
str = EncodingUtils.setStrBuf(context.runtime, str, offset + size);
ByteList strByteList = ((RubyString)str).getByteList();
arg.strPtrBytes = strByteList.unsafeBytes();
arg.strPtr = strByteList.begin() + offset;
arg.len = size;
arg.fptr = this;
// we don't support string locking
// rb_str_locktmp_ensure(str, bufread_call, (VALUE)&arg);
bufreadCall(context, arg);
len = arg.len;
// should be errno
if (len < 0) throw context.runtime.newErrnoFromErrno(posix.errno, pathv);
return len;
}
代码示例来源:origin: org.jruby/jruby-complete
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;
}
代码示例来源:origin: org.jruby/jruby-core
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;
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(name = {"pos", "tell"})
public RubyFixnum pos(ThreadContext context) {
OpenFile fptr = getOpenFileChecked();
boolean locked = fptr.lock();
try {
long pos = fptr.tell(context);
if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath());
pos -= fptr.rbuf.len;
return context.runtime.newFixnum(pos);
} finally {
if (locked) fptr.unlock();
}
}
代码示例来源:origin: org.jruby/jruby-core
@JRubyMethod(name = {"pos", "tell"})
public RubyFixnum pos(ThreadContext context) {
OpenFile fptr = getOpenFileChecked();
boolean locked = fptr.lock();
try {
long pos = fptr.tell(context);
if (pos == -1 && fptr.errno() != null) throw context.runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath());
pos -= fptr.rbuf.len;
return context.runtime.newFixnum(pos);
} finally {
if (locked) fptr.unlock();
}
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-core
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@JRubyMethod(required = 1)
public IRubyObject truncate(ThreadContext context, IRubyObject len) {
Ruby runtime = context.runtime;
OpenFile fptr;
long pos;
pos = RubyNumeric.num2int(len);
fptr = getOpenFileChecked();
if (!fptr.isWritable()) {
throw runtime.newIOError("not opened for writing");
}
flushRaw(context, false);
if (pos < 0) {
throw runtime.newErrnoEINVALError(openFile.getPath());
}
if (fptr.posix.ftruncate(fptr.fd(), pos) < 0) {
throw runtime.newErrnoFromErrno(fptr.posix.errno, fptr.getPath());
}
return RubyFixnum.zero(runtime);
}
内容来源于网络,如有侵权,请联系作者删除!