List of usage examples for org.apache.commons.cli CommandLineParser parse
CommandLine parse(Options options, String[] arguments) throws ParseException;
From source file:io.scigraph.owlapi.loader.BatchOwlLoader.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;//from w w w .j ava 2s . c om try { cmd = parser.parse(getOptions(), args); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(BatchOwlLoader.class.getSimpleName(), getOptions()); System.exit(-1); } OwlLoadConfigurationLoader owlLoadConfigurationLoader = new OwlLoadConfigurationLoader( new File(cmd.getOptionValue('c').trim())); OwlLoadConfiguration config = owlLoadConfigurationLoader.loadConfig(); load(config); // TODO: Is Guice causing this to hang? #44 System.exit(0); }
From source file:de.huberlin.german.korpling.laudatioteitool.App.java
public static void main(String[] args) { Options opts = new Options() .addOption(new Option("merge", true, messages.getString("MERGE CONTENT FROM INPUT DIRECTORY INTO ONE TEI HEADER"))) .addOption(new Option("split", true, messages.getString("SPLIT ONE TEI HEADER INTO SEVERAL HEADER FILES"))) .addOption(new Option("validate", true, messages.getString("VALIDATE DIRECTORY OR FILE"))) .addOption(new Option("config", true, messages.getString("CONFIG FILE LOCATION"))) .addOption(new Option("schemecorpus", true, messages.getString("CORPUS SCHEME LOCATION"))) .addOption(new Option("schemedoc", true, messages.getString("DOCUMENT SCHEME LOCATION"))) .addOption(new Option("schemeprep", true, messages.getString("PREPARATION SCHEME LOCATION"))) .addOption(new Option("help", false, messages.getString("SHOW THIS HELP"))); HelpFormatter fmt = new HelpFormatter(); String usage = "java -jar teitool.jar [options] [output directory/file]"; String header = messages.getString("HELP HEADER"); String footer = messages.getString("HELP FOOTER"); try {//from ww w . j av a2s . c om CommandLineParser cliParser = new PosixParser(); CommandLine cmd = cliParser.parse(opts, args); Properties props = new Properties(); if (cmd.hasOption("config")) { props = readConfig(cmd.getOptionValue("config")); } // end if "config" given fillPropertiesFromCommandLine(props, cmd); if (cmd.hasOption("help")) { fmt.printHelp(usage, header, opts, footer); } else if (cmd.hasOption("validate")) { validate(cmd.getOptionValue("validate"), props.getProperty("schemecorpus"), props.getProperty("schemedoc"), props.getProperty("schemeprep")); } else if (cmd.hasOption("merge")) { if (cmd.getArgs().length != 1) { System.out.println(messages.getString("YOU NEED TO GIVE AT AN OUTPUT FILE AS ARGUMENT")); System.exit(-1); } MergeTEI merge = new MergeTEI(new File(cmd.getOptionValue("merge")), new File(cmd.getArgs()[0]), props.getProperty("schemecorpus"), props.getProperty("schemedoc"), props.getProperty("schemeprep")); merge.merge(); System.exit(0); } else if (cmd.hasOption("split")) { if (cmd.getArgs().length != 1) { System.out.println(messages.getString("YOU NEED TO GIVE AT AN OUTPUT DIRECTORY AS ARGUMENT")); System.exit(-1); } SplitTEI split = new SplitTEI(new File(cmd.getOptionValue("split")), new File(cmd.getArgs()[0]), props.getProperty("schemecorpus"), props.getProperty("schemedoc"), props.getProperty("schemeprep")); split.split(); System.exit(0); } else { fmt.printHelp(usage, header, opts, footer); } } catch (ParseException ex) { System.err.println(ex.getMessage()); fmt.printHelp(usage, header, opts, footer); } catch (LaudatioException ex) { System.err.println(ex.getMessage()); } catch (UnsupportedOperationException ex) { System.err.println(ex.getMessage()); } System.exit(1); }
From source file:com.ctriposs.rest4j.tools.data.FilterSchemaGenerator.java
public static void main(String[] args) { final CommandLineParser parser = new GnuParser(); CommandLine cl = null;/*w w w. j av a 2 s .com*/ try { cl = parser.parse(_options, args); } catch (ParseException e) { _log.error("Invalid arguments: " + e.getMessage()); reportInvalidArguments(); } final String[] directoryArgs = cl.getArgs(); if (directoryArgs.length != 2) { reportInvalidArguments(); } final File sourceDirectory = new File(directoryArgs[0]); if (!sourceDirectory.exists()) { _log.error(sourceDirectory.getPath() + " does not exist"); System.exit(1); } if (!sourceDirectory.isDirectory()) { _log.error(sourceDirectory.getPath() + " is not a directory"); System.exit(1); } final URI sourceDirectoryURI = sourceDirectory.toURI(); final File outputDirectory = new File(directoryArgs[1]); if (outputDirectory.exists() && !sourceDirectory.isDirectory()) { _log.error(outputDirectory.getPath() + " is not a directory"); System.exit(1); } final boolean isAvroMode = cl.hasOption('a'); final String predicateExpression = cl.getOptionValue('e'); final Predicate predicate = PredicateExpressionParser.parse(predicateExpression); final Collection<File> sourceFiles = FileUtil.listFiles(sourceDirectory, null); int exitCode = 0; for (File sourceFile : sourceFiles) { try { final ValidationOptions val = new ValidationOptions(); val.setAvroUnionMode(isAvroMode); final SchemaParser schemaParser = new SchemaParser(); schemaParser.setValidationOptions(val); schemaParser.parse(new FileInputStream(sourceFile)); if (schemaParser.hasError()) { _log.error("Error parsing " + sourceFile.getPath() + ": " + schemaParser.errorMessageBuilder().toString()); exitCode = 1; continue; } final DataSchema originalSchema = schemaParser.topLevelDataSchemas().get(0); if (!(originalSchema instanceof NamedDataSchema)) { _log.error(sourceFile.getPath() + " does not contain valid NamedDataSchema"); exitCode = 1; continue; } final SchemaParser filterParser = new SchemaParser(); filterParser.setValidationOptions(val); final NamedDataSchema filteredSchema = Filters.removeByPredicate((NamedDataSchema) originalSchema, predicate, filterParser); if (filterParser.hasError()) { _log.error("Error applying predicate: " + filterParser.errorMessageBuilder().toString()); exitCode = 1; continue; } final String relativePath = sourceDirectoryURI.relativize(sourceFile.toURI()).getPath(); final String outputFilePath = outputDirectory.getPath() + File.separator + relativePath; final File outputFile = new File(outputFilePath); final File outputFileParent = outputFile.getParentFile(); outputFileParent.mkdirs(); if (!outputFileParent.exists()) { _log.error("Unable to write filtered schema to " + outputFileParent.getPath()); exitCode = 1; continue; } FileOutputStream fout = new FileOutputStream(outputFile); fout.write(filteredSchema.toString().getBytes(RestConstants.DEFAULT_CHARSET)); fout.close(); } catch (IOException e) { _log.error(e.getMessage()); exitCode = 1; } } System.exit(exitCode); }
From source file:com.falcon.orca.Main.java
public static void main(String[] args) throws IOException { Option mode = Option.builder("mo").longOpt("mode").required(true).hasArg(true) .desc("Mode to start the node " + "in, possible values are standalone master slave").build(); Option host = Option.builder("ho").longOpt("host").hasArg(true).desc("Machine name").build(); Options modeOptions = new Options(); modeOptions.addOption(mode);/*from ww w.ja v a 2s.c o m*/ modeOptions.addOption(host); CommandLineParser commandLineParser = new DefaultParser(); ModeHandler handler; final ActorSystem actorSystem = ActorSystem.create(); String machineName = "127.0.0.1"; try { CommandLine commandLine = commandLineParser.parse(modeOptions, args); if (commandLine.hasOption("host")) { machineName = commandLine.getOptionValue("host"); } if (commandLine.hasOption("mode")) { String modeValue = commandLine.getOptionValue("mode"); if ("standalone".equalsIgnoreCase(modeValue)) { handler = new StandAloneHandler(actorSystem); handler.handle(); } else if ("master".equalsIgnoreCase(modeValue)) { handler = new MasterHandler(actorSystem, 1, machineName); handler.handle(); } else if ("slave".equalsIgnoreCase(modeValue)) { handler = new SlaveHandler(actorSystem); handler.handle(); } else { actorSystem.shutdown(); System.out .println("Mode is required, use -mo or --mode, possible values are standalone, master " + "and slave"); } } else { actorSystem.shutdown(); System.out .println("Mode is required, use -mo or --mode, possible values are standalone, master and " + "slave"); } } catch (ParseException e) { actorSystem.shutdown(); System.out.println( "Mode is required, use -mo or --mode, possible values are standalone, master and slave"); } }
From source file:net.aepik.alasca.plugin.schemaquery.SchemaQueryTool.java
/** * Launch this tool.//w ww . jav a 2 s . co m */ public static void main(String[] args) { String inFile = null; String inSyntax = null; boolean attr = false; boolean objt = false; boolean synt = false; // // Parsing options. // CommandLineParser parser = new GnuParser(); try { CommandLine cmdOptions = parser.parse(options, args); inFile = cmdOptions.getOptionValue("i"); inSyntax = cmdOptions.getOptionValue("I"); if (cmdOptions.hasOption("a")) { attr = true; } if (cmdOptions.hasOption("o")) { objt = true; } if (cmdOptions.hasOption("l")) { synt = true; } if (cmdOptions.getOptions().length == 0) { displayHelp(); System.exit(2); } } catch (MissingArgumentException e) { System.out.println("Missing arguments\n"); displayHelp(); System.exit(2); } catch (ParseException e) { System.out.println("Wrong arguments\n"); displayHelp(); System.exit(2); } // // Print query options. // if (synt) { displayAvailableSyntaxes(); System.exit(0); } // // Launch schema. // SchemaSyntax inSchemaSyntax = createSchemaSyntax(inSyntax); if (inSchemaSyntax == null) { System.out.println("Unknow input syntax (" + inSyntax + ")"); System.exit(1); } Schema inSchema = createSchema(inSchemaSyntax, inFile); if (inSchema == null) { System.out.println("Failed to read input schema file (" + inFile + ")"); System.exit(1); } // // List if asks // if (attr) { displayAttributes(inSchema); } if (objt) { displayObjectClasses(inSchema); } System.exit(0); }
From source file:com.genentech.chemistry.openEye.apps.SDFSubRMSD.java
public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option("in", true, "input file oe-supported"); opt.setRequired(true);/*from w w w . ja v a2s. c o m*/ options.addOption(opt); opt = new Option("out", true, "output file oe-supported"); opt.setRequired(false); options.addOption(opt); opt = new Option("fragFile", true, "file with single 3d substructure query"); opt.setRequired(false); options.addOption(opt); opt = new Option("isMDL", false, "if given the fragFile is suposed to be an mdl query file, query features are supported."); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue("in"); String outFile = cmd.getOptionValue("out"); String fragFile = cmd.getOptionValue("fragFile"); // read fragment OESubSearch ss; oemolistream ifs = new oemolistream(fragFile); OEMolBase mol; if (!cmd.hasOption("isMDL")) { mol = new OEGraphMol(); oechem.OEReadMolecule(ifs, mol); ss = new OESubSearch(mol, OEExprOpts.AtomicNumber, OEExprOpts.BondOrder); } else { int aromodel = OEIFlavor.Generic.OEAroModelOpenEye; int qflavor = ifs.GetFlavor(ifs.GetFormat()); ifs.SetFlavor(ifs.GetFormat(), (qflavor | aromodel)); int opts = OEMDLQueryOpts.Default | OEMDLQueryOpts.SuppressExplicitH; OEQMol qmol = new OEQMol(); oechem.OEReadMDLQueryFile(ifs, qmol, opts); ss = new OESubSearch(qmol); mol = qmol; } double nSSatoms = mol.NumAtoms(); double sssCoords[] = new double[mol.GetMaxAtomIdx() * 3]; mol.GetCoords(sssCoords); mol.Clear(); ifs.close(); if (!ss.IsValid()) throw new Error("Invalid query " + args[0]); ifs = new oemolistream(inFile); oemolostream ofs = new oemolostream(outFile); int count = 0; while (oechem.OEReadMolecule(ifs, mol)) { count++; double rmsd = Double.MAX_VALUE; double molCoords[] = new double[mol.GetMaxAtomIdx() * 3]; mol.GetCoords(molCoords); for (OEMatchBase mb : ss.Match(mol, false)) { double r = 0; for (OEMatchPairAtom mp : mb.GetAtoms()) { OEAtomBase asss = mp.getPattern(); double sx = sssCoords[asss.GetIdx() * 3]; double sy = sssCoords[asss.GetIdx() * 3]; double sz = sssCoords[asss.GetIdx() * 3]; OEAtomBase amol = mp.getTarget(); double mx = molCoords[amol.GetIdx() * 3]; double my = molCoords[amol.GetIdx() * 3]; double mz = molCoords[amol.GetIdx() * 3]; r += Math.sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my) + (sz - mz) * (sz - mz)); } r /= nSSatoms; rmsd = Math.min(rmsd, r); } if (rmsd != Double.MAX_VALUE) oechem.OESetSDData(mol, "SSSrmsd", String.format("%.3f", rmsd)); oechem.OEWriteMolecule(ofs, mol); mol.Clear(); } ifs.close(); ofs.close(); mol.delete(); ss.delete(); }
From source file:com.hortonworks.registries.storage.tool.TablesInitializer.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(Option.builder("s").numberOfArgs(1).longOpt(OPTION_SCRIPT_ROOT_PATH) .desc("Root directory of script path").build()); options.addOption(Option.builder("c").numberOfArgs(1).longOpt(OPTION_CONFIG_FILE_PATH) .desc("Config file path").build()); options.addOption(Option.builder("m").numberOfArgs(1).longOpt(OPTION_MYSQL_JAR_URL_PATH) .desc("Mysql client jar url to download").build()); options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_CREATE_TABLE) .desc("Execute 'create table' script").build()); options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_DROP_TABLE) .desc("Execute 'drop table' script").build()); options.addOption(Option.builder().hasArg(false).longOpt(OPTION_EXECUTE_CHECK_CONNECTION) .desc("Check the connection for configured data source").build()); CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption(OPTION_CONFIG_FILE_PATH) || !commandLine.hasOption(OPTION_SCRIPT_ROOT_PATH)) { usage(options);// www. ja v a 2 s.c o m System.exit(1); } // either create or drop should be specified, not both boolean executeCreate = commandLine.hasOption(OPTION_EXECUTE_CREATE_TABLE); boolean executeDrop = commandLine.hasOption(OPTION_EXECUTE_DROP_TABLE); boolean checkConnection = commandLine.hasOption(OPTION_EXECUTE_CHECK_CONNECTION); boolean moreThanOneOperationIsSpecified = executeCreate == executeDrop ? executeCreate : checkConnection; boolean noOperationSpecified = !(executeCreate || executeDrop || checkConnection); if (moreThanOneOperationIsSpecified) { System.out.println( "Only one operation can be execute at once, please select 'create' or 'drop', or 'check-connection'."); System.exit(1); } else if (noOperationSpecified) { System.out.println( "One of 'create', 'drop', 'check-connection' operation should be specified to execute."); System.exit(1); } String confFilePath = commandLine.getOptionValue(OPTION_CONFIG_FILE_PATH); String scriptRootPath = commandLine.getOptionValue(OPTION_SCRIPT_ROOT_PATH); String mysqlJarUrl = commandLine.getOptionValue(OPTION_MYSQL_JAR_URL_PATH); StorageProviderConfiguration storageProperties; try { Map<String, Object> conf = Utils.readConfig(confFilePath); StorageProviderConfigurationReader confReader = new StorageProviderConfigurationReader(); storageProperties = confReader.readStorageConfig(conf); } catch (IOException e) { System.err.println("Error occurred while reading config file: " + confFilePath); System.exit(1); throw new IllegalStateException("Shouldn't reach here"); } String bootstrapDirPath = null; try { bootstrapDirPath = System.getProperty("bootstrap.dir"); MySqlDriverHelper.downloadMySQLJarIfNeeded(storageProperties, bootstrapDirPath, mysqlJarUrl); } catch (Exception e) { System.err.println("Error occurred while downloading MySQL jar. bootstrap dir: " + bootstrapDirPath); System.exit(1); throw new IllegalStateException("Shouldn't reach here"); } try { SQLScriptRunner sqlScriptRunner = new SQLScriptRunner(storageProperties); try { sqlScriptRunner.initializeDriver(); } catch (ClassNotFoundException e) { System.err.println( "Driver class is not found in classpath. Please ensure that driver is in classpath."); System.exit(1); } if (checkConnection) { if (!sqlScriptRunner.checkConnection()) { System.exit(1); } } else if (executeDrop) { doExecuteDrop(sqlScriptRunner, storageProperties, scriptRootPath); } else { // executeCreate doExecuteCreate(sqlScriptRunner, storageProperties, scriptRootPath); } } catch (IOException e) { System.err.println("Error occurred while reading script file. Script root path: " + scriptRootPath); System.exit(1); } }
From source file:com.jolbox.benchmark.BenchmarkLaunch.java
/** * @param args// ww w . j a va 2s . co m * @throws ClassNotFoundException * @throws PropertyVetoException * @throws SQLException * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException * @throws InterruptedException * @throws SecurityException * @throws IllegalArgumentException * @throws NamingException * @throws ParseException * @throws IOException */ public static void main(String[] args) throws ClassNotFoundException, SQLException, PropertyVetoException, IllegalArgumentException, SecurityException, InterruptedException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NamingException, ParseException, IOException { Options options = new Options(); options.addOption("t", "threads", true, "Max number of threads"); options.addOption("s", "stepping", true, "Stepping of threads"); options.addOption("p", "poolsize", true, "Pool size"); options.addOption("h", "help", false, "Help"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("benchmark.jar", options); System.exit(1); } BenchmarkTests.threads = 400; BenchmarkTests.stepping = 5; BenchmarkTests.pool_size = 200; if (cmd.hasOption("t")) { BenchmarkTests.threads = Integer.parseInt(cmd.getOptionValue("t", "400")); } if (cmd.hasOption("s")) { BenchmarkTests.stepping = Integer.parseInt(cmd.getOptionValue("s", "20")); } if (cmd.hasOption("p")) { BenchmarkTests.pool_size = Integer.parseInt(cmd.getOptionValue("p", "200")); } System.out.println("Starting benchmark tests with " + BenchmarkTests.threads + " threads (stepping " + BenchmarkTests.stepping + ") using pool size of " + BenchmarkTests.pool_size + " connections"); new MockJDBCDriver(); BenchmarkTests tests = new BenchmarkTests(); plotLineGraph(tests.testMultiThreadedConstantDelay(0), 0, false); plotLineGraph(tests.testMultiThreadedConstantDelay(10), 10, false); plotLineGraph(tests.testMultiThreadedConstantDelay(25), 25, false); plotLineGraph(tests.testMultiThreadedConstantDelay(50), 50, false); plotLineGraph(tests.testMultiThreadedConstantDelay(75), 75, false); plotBarGraph("Single Thread", "bonecp-singlethread-poolsize-" + BenchmarkTests.pool_size + "-threads-" + BenchmarkTests.threads + ".png", tests.testSingleThread()); plotBarGraph( "Prepared Statement\nSingle Threaded", "bonecp-preparedstatement-single-poolsize-" + BenchmarkTests.pool_size + "-threads-" + BenchmarkTests.threads + ".png", tests.testPreparedStatementSingleThread()); plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(0), 0, true); plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(10), 10, true); plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(25), 25, true); plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(50), 50, true); plotLineGraph(tests.testMultiThreadedConstantDelayWithPreparedStatements(75), 75, true); }
From source file:co.turnus.analysis.partitioning.CommunicationCostPartitioningCli.java
public static void main(String[] args) { try {//from ww w .j av a 2 s .c o m CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(cliOptions, args); Configuration config = parseCommandLine(cmd); // init models AnalysisActivator.init(); // init models AnalysisActivator.init(); // set logger verbosity if (config.getBoolean(VERBOSE, false)) { TurnusLogger.setLevel(TurnusLevel.ALL); } // load trace project File tDir = new File(config.getString(TRACE_PROJECT)); TraceProject project = TraceProject.load(tDir); CommunicationCostPartitioning ccp = new CommunicationCostPartitioning(project); ccp.setConfiguration(config); PartitioningData data = ccp.run(); TurnusLogger.info("Storing results..."); File outPath = new File(config.getString(OUTPUT_PATH)); // store the analysis report String uuid = UUID.randomUUID().toString(); File rFile = new File(outPath, uuid + "." + TurnusExtension.REPORT); Report report = DataFactory.eINSTANCE.createReport(); report.setDate(new Date()); report.setComment("Report with only Communication cost partitioning results analysis"); report.getDataSet().add(data); EcoreHelper.storeEObject(report, new ResourceSetImpl(), rFile); TurnusLogger.info("TURNUS report stored in " + rFile); // store formatted reports String xlsName = config.getString(XLS, ""); if (!xlsName.isEmpty()) { File xlsFile = new File(outPath, xlsName + ".xls"); new XlsPartitioningDataWriter().write(data, xlsFile); TurnusLogger.info("XLS report stored in " + xlsFile); } String bxdfName = config.getString(XCF, ""); if (!bxdfName.isEmpty()) { File xcfFile = new File(outPath, bxdfName + ".xcf"); new XmlPartitioningDataWriter().write(data, xcfFile); TurnusLogger.info("XCF files (one for each configuration) " + "stored in " + outPath); } TurnusLogger.info("Analysis Done!"); } catch (ParseException e) { TurnusLogger.error(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CommunicationCostPartitioningCli.class.getSimpleName(), cliOptions); } catch (Exception e) { TurnusLogger.error(e.getMessage()); } }
From source file:io.bfscan.clueweb12.BuildWarcTrecIdMapping.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("bz2 Wikipedia XML dump file") .create(INPUT_OPTION));//from w ww.j a va2 s. co m options.addOption( OptionBuilder.withArgName("dir").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg() .withDescription("maximum number of documents to index").create(MAX_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("number of indexing threads") .create(THREADS_OPTION)); options.addOption(new Option(OPTIMIZE_OPTION, "merge indexes into a single segment")); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(BuildWarcTrecIdMapping.class.getCanonicalName(), options); System.exit(-1); } String indexPath = cmdline.getOptionValue(INDEX_OPTION); int maxdocs = cmdline.hasOption(MAX_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MAX_OPTION)) : Integer.MAX_VALUE; int threads = cmdline.hasOption(THREADS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(THREADS_OPTION)) : DEFAULT_NUM_THREADS; long startTime = System.currentTimeMillis(); String path = cmdline.getOptionValue(INPUT_OPTION); PrintStream out = new PrintStream(System.out, true, "UTF-8"); Directory dir = FSDirectory.open(new File(indexPath)); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, ANALYZER); config.setOpenMode(OpenMode.CREATE); IndexWriter writer = new IndexWriter(dir, config); LOG.info("Creating index at " + indexPath); LOG.info("Indexing with " + threads + " threads"); FileInputStream fis = null; BufferedReader br = null; try { fis = new FileInputStream(new File(path)); byte[] ignoreBytes = new byte[2]; fis.read(ignoreBytes); // "B", "Z" bytes from commandline tools br = new BufferedReader(new InputStreamReader(new CBZip2InputStream(fis), "UTF8")); ExecutorService executor = Executors.newFixedThreadPool(threads); int cnt = 0; String s; while ((s = br.readLine()) != null) { Runnable worker = new AddDocumentRunnable(writer, s); executor.execute(worker); cnt++; if (cnt % 1000000 == 0) { LOG.info(cnt + " articles added"); } if (cnt >= maxdocs) { break; } } executor.shutdown(); // Wait until all threads are finish while (!executor.isTerminated()) { } LOG.info("Total of " + cnt + " articles indexed."); if (cmdline.hasOption(OPTIMIZE_OPTION)) { LOG.info("Merging segments..."); writer.forceMerge(1); LOG.info("Done!"); } LOG.info("Total elapsed time: " + (System.currentTimeMillis() - startTime) + "ms"); } catch (Exception e) { e.printStackTrace(); } finally { writer.close(); dir.close(); out.close(); br.close(); fis.close(); } }