List of usage examples for org.apache.commons.cli ParseException ParseException
public ParseException(String message)
ParseException
with the specified detail message. From source file:de.clusteval.data.dataset.generator.HyperCubeCornersDataSetGenerator.java
@Override protected void handleOptions(CommandLine cmd) throws ParseException { if (cmd.getArgList().size() > 0) throw new ParseException("Unknown parameters: " + Arrays.toString(cmd.getArgs())); if (cmd.hasOption("n")) this.numberOfPoints = Integer.parseInt(cmd.getOptionValue("n")); else/*from w w w .j a v a 2 s. c om*/ this.numberOfPoints = 100; if (cmd.hasOption("d")) this.numberDimensions = Integer.parseInt(cmd.getOptionValue("d")); else this.numberDimensions = 2; if (cmd.hasOption("sd")) this.standardDeviation = Double.parseDouble(cmd.getOptionValue("sd")); else this.standardDeviation = 0.1; }
From source file:epgtools.dumpepgfromts.Main.java
public void start(String[] args) throws org.apache.commons.cli.ParseException { final String fileName; final Long limit; System.out.println("args : " + dumpArgs(args)); final Option fileNameOption = Option.builder("f").required().longOpt("tsfile").desc("ts") .hasArg().type(String.class).build(); final Option limitOption = Option.builder("l").required(false).longOpt("limit").desc( "??(???????100000000)") .hasArg().type(Long.class).build(); Options opts = new Options(); opts.addOption(fileNameOption);//from w w w. j av a 2 s.c o m // opts.addOption(PhysicalChannelNumberOption); opts.addOption(limitOption); CommandLineParser parser = new DefaultParser(); CommandLine cl; HelpFormatter help = new HelpFormatter(); try { // parse options cl = parser.parse(opts, args); fileName = cl.getOptionValue(fileNameOption.getOpt()); if (fileName == null) { throw new ParseException("????????"); } Long xl = null; try { xl = Long.parseUnsignedLong(cl.getOptionValue(limitOption.getOpt())); } catch (NumberFormatException e) { xl = 10000000L; } finally { limit = xl; } LOG.info("Starting application..."); LOG.info("filename : " + fileName); LOG.info("limit : " + limit); FileLoader fl = new FileLoader(new File(fileName), limit); fl.load(); //??? Set<Channel> ch = fl.getChannels(); LOG.info("?? = " + ch.size()); for (Channel c : ch) { LOG.info( "***********************************************************************************************************************************************************************************************************"); LOG.info(c.getString()); LOG.info( "***********************************************************************************************************************************************************************************************************"); } // ? Set<Programme> p = fl.getProgrammes(); LOG.info(" = " + p.size()); for (Programme pg : p) { LOG.info( "***********************************************************************************************************************************************************************************************************"); LOG.info(pg.getString()); LOG.info( "***********************************************************************************************************************************************************************************************************"); } System.gc(); } catch (ParseException e) { // print usage. help.printHelp("My Java Application", opts); throw e; } catch (FileNotFoundException ex) { LOG.fatal("?????", ex); } }
From source file:bachelorthesis.captchabuilder.builder.CaptchaBuildSequenceParser.java
private static CaptchaBuilder parseBuildSequenceOption(BuildSequenceOptions option, String[] buildSequenceOptions, CaptchaBuilder builder) throws ParseException { switch (option) { case BACKGROUND: return BackgroundParser.parse(buildSequenceOptions, builder); case BORDER://from w w w . j a va2 s .c o m return BorderParser.parse(buildSequenceOptions, builder); case GIMP: return GimpyParser.parse(buildSequenceOptions, builder); case NOISE: return NoiseParser.parse(buildSequenceOptions, builder); case TEXT: return TextParser.parse(buildSequenceOptions, builder); default: throw new ParseException("argument not found: " + option.name()); } }
From source file:descriptordump.Main.java
public void start(String args[]) throws DecoderException, ParseException { File inputFile = null;/*from w w w. j a v a 2 s. co m*/ Charset cs = null; final Option charSetOption = Option.builder("c").required(false).longOpt("charset").desc( "?????????????") .hasArg().type(String.class).build(); final Option fileNameOption = Option.builder("f").required().longOpt("filename") .desc("??").hasArg().type(String.class).build(); Options opts = new Options(); opts.addOption(fileNameOption); CommandLineParser parser = new DefaultParser(); CommandLine cl; HelpFormatter help = new HelpFormatter(); try { cl = parser.parse(opts, args); try { cs = Charset.forName(cl.getOptionValue(charSetOption.getOpt())); } catch (Exception e) { LOG.error( "?????????", e); cs = Charset.defaultCharset(); } inputFile = new File(cl.getOptionValue(fileNameOption.getOpt())); if (!inputFile.isFile()) { throw new ParseException("?????????"); } } catch (ParseException e) { // print usage. help.printHelp("My Java Application", opts); } final Set<TABLE_ID> tids = new HashSet<>(); tids.add(TABLE_ID.SDT_THIS_STREAM); tids.add(TABLE_ID.SDT_OTHER_STREAM); tids.add(TABLE_ID.NIT_THIS_NETWORK); tids.add(TABLE_ID.NIT_OTHER_NETWORK); tids.add(TABLE_ID.EIT_THIS_STREAM_8_DAYS); tids.add(TABLE_ID.EIT_THIS_STREAM_NOW_AND_NEXT); tids.add(TABLE_ID.EIT_OTHER_STREAM_8_DAYS); tids.add(TABLE_ID.EIT_OTHER_STREAM_NOW_AND_NEXT); LOG.info("Starting application..."); LOG.info("ts filename : " + inputFile.getAbsolutePath()); LOG.info("charset : " + cs); Set<Section> sections = new HashSet<>(); try { FileInputStream input = new FileInputStream(inputFile); InputStreamReader stream = new InputStreamReader(input, cs); BufferedReader buffer = new BufferedReader(stream); String line; long lines = 0; while ((line = buffer.readLine()) != null) { byte[] b = Hex.decodeHex(line.toCharArray()); Section s = new Section(b); if (s.checkCRC() == CRC_STATUS.NO_CRC_ERROR && tids.contains(s.getTable_id_const())) { sections.add(s); LOG.trace("1????"); } else { LOG.error("?????? = " + s); } lines++; } LOG.info( "?? = " + lines + " ? = " + sections.size()); input.close(); stream.close(); buffer.close(); } catch (FileNotFoundException ex) { LOG.fatal("???????", ex); } catch (IOException ex) { LOG.fatal("???????", ex); } SdtDescGetter sde = new SdtDescGetter(); NitDescGetter nide = new NitDescGetter(); EitDescGetter eide = new EitDescGetter(); for (Section s : sections) { sde.process(s); nide.process(s); eide.process(s); } Set<Descriptor> descs = new HashSet<>(); descs.addAll(sde.getUnmodifiableDest()); descs.addAll(nide.getUnmodifiableDest()); descs.addAll(eide.getUnmodifiableDest()); Set<Integer> dtags = new TreeSet<>(); for (Descriptor d : descs) { dtags.add(d.getDescriptor_tag()); } for (Integer i : dtags) { LOG.info(Integer.toHexString(i)); } }
From source file:com.cloudera.beeswax.Server.java
private static int parsePort(Option opt) throws ParseException { int port = Integer.valueOf(opt.getValue()); if (port < 0 || port > USHRT_MAX) throw new ParseException("Port number must be a number in [0, " + USHRT_MAX + "]"); return port;//from ww w . ja v a2 s . c o m }
From source file:ch.eiafr.cojac.Args.java
private void verifyOptionFormat(Arg arg) throws ParseException { String val = values.get(arg).getValue(); String msg = "bad format for option " + arg; try {// ww w. j av a2s . co m switch (arg) { case BIG_DECIMAL_PRECISION: case JMX_PORT: Integer.parseInt(val); break; case STABILITY_THRESHOLD: Double.parseDouble(val); break; case OPCODES: processOpcodeList(val); break; } } catch (Exception e) { throw new ParseException(msg); } }
From source file:com.dsf.dbxtract.cdc.App.java
private static void parseCommand(CommandLine cmd) throws ConfigurationException, IOException, ParseException { String configFilename;/* w w w. j a v a 2s . c o m*/ Config config; if (cmd.hasOption(PARAM_CONFIG)) { configFilename = cmd.getOptionValue(PARAM_CONFIG); config = new Config(configFilename); } else { throw new InvalidParameterException("Parameter required: --config"); } if (cmd.hasOption(COMMAND_LIST)) { config.listAll(); } else if (cmd.hasOption(COMMAND_START)) { info("Welcome to db-xtract"); // get db-xtract configuration config.report(); // Starts monitor server Monitor.getInstance(config); // Starts service App app = new App(config); app.start(); } else { throw new ParseException("A command is required: --list or --start"); } }
From source file:it.crs4.seal.prq.PrqOptionParser.java
@Override protected CommandLine parseOptions(Configuration conf, String[] args) throws IOException, ParseException { conf.setInt(MinBasesThresholdConfigName, DefaultMinBasesThreshold); conf.setBoolean(DropFailedFilterConfigName, DropFailedFilterDefault); conf.setBoolean(WarningOnlyIfUnpairedConfigName, WarningOnlyIfUnpairedDefault); conf.setInt(NumReadsExpectedConfigName, NumReadsExpectedDefault); CommandLine line = super.parseOptions(conf, args); /* **** handle deprected properties **** */ if (conf.get(PrqOptionParser.OLD_INPUT_FORMAT_CONF) != null) { throw new ParseException("The property " + PrqOptionParser.OLD_INPUT_FORMAT_CONF + " is no longer supported.\n" + "Please use the command line option --input-format instead."); }/* w ww. j a v a 2 s .c o m*/ Utils.checkDeprecatedProp(conf, LOG, MinBasesThresholdConfigName_deprecated, MinBasesThresholdConfigName); Utils.checkDeprecatedProp(conf, LOG, DropFailedFilterConfigName_deprecated, DropFailedFilterConfigName); Utils.checkDeprecatedProp(conf, LOG, WarningOnlyIfUnpairedConfigName_deprecated, WarningOnlyIfUnpairedConfigName); // Let the deprecated properties override the new ones, unless the new ones have a non-default value. // If the new property has a non-default value, it must have been set by the user. // If, on the other hand, the deprecated property has a value, it must have been set by the user since // we're not setting them here. if (conf.get(MinBasesThresholdConfigName_deprecated) != null && conf.getInt(MinBasesThresholdConfigName, DefaultMinBasesThreshold) == DefaultMinBasesThreshold) { conf.setInt(MinBasesThresholdConfigName, conf.getInt(MinBasesThresholdConfigName_deprecated, DefaultMinBasesThreshold)); } if (conf.get(DropFailedFilterConfigName_deprecated) != null && conf.getBoolean(DropFailedFilterConfigName, DropFailedFilterDefault) == DropFailedFilterDefault) { conf.setBoolean(DropFailedFilterConfigName, conf.getBoolean(DropFailedFilterConfigName_deprecated, DropFailedFilterDefault)); } if (conf.get(WarningOnlyIfUnpairedConfigName_deprecated) != null && conf.getBoolean(WarningOnlyIfUnpairedConfigName, WarningOnlyIfUnpairedDefault) == WarningOnlyIfUnpairedDefault) { conf.setBoolean(WarningOnlyIfUnpairedConfigName, conf.getBoolean(WarningOnlyIfUnpairedConfigName_deprecated, WarningOnlyIfUnpairedDefault)); } /* **** end handle deprecated properties **** */ if (line.hasOption(opt_traditionalIds.getOpt())) conf.setBoolean(PairReadsQSeq.PRQ_CONF_TRADITIONAL_IDS, true); if (line.hasOption(opt_numReads.getOpt())) { int numReads; try { numReads = Integer.valueOf(line.getOptionValue(opt_numReads.getOpt())); if (numReads <= 0) throw new ParseException("Number of reads per fragment must be >= 0 (got " + numReads + ")"); if (numReads > 2) { throw new ParseException( "Working with more than two reads per template is not supported at the moment.\n" + "If you're interested in seeing this feature implemented contact the Seal developers."); } } catch (NumberFormatException e) { throw new ParseException(e.getMessage()); } conf.setInt(NumReadsExpectedConfigName, numReads); } // set number of reduce tasks to use conf.set(ClusterUtils.NUM_RED_TASKS_PROPERTY, String.valueOf(getNReduceTasks())); return line; }
From source file:dumpsection.Main.java
public void start(String[] args) throws org.apache.commons.cli.ParseException { final String fileName; final Long limit; System.out.println("args : " + dumpArgs(args)); final Option fileNameOption = Option.builder("f").required().longOpt("filename").desc("ts??") .hasArg().type(String.class).build(); final Option limitOption = Option.builder("l").required(false).longOpt("limit") .desc("??(???????EOF??)").hasArg() .type(Long.class).build(); Options opts = new Options(); opts.addOption(fileNameOption);// www . j av a2 s . c o m opts.addOption(limitOption); CommandLineParser parser = new DefaultParser(); CommandLine cl; HelpFormatter help = new HelpFormatter(); try { // parse options cl = parser.parse(opts, args); // handle interface option. fileName = cl.getOptionValue(fileNameOption.getOpt()); if (fileName == null) { throw new ParseException("????????"); } // handlet destination option. Long xl = null; try { xl = Long.parseUnsignedLong(cl.getOptionValue(limitOption.getOpt())); } catch (NumberFormatException e) { xl = null; } finally { limit = xl; } final PROGRAM_ID pids = PROGRAM_ID.SDT_OR_BAT; System.out.println("Starting application..."); System.out.println("filename : " + fileName); System.out.println("limit : " + limit); // your code TsReader reader; if (limit == null) { reader = new TsReader(new File(fileName), pids.getPids()); } else { reader = new TsReader(new File(fileName), pids.getPids(), limit); } Map<Integer, List<TsPacketParcel>> ret = reader.getPackets(); for (Integer pid : ret.keySet()) { try (FileWriter writer = new FileWriter(fileName + "_" + Integer.toHexString(pid) + "_SDT.txt")) { SectionReconstructor sr = new SectionReconstructor(ret.get(pid), pid); for (Section s : sr.getSections()) { String text = Hex.encodeHexString(s.getData()); writer.write(text + "\n"); } writer.flush(); } catch (IOException ex) { LOG.fatal("", ex); } } } catch (ParseException e) { // print usage. help.printHelp("My Java Application", opts); throw e; } catch (FileNotFoundException ex) { LOG.fatal("?????", ex); } }
From source file:de.ncoder.studipsync.ui.StandardUIAdapter.java
public static UIAdapter loadUIAdapter(String classname) throws ParseException, ClassNotFoundException { try {//from ww w .j a v a 2 s.c o m Class<?> clazz = Class.forName(classname); Object instance = clazz.newInstance(); if (!(instance instanceof UIAdapter)) { throw new ParseException(instance + " is not an UI adapter"); } return (UIAdapter) instance; } catch (InstantiationException | IllegalAccessException e) { ParseException pe = new ParseException( "Could not instantiate class " + classname + ". " + e.getMessage()); pe.initCause(e); throw pe; } }