org.jruby.Ruby.newErrnoEEXISTError()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(15.8k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.jruby.Ruby.newErrnoEEXISTError方法的一些代码示例,展示了Ruby.newErrnoEEXISTError的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.newErrnoEEXISTError方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:newErrnoEEXISTError

Ruby.newErrnoEEXISTError介绍

暂无

代码示例

代码示例来源:origin: org.jruby/jruby-complete

private static IRubyObject mkdirCommon(Ruby runtime, String path, IRubyObject[] args) {
  if (path.startsWith("uri:")) throw runtime.newErrnoEACCESError(path);
  path = dirFromPath(path, runtime);
  FileResource res = JRubyFile.createResource(runtime, path);
  if (res.isDirectory()) throw runtime.newErrnoEEXISTError(path);
  String name = path.replace('\\', '/');
  boolean startsWithDriveLetterOnWindows = RubyFile.startsWithDriveLetterOnWindows(name);
  // don't attempt to create a dir for drive letters
  if (startsWithDriveLetterOnWindows) {
    // path is just drive letter plus :
    if (path.length() == 2) return RubyFixnum.zero(runtime);
    // path is drive letter plus : plus leading or trailing /
    if (path.length() == 3 && (path.charAt(0) == '/' || path.charAt(2) == '/')) return RubyFixnum.zero(runtime);
    // path is drive letter plus : plus leading and trailing /
    if (path.length() == 4 && (path.charAt(0) == '/' && path.charAt(3) == '/')) return RubyFixnum.zero(runtime);
  }
  File newDir = res.unwrap(File.class);
  if (File.separatorChar == '\\') newDir = new File(newDir.getPath());
  int mode = args.length == 2 ? ((int) args[1].convertToInteger().getLongValue()) : 0777;
  if (runtime.getPosix().mkdir(newDir.getAbsolutePath(), mode) < 0) {
    // FIXME: This is a system error based on errno
    throw runtime.newSystemCallError("mkdir failed");
  }
  return RubyFixnum.zero(runtime);
}

代码示例来源:origin: org.jruby/jruby-core

private static IRubyObject mkdirCommon(Ruby runtime, String path, IRubyObject[] args) {
  if (path.startsWith("uri:")) throw runtime.newErrnoEACCESError(path);
  path = dirFromPath(path, runtime);
  FileResource res = JRubyFile.createResource(runtime, path);
  if (res.isDirectory()) throw runtime.newErrnoEEXISTError(path);
  String name = path.replace('\\', '/');
  boolean startsWithDriveLetterOnWindows = RubyFile.startsWithDriveLetterOnWindows(name);
  // don't attempt to create a dir for drive letters
  if (startsWithDriveLetterOnWindows) {
    // path is just drive letter plus :
    if (path.length() == 2) return RubyFixnum.zero(runtime);
    // path is drive letter plus : plus leading or trailing /
    if (path.length() == 3 && (path.charAt(0) == '/' || path.charAt(2) == '/')) return RubyFixnum.zero(runtime);
    // path is drive letter plus : plus leading and trailing /
    if (path.length() == 4 && (path.charAt(0) == '/' && path.charAt(3) == '/')) return RubyFixnum.zero(runtime);
  }
  File newDir = res.unwrap(File.class);
  if (File.separatorChar == '\\') newDir = new File(newDir.getPath());
  int mode = args.length == 2 ? ((int) args[1].convertToInteger().getLongValue()) : 0777;
  if (runtime.getPosix().mkdir(newDir.getAbsolutePath(), mode) < 0) {
    // FIXME: This is a system error based on errno
    throw runtime.newSystemCallError("mkdir failed");
  }
  return RubyFixnum.zero(runtime);
}

代码示例来源:origin: org.jruby/jruby-complete

/** Returns a Java <code>File</code> object for the specified path.  If
 * <code>path</code> is not a directory, throws <code>IOError</code>.
 *
 * @param   path path for which to return the <code>File</code> object.
 * @param   mustExist is true the directory must exist.  If false it must not.
 */ // split out - no longer used
protected static FileResource getDir(final Ruby runtime, final String path, final boolean mustExist) {
  String dir = dirFromPath(path, runtime);
  FileResource result = JRubyFile.createResource(runtime, dir);
  if (mustExist && (result == null || !result.exists())) {
    throw runtime.newErrnoENOENTError(dir);
  }
  boolean isDirectory = result.isDirectory();
  if (mustExist && !isDirectory) {
    throw runtime.newErrnoENOTDIRError(path);
  }
  if (!mustExist && isDirectory) {
    throw runtime.newErrnoEEXISTError(dir);
  }
  return result;
}

代码示例来源:origin: org.jruby/jruby-core

/** Returns a Java <code>File</code> object for the specified path.  If
 * <code>path</code> is not a directory, throws <code>IOError</code>.
 *
 * @param   path path for which to return the <code>File</code> object.
 * @param   mustExist is true the directory must exist.  If false it must not.
 */ // split out - no longer used
protected static FileResource getDir(final Ruby runtime, final String path, final boolean mustExist) {
  String dir = dirFromPath(path, runtime);
  FileResource result = JRubyFile.createResource(runtime, dir);
  if (mustExist && (result == null || !result.exists())) {
    throw runtime.newErrnoENOENTError(dir);
  }
  boolean isDirectory = result.isDirectory();
  if (mustExist && !isDirectory) {
    throw runtime.newErrnoENOTDIRError(path);
  }
  if (!mustExist && isDirectory) {
    throw runtime.newErrnoEEXISTError(dir);
  }
  return result;
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/** Returns a Java <code>File</code> object for the specified path.  If
 * <code>path</code> is not a directory, throws <code>IOError</code>.
 *
 * @param   path path for which to return the <code>File</code> object.
 * @param   mustExist is true the directory must exist.  If false it must not.
 * @throws  IOError if <code>path</code> is not a directory.
 */
protected static JRubyFile getDir(final Ruby runtime, final String path, final boolean mustExist) {
  String dir = dirFromPath(path, runtime);
  JRubyFile result = JRubyFile.create(runtime.getCurrentDirectory(), dir);
  if (mustExist && !result.exists()) {
    throw runtime.newErrnoENOENTError(dir);
  }
  boolean isDirectory = result.isDirectory();
  if (mustExist && !isDirectory) {
    throw runtime.newErrnoENOTDIRError(path);
  }
  if (!mustExist && isDirectory) {
    throw runtime.newErrnoEEXISTError(dir);
  }
  return result;
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/** Returns a Java <code>File</code> object for the specified path.  If
 * <code>path</code> is not a directory, throws <code>IOError</code>.
 *
 * @param   path path for which to return the <code>File</code> object.
 * @param   mustExist is true the directory must exist.  If false it must not.
 * @throws  IOError if <code>path</code> is not a directory.
 */
protected static JRubyFile getDir(final Ruby runtime, final String path, final boolean mustExist) {
  String dir = dirFromPath(path, runtime);
  JRubyFile result = JRubyFile.create(runtime.getCurrentDirectory(), dir);
  if (mustExist && !result.exists()) {
    throw runtime.newErrnoENOENTError(dir);
  }
  boolean isDirectory = result.isDirectory();
  if (mustExist && !isDirectory) {
    throw runtime.newErrnoENOTDIRError(path);
  }
  if (!mustExist && isDirectory) {
    throw runtime.newErrnoEEXISTError(dir);
  }
  return result;
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(required = 2, meta = true)
public static IRubyObject link(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  String fromStr = file(from).toString();
  String toStr = file(to).toString();
  int ret = runtime.getPosix().link(fromStr, toStr);
  if (ret != 0) {
    if (runtime.getPosix().isNative()) {
      throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
    } else {
      // In most cases, when there is an error during the call,
      // the POSIX handler throws an exception, but not in case
      // with pure Java POSIX layer (when native support is disabled),
      // so we deal with it like this:
      throw runtime.newErrnoEEXISTError(fromStr + " or " + toStr);
    }
  }
  return runtime.newFixnum(ret);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@JRubyMethod(required = 2, meta = true)
public static IRubyObject link(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  String fromStr = file(from).toString();
  String toStr = file(to).toString();
  int ret = runtime.getPosix().link(fromStr, toStr);
  if (ret != 0) {
    if (runtime.getPosix().isNative()) {
      throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
    } else {
      // In most cases, when there is an error during the call,
      // the POSIX handler throws an exception, but not in case
      // with pure Java POSIX layer (when native support is disabled),
      // so we deal with it like this:
      throw runtime.newErrnoEEXISTError(fromStr + " or " + toStr);
    }
  }
  return runtime.newFixnum(ret);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(required = 2, meta = true)
public static IRubyObject symlink(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  RubyString fromStr = get_path(context, from);
  RubyString toStr = get_path(context, to);
  String tovalue = toStr.getUnicodeValue();
  tovalue = JRubyFile.create(runtime.getCurrentDirectory(), tovalue).getAbsolutePath();
  try {
    if (runtime.getPosix().symlink(fromStr.getUnicodeValue(), tovalue) == -1) {
      if (runtime.getPosix().isNative()) {
        throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
      } else {
        throw runtime.newErrnoEEXISTError(String.format("(%s, %s)", fromStr, toStr));
      }
    }
  } catch (java.lang.UnsatisfiedLinkError ule) {
    throw runtime.newNotImplementedError("symlink() function is unimplemented on this machine");
  }
  
  return RubyFixnum.zero(runtime);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(required = 2, meta = true)
public static IRubyObject link(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  String fromStr = file(from).toString();
  String toStr = file(to).toString();
  int ret = runtime.getPosix().link(fromStr, toStr);
  if (ret != 0) {
    if (runtime.getPosix().isNative()) {
      throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
    } else {
      // In most cases, when there is an error during the call,
      // the POSIX handler throws an exception, but not in case
      // with pure Java POSIX layer (when native support is disabled),
      // so we deal with it like this:
      throw runtime.newErrnoEEXISTError(fromStr + " or " + toStr);
    }
  }
  return runtime.newFixnum(ret);
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

@JRubyMethod(required = 2, meta = true)
public static IRubyObject link(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  String fromStr = file(from).toString();
  String toStr = file(to).toString();
  int ret = runtime.getPosix().link(fromStr, toStr);
  if (ret != 0) {
    if (runtime.getPosix().isNative()) {
      throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
    } else {
      // In most cases, when there is an error during the call,
      // the POSIX handler throws an exception, but not in case
      // with pure Java POSIX layer (when native support is disabled),
      // so we deal with it like this:
      throw runtime.newErrnoEEXISTError(fromStr + " or " + toStr);
    }
  }
  return runtime.newFixnum(ret);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

@JRubyMethod(required = 2, meta = true)
public static IRubyObject symlink(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  RubyString fromStr = get_path(context, from);
  RubyString toStr = get_path(context, to);
  String tovalue = toStr.getUnicodeValue();
  tovalue = JRubyFile.create(runtime.getCurrentDirectory(), tovalue).getAbsolutePath();
  try {
    if (runtime.getPosix().symlink(fromStr.getUnicodeValue(), tovalue) == -1) {
      if (runtime.getPosix().isNative()) {
        throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
      } else {
        throw runtime.newErrnoEEXISTError(String.format("(%s, %s)", fromStr, toStr));
      }
    }
  } catch (java.lang.UnsatisfiedLinkError ule) {
    throw runtime.newNotImplementedError("symlink() function is unimplemented on this machine");
  }
  
  return RubyFixnum.zero(runtime);
}

代码示例来源:origin: org.jruby/jruby-complete

@JRubyMethod(required = 2, meta = true)
public static IRubyObject symlink(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  RubyString fromStr = StringSupport.checkEmbeddedNulls(runtime, get_path(context, from));
  RubyString toStr = StringSupport.checkEmbeddedNulls(runtime, get_path(context, to));
  String tovalue = toStr.getUnicodeValue();
  tovalue = JRubyFile.create(runtime.getCurrentDirectory(), tovalue).getAbsolutePath();
  try {
    if (runtime.getPosix().symlink(fromStr.getUnicodeValue(), tovalue) == -1) {
      if (runtime.getPosix().isNative()) {
        throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
      } else {
        throw runtime.newErrnoEEXISTError(String.format("(%s, %s)", fromStr, toStr));
      }
    }
  } catch (java.lang.UnsatisfiedLinkError ule) {
    throw runtime.newNotImplementedError("symlink() function is unimplemented on this machine");
  }
  return RubyFixnum.zero(runtime);
}

代码示例来源:origin: org.jruby/jruby-core

@JRubyMethod(required = 2, meta = true)
public static IRubyObject symlink(ThreadContext context, IRubyObject recv, IRubyObject from, IRubyObject to) {
  Ruby runtime = context.runtime;
  RubyString fromStr = StringSupport.checkEmbeddedNulls(runtime, get_path(context, from));
  RubyString toStr = StringSupport.checkEmbeddedNulls(runtime, get_path(context, to));
  String tovalue = toStr.getUnicodeValue();
  tovalue = JRubyFile.create(runtime.getCurrentDirectory(), tovalue).getAbsolutePath();
  try {
    if (runtime.getPosix().symlink(fromStr.getUnicodeValue(), tovalue) == -1) {
      if (runtime.getPosix().isNative()) {
        throw runtime.newErrnoFromInt(runtime.getPosix().errno(), String.format("(%s, %s)", fromStr, toStr));
      } else {
        throw runtime.newErrnoEEXISTError(String.format("(%s, %s)", fromStr, toStr));
      }
    }
  } catch (java.lang.UnsatisfiedLinkError ule) {
    throw runtime.newNotImplementedError("symlink() function is unimplemented on this machine");
  }
  return RubyFixnum.zero(runtime);
}

代码示例来源:origin: org.jruby/jruby-core

tmpFile = tmp;
} else {
  throw context.runtime.newErrnoEEXISTError(getPath());

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

throw getRuntime().newErrnoEISDirError();
} catch (FileExistsException ex) {
  throw getRuntime().newErrnoEEXISTError(path);
} catch (IOException ex) {
  throw getRuntime().newIOErrorFromException(ex);

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

throw runtime.newErrnoEISDirError(path);
} catch (FileExistsException fee) {
  throw runtime.newErrnoEEXISTError(path);
} catch (IOException ioe) {
  throw runtime.newIOErrorFromException(ioe);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

throw runtime.newErrnoEISDirError(path);
} catch (FileExistsException fee) {
  throw runtime.newErrnoEEXISTError(path);
} catch (IOException ioe) {
  throw runtime.newIOErrorFromException(ioe);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private ChannelDescriptor sysopen(String path, ModeFlags modes, int perm) {
  try {
    ChannelDescriptor descriptor = ChannelDescriptor.open(
        getRuntime().getCurrentDirectory(),
        path,
        modes,
        perm,
        getRuntime().getPosix(),
        getRuntime().getJRubyClassLoader());
    // TODO: check if too many open files, GC and try again
    return descriptor;
  } catch (PermissionDeniedException pde) {
    // PDException can be thrown only when creating the file and
    // permission is denied.  See JavaDoc of PermissionDeniedException.
    throw getRuntime().newErrnoEACCESError(path);
  } catch (FileNotFoundException fnfe) {
    // FNFException can be thrown in both cases, when the file
    // is not found, or when permission is denied.
    if (Ruby.isSecurityRestricted() || new File(path).exists()) {
      throw getRuntime().newErrnoEACCESError(path);
    }
    throw getRuntime().newErrnoENOENTError(path);
  } catch (DirectoryAsFileException dafe) {
    throw getRuntime().newErrnoEISDirError();
  } catch (FileExistsException fee) {
    throw getRuntime().newErrnoEEXISTError(path);
  } catch (IOException ioe) {
    throw getRuntime().newIOErrorFromException(ioe);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private ChannelDescriptor sysopen(String path, ModeFlags modes, int perm) {
  try {
    ChannelDescriptor descriptor = ChannelDescriptor.open(
        getRuntime().getCurrentDirectory(),
        path,
        modes,
        perm,
        getRuntime().getPosix(),
        getRuntime().getJRubyClassLoader());
    // TODO: check if too many open files, GC and try again
    return descriptor;
  } catch (PermissionDeniedException pde) {
    // PDException can be thrown only when creating the file and
    // permission is denied.  See JavaDoc of PermissionDeniedException.
    throw getRuntime().newErrnoEACCESError(path);
  } catch (FileNotFoundException fnfe) {
    // FNFException can be thrown in both cases, when the file
    // is not found, or when permission is denied.
    if (Ruby.isSecurityRestricted() || new File(path).exists()) {
      throw getRuntime().newErrnoEACCESError(path);
    }
    throw getRuntime().newErrnoENOENTError(path);
  } catch (DirectoryAsFileException dafe) {
    throw getRuntime().newErrnoEISDirError();
  } catch (FileExistsException fee) {
    throw getRuntime().newErrnoEEXISTError(path);
  } catch (IOException ioe) {
    throw getRuntime().newIOErrorFromException(ioe);
  }
}

相关文章

Ruby类方法