当前位置: 首页>>代码示例>>Java>>正文


Java ParseException类代码示例

本文整理汇总了Java中org.apache.commons.cli.ParseException的典型用法代码示例。如果您正苦于以下问题:Java ParseException类的具体用法?Java ParseException怎么用?Java ParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ParseException类属于org.apache.commons.cli包,在下文中一共展示了ParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ThompsonTraillCompletenessParameters

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
public ThompsonTraillCompletenessParameters(String[] arguments) throws ParseException {
	super(arguments);

	if (cmd.hasOption("fileName"))
		fileName = cmd.getOptionValue("fileName");

	if (fileName.equals("stdout"))
		useStandardOutput = true;

	if (cmd.hasOption("limit"))
		limit = Integer.parseInt(cmd.getOptionValue("limit"));

	if (cmd.hasOption("offset"))
		offset = Integer.parseInt(cmd.getOptionValue("offset"));

	if (offset > -1 && limit > -1)
		limit += offset;
}
 
开发者ID:pkiraly,项目名称:metadata-qa-marc,代码行数:19,代码来源:ThompsonTraillCompletenessParameters.java

示例2: validArgs

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
/**
 * validArgs checks the command line parameters and verifies the existence of Files.
 *
 * @param args Command line parameters.
 * @return  A list of file(s) that are to be transformed.
 */
static Collection<Path> validArgs(String... args) {
	Collection<Path> returnValue = new LinkedList<>();
	try {
		CommandLine line = cli(args);
		if (shouldContinue(line)) {
			returnValue = checkArgs(line);
		} else {
			formatter.printHelp("convert", options, true);
		}
	} catch (ParseException pe) {
		DEV_LOG.error(CLI_PROBLEM, pe);
	}

	return returnValue;
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:22,代码来源:ConversionEntry.java

示例3: extractTables

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
public void extractTables(CommandLine line) throws ParseException {
    if (line.hasOption('b')) {
        if (line.getArgs().length != 0) {
            throw new ParseException("Filename specified with batch\nTry --help for help");
        }

        File pdfDirectory = new File(line.getOptionValue('b'));
        if (!pdfDirectory.isDirectory()) {
            throw new ParseException("Directory does not exist or is not a directory");
        }
        extractDirectoryTables(line, pdfDirectory);
        return;
    }

    if (line.getArgs().length != 1) {
        throw new ParseException("Need exactly one filename\nTry --help for help");
    }

    File pdfFile = new File(line.getArgs()[0]);
    if (!pdfFile.exists()) {
        throw new ParseException("File does not exist");
    }
    extractFileTables(line, pdfFile);
}
 
开发者ID:redmyers,项目名称:484_P7_1-Java,代码行数:25,代码来源:CommandLineApp.java

示例4: itShouldGetTheExternalFields

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
@Test
public void itShouldGetTheExternalFields() throws ParseException {

	String[] args = new String[] { "-xmlpath",
			"testData/XMLFiles/DelimitedInputAndOutput.xml", "-param",
			"PATH=testData/Input/delimitedInputFile","-param","PATH2=testData/XMLFiles/schema2.xml",
			"-param", "input=input'1","-param", "out&put=output"};
	try {
		ParameterSubstitutor parameterSubstitutor = new ParameterSubstitutor(
				new UserParameters(args));

		String xmlContents = XmlParsingUtils.getXMLStringFromPath(args[1]);

		ParseExternalElements parseExternalElements = new ParseExternalElements(
				parameterSubstitutor.substitute(xmlContents), parameterSubstitutor);

		Document xmlDom = parseExternalElements.getXmlDom();

		NodeList nodes = xmlDom.getElementsByTagName("schema");

		Assert.assertEquals(3,nodes.item(0).getChildNodes().getLength());
	} catch (IOException e) {
		LOG.error("", e);
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:26,代码来源:ParseExternalElementsTest.java

示例5: parseHelpArgument

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
/**
 * Parse the arguments for commands
 * 
 * @param args the argument to be parsed
 * @param helpDescription help information to be printed out
 * @param out Printer
 * @param printGenericCommandUsage whether to print the 
 *              generic command usage defined in ToolRunner
 * @return true when the argument matches help option, false if not
 */
public static boolean parseHelpArgument(String[] args,
    String helpDescription, PrintStream out, boolean printGenericCommandUsage) {
  if (args.length == 1) {
    try {
      CommandLineParser parser = new PosixParser();
      CommandLine cmdLine = parser.parse(helpOptions, args);
      if (cmdLine.hasOption(helpOpt.getOpt())
          || cmdLine.hasOption(helpOpt.getLongOpt())) {
        // should print out the help information
        out.println(helpDescription + "\n");
        if (printGenericCommandUsage) {
          ToolRunner.printGenericCommandUsage(out);
        }
        return true;
      }
    } catch (ParseException pe) {
      return false;
    }
  }
  return false;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:DFSUtil.java

示例6: validateOptions

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
private void validateOptions() throws ParseException {
  if (!compress.equals("none") && !compress.equals("lzo")
      && !compress.equals("gz")) {
    throw new ParseException("Unknown compression scheme: " + compress);
  }

  if (minKeyLen >= maxKeyLen) {
    throw new ParseException(
        "Max key length must be greater than min key length.");
  }

  if (minValLength >= maxValLength) {
    throw new ParseException(
        "Max value length must be greater than min value length.");
  }

  if (minWordLen >= maxWordLen) {
    throw new ParseException(
        "Max word length must be greater than min word length.");
  }
  return;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:TestTFileSeek.java

示例7: MyOptions

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
public MyOptions(String[] args) {
  seed = System.nanoTime();

  try {
    Options opts = buildOptions();
    CommandLineParser parser = new GnuParser();
    CommandLine line = parser.parse(opts, args, true);
    processOptions(line, opts);
    validateOptions();
  }
  catch (ParseException e) {
    System.out.println(e.getMessage());
    System.out.println("Try \"--help\" option for details.");
    setStopProceed();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:TestTFileSeqFileComparison.java

示例8: validateOptions

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
private void validateOptions() throws ParseException {
  if (!compress.equals("none") && !compress.equals("lzo")
      && !compress.equals("gz")) {
    throw new ParseException("Unknown compression scheme: " + compress);
  }

  if (!format.equals("tfile") && !format.equals("seqfile")) {
    throw new ParseException("Unknown file format: " + format);
  }

  if (minWordLen >= maxWordLen) {
    throw new ParseException(
        "Max word length must be greater than min word length.");
  }
  return;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:TestTFileSeqFileComparison.java

示例9: prepareCLI

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
/**
 * @param args cmd params
 */
public QConfig prepareCLI(String[] args) {
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        throw new RuntimeException("Parsing failed.  Reason: ", exp);
    }

    new HelpFormatter().printHelp("command line parameters for QMS QSystem...", options);
    // automatically generate the help statement
    if (line.hasOption("help") || line.hasOption("h") || line.hasOption("?")) {

        System.exit(0);
    }

    QLog.l().logger().info("Properties are ready.");
    return this;
}
 
开发者ID:bcgov,项目名称:sbc-qsystem,代码行数:23,代码来源:QConfig.java

示例10: testDefaults

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
@Test
public void testDefaults() {
	String[] arguments = new String[]{"a-marc-file.mrc"};
	try {
		ValidatorParameters parameters = new ValidatorParameters(arguments);

		assertNotNull(parameters.getArgs());
		assertEquals(1, parameters.getArgs().length);
		assertEquals("a-marc-file.mrc", parameters.getArgs()[0]);

		assertFalse(parameters.doHelp());

		assertNotNull(parameters.getFileName());
		assertEquals("validation-report.txt", parameters.getFileName());
		assertFalse(parameters.useStandardOutput());

		assertEquals(-1, parameters.getLimit());
		assertEquals(-1, parameters.getOffset());

		assertFalse(parameters.doSummary());

		assertEquals(ValidationErrorFormat.TEXT, parameters.getFormat());
	} catch (ParseException e) {
		e.printStackTrace();
	}
}
 
开发者ID:pkiraly,项目名称:metadata-qa-marc,代码行数:27,代码来源:ValidatorParametersTest.java

示例11: validateOptions

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
private void validateOptions() throws ParseException {
  if (!compress.equals("none") && !compress.equals("lzo")
      && !compress.equals("gz") && !compress.equals("snappy")) {
    throw new ParseException("Unknown compression scheme: " + compress);
  }

  if (minKeyLen >= maxKeyLen) {
    throw new ParseException(
        "Max key length must be greater than min key length.");
  }

  if (minValLength >= maxValLength) {
    throw new ParseException(
        "Max value length must be greater than min value length.");
  }

  if (minWordLen >= maxWordLen) {
    throw new ParseException(
        "Max word length must be greater than min word length.");
  }
  return;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:TestHFileSeek.java

示例12: getOptionFirstArgDouble

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
/**
 * Gets the first introduced argument of an option parsed to double.
 * 
 * @param optionArgs The option introduced arguments.
 * @param emptyValue Value which is returned if the option was not introduced, or was introduced
 *        with no argument.
 * @param argsOption The option.
 * @return The option first introduced argument parsed to double.
 *         If the option was not introduced, or was introduced with no argument, emptyValue is
 *         returned.
 * @throws ParseException If an error occurs parsing the argument to double.
 */
private static double getOptionFirstArgDouble(
        String[] optionArgs,
        double emptyValue,
        ArgsOptions argsOption)
        throws ParseException {

    String optionArg = getOptionFirstArg(optionArgs);

    if (optionArg == null || optionArg.isEmpty()) {
        return emptyValue;
    }

    try {
        return Double.parseDouble(optionArg);
    } catch (NumberFormatException numberFormatException) {
        throw new ParseException(String.format(
                "Option %s must be a decimal number.",
                argsOption.display()));
    }

}
 
开发者ID:s3curitybug,项目名称:similarity-uniform-fuzzy-hash,代码行数:34,代码来源:Main.java

示例13: testSearch

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
@Test
public void testSearch() {
	String[] arguments = new String[]{"--search", "920$a=book", "a-marc-file.mrc"};
	try {
		FormatterParameters parameters = new FormatterParameters(arguments);

		assertNotNull(parameters.getSearch());
		assertTrue(parameters.hasSearch());
		assertEquals("920$a=book", parameters.getSearch());
		assertEquals("920$a", parameters.getPath());
		assertEquals("book", parameters.getQuery());

	} catch (ParseException e) {
		e.printStackTrace();
	}
}
 
开发者ID:pkiraly,项目名称:metadata-qa-marc,代码行数:17,代码来源:FormatterParametersTest.java

示例14: parseArguments

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
private static boolean parseArguments(String[] args) {
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine commandLine = parser.parse(OPTIONS, args);

        inputPath = commandLine.getOptionValue(INPUT_PATH.getOpt());
        outputPath = new Path(commandLine.getOptionValue(OUTPUT_PATH.getOpt()));
        pattern = Pattern.compile(commandLine.getOptionValue(PATTERN.getOpt()));
        if (commandLine.hasOption(SAMPLE_FRACTION.getOpt())) {
            sampleFraction = Double.valueOf(commandLine.getOptionValue(SAMPLE_FRACTION.getOpt()));
        }

        if (sampleFraction < 0 || sampleFraction > 1) {
            return false;
        }

        return true;
    } catch (ParseException | IllegalArgumentException e) {
        return false;
    }
}
 
开发者ID:comdirect,项目名称:hadoop-logfile-inputformat,代码行数:22,代码来源:Sample.java

示例15: main

import org.apache.commons.cli.ParseException; //导入依赖的package包/类
public static void main(String[] args) {
    Options options = getOptions();
    CommandLine cmd = null;
    try {
        cmd = parseCommandLineArgs(options, args);
    } catch (ParseException e) {
        System.out.format("%s.%n", e.getMessage());
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ConsoleReader", options);
        System.exit(1);
    }
    
    final String scope = cmd.getOptionValue("scope") == null ? Constants.DEFAULT_SCOPE : cmd.getOptionValue("scope");
    final String streamName = cmd.getOptionValue("name") == null ? Constants.DEFAULT_STREAM_NAME : cmd.getOptionValue("name");
    final String uriString = cmd.getOptionValue("uri") == null ? Constants.DEFAULT_CONTROLLER_URI : cmd.getOptionValue("uri");
    final URI controllerURI = URI.create(uriString);
    
    ConsoleReader reader = new ConsoleReader(scope, streamName, controllerURI);
    reader.run();
}
 
开发者ID:pravega,项目名称:pravega-samples,代码行数:21,代码来源:ConsoleReader.java


注:本文中的org.apache.commons.cli.ParseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。