org.apache.commons.cli.ParseException.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(393)

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

ParseException.<init>介绍

[英]Construct a new ParseException with the specified detail message.
[中]用指定的详细信息构造一个新的ParseException

代码示例

代码示例来源:origin: commons-cli/commons-cli

/**
 * Returns the URL represented by <code>str</code>.
 *
 * @param str the URL string
 * @return The URL in <code>str</code> is well-formed
 * @throws ParseException if the URL in <code>str</code> is not well-formed
 */
public static URL createURL(String str) throws ParseException
{
  try
  {
    return new URL(str);
  }
  catch (MalformedURLException e)
  {
    throw new ParseException("Unable to parse the URL: " + str);
  }
}

代码示例来源:origin: commons-cli/commons-cli

/**
 * Returns the class whose name is <code>classname</code>.
 *
 * @param classname the class name
 * @return The class if it is found
 * @throws ParseException if the class could not be found
 */
public static Class<?> createClass(String classname) throws ParseException
{
  try
  {
    return Class.forName(classname);
  }
  catch (ClassNotFoundException e)
  {
    throw new ParseException("Unable to find the class: " + classname);
  }
}

代码示例来源:origin: apache/hive

private void printAndExit(String reason) throws ParseException {
 if (reason != null) {
  System.err.println(reason);
 }
 HelpFormatter formatter = new HelpFormatter();
 formatter.printHelp("schemaTool", cmdLineOptions);
 if (reason != null) {
  throw new ParseException(reason);
 } else {
  System.exit(0);
 }
}

代码示例来源:origin: alibaba/jstorm

@Override
  public void process(Config conf, CommandLine commandLine) throws ParseException {
    for (String s : commandLine.getOptionValues("D")) {
      String[] keyval = s.split("=", 2);
      if (keyval.length != 2)
        throw new ParseException("Invalid option value `" + s + "'");
      conf.putAll((Map) yaml.load(keyval[0] + ": " + keyval[1]));
    }
  }
}

代码示例来源:origin: twitter/distributedlog

static DLSN parseDLSN(String dlsnStr) throws ParseException {
  if (dlsnStr.equals("InitialDLSN")) {
    return DLSN.InitialDLSN;
  }
  String[] parts = dlsnStr.split(",");
  if (parts.length != 3) {
    throw new ParseException("Invalid dlsn : " + dlsnStr);
  }
  try {
    return new DLSN(Long.parseLong(parts[0]), Long.parseLong(parts[1]), Long.parseLong(parts[2]));
  } catch (Exception nfe) {
    throw new ParseException("Invalid dlsn : " + dlsnStr);
  }
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (!cmdline.hasOption("s")) {
    throw new ParseException("No stream name provided.");
  }
  streamName = cmdline.getOptionValue("s");
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (!cmdline.hasOption("d")) {
    throw new ParseException("No DLSN provided");
  }
  String[] dlsnStrs = cmdline.getOptionValue("d").split(",");
  if (dlsnStrs.length != 3) {
    throw new ParseException("Invalid DLSN : " + cmdline.getOptionValue("d"));
  }
  dlsn = new DLSN(Long.parseLong(dlsnStrs[0]), Long.parseLong(dlsnStrs[1]), Long.parseLong(dlsnStrs[2]));
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (!cmdline.hasOption("s")) {
    throw new ParseException("No stream to set ACL");
  }
  stream = cmdline.getOptionValue("s");
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (!cmdline.hasOption("e")) {
    throw new ParseException("No action 'enable/disable' provided");
  }
  enabled = Boolean.parseBoolean(cmdline.getOptionValue("e"));
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  dryrun = cmdline.hasOption("d");
  verbose = cmdline.hasOption("v");
  force = !dryrun && cmdline.hasOption("f");
  if (!cmdline.hasOption("l")) {
    throw new ParseException("No streams provided to repair");
  }
  String streamsList = cmdline.getOptionValue("l");
  Collections.addAll(streams, streamsList.split(","));
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (!cmdline.hasOption("s")) {
    throw new ParseException("No stream to set ACL");
  }
  stream = cmdline.getOptionValue("s");
}

代码示例来源:origin: alibaba/jstorm

@Override
  public void process(Config conf, CommandLine commandLine) throws ParseException {
    try {
      for (String f : commandLine.getOptionValues("conf")) {
        Map m = loadConf(f);
        if (m == null)
          throw new ParseException("Empty configuration file " + f);
        conf.putAll(m);
      }
    } catch (IOException e) {
      throw new ParseException(e.getMessage());
    }
  }
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (!cmdline.hasOption("l")) {
    throw new ParseException("No ledger provided.");
  }
  ledgerId = Long.parseLong(cmdline.getOptionValue("l"));
}

代码示例来源:origin: twitter/distributedlog

protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  if (!cmdline.hasOption("H")) {
    throw new ParseException("No proxy address provided");
  }
  address = DLSocketAddress.parseSocketAddress(cmdline.getOptionValue("H"));
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (cmdline.hasOption("r")) {
    streamPrefix = cmdline.getOptionValue("r");
  }
  if (cmdline.hasOption("e")) {
    streamExpression = cmdline.getOptionValue("e");
  }
  if (null == streamPrefix || null == streamExpression) {
    throw new ParseException("Please specify stream prefix & expression.");
  }
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  dryrun = cmdline.hasOption("d");
  verbose = cmdline.hasOption("v");
  if (cmdline.hasOption("cy")) {
    try {
      concurrency = Integer.parseInt(cmdline.getOptionValue("cy"));
    } catch (NumberFormatException nfe) {
      throw new ParseException("Invalid concurrency value : " + cmdline.getOptionValue("cy"));
    }
  }
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (cmdline.hasOption("t")) {
    concurrency = Integer.parseInt(cmdline.getOptionValue("t"));
    if (concurrency <= 0) {
      throw new ParseException("Invalid concurrency value : " + concurrency + ": it must be greater or equal to 0.");
    }
  }
  if (cmdline.hasOption("ap")) {
    allocationPoolPath = cmdline.getOptionValue("ap");
    if (!allocationPoolPath.startsWith(".") || !allocationPoolPath.contains("allocation")) {
      throw new ParseException("Invalid allocation pool path : " + allocationPoolPath + ": it must starts with a '.' and must contains 'allocation'");
    }
  }
}

代码示例来源:origin: twitter/distributedlog

protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  if (!cmdline.hasOption("u")) {
    throw new ParseException("No proxy serverset provided.");
  }
  uri = URI.create(cmdline.getOptionValue("u"));
  if (cmdline.hasOption("sp")) {
    String sourceProxyStr = cmdline.getOptionValue("sp");
    try {
      DLSocketAddress.parseSocketAddress(sourceProxyStr);
    } catch (IllegalArgumentException iae) {
      throw new ParseException("Invalid source proxy " + sourceProxyStr + " : " + iae.getMessage());
    }
    this.source = sourceProxyStr;
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
  public void process(Config conf, CommandLine commandLine) throws ParseException {
    try {
      List<File> jarFiles = validateFiles(commandLine.getOptionValue("libjars"));
      Map<String, String> jars = new HashMap<>(jarFiles.size());
      List<String> names = new ArrayList<>(jarFiles.size());
      for (File f : jarFiles) {
        jars.put(f.getName(), f.getAbsolutePath());
        names.add(f.getName());
      }
      conf.put(TOPOLOGY_LIB_PATH, jars);
      conf.put(TOPOLOGY_LIB_NAME, names);
    } catch (IOException e) {
      throw new ParseException(e.getMessage());
    }
  }
}

代码示例来源:origin: twitter/distributedlog

@Override
protected void parseCommandLine(CommandLine cmdline) throws ParseException {
  super.parseCommandLine(cmdline);
  String[] args = cmdline.getArgs();
  if (args.length < 1) {
    throw new ParseException("Must specify at least start dlsn.");
  }
  if (args.length >= 1) {
    startDLSN = parseDLSN(args[0]);
  }
  if (args.length >= 2) {
    endDLSN = parseDLSN(args[1]);
  }
}

相关文章