Search in sources :

Example 41 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project tika by apache.

the class FSBatchProcessCLI method execute.

private void execute(String[] args) throws Exception {
    CommandLineParser cliParser = new DefaultParser();
    CommandLine line = cliParser.parse(options, args);
    if (line.hasOption("help")) {
        usage();
        System.exit(BatchProcessDriverCLI.PROCESS_NO_RESTART_EXIT_CODE);
    }
    Map<String, String> mapArgs = new HashMap<String, String>();
    for (Option option : line.getOptions()) {
        String v = option.getValue();
        if (v == null || v.equals("")) {
            v = "true";
        }
        mapArgs.put(option.getOpt(), v);
    }
    BatchProcessBuilder b = new BatchProcessBuilder();
    TikaInputStream is = null;
    BatchProcess process = null;
    try {
        is = getConfigInputStream(args, false);
        process = b.build(is, mapArgs);
    } finally {
        IOUtils.closeQuietly(is);
    }
    final Thread mainThread = Thread.currentThread();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<ParallelFileProcessingResult> futureResult = executor.submit(process);
    ParallelFileProcessingResult result = futureResult.get();
    System.out.println(FINISHED_STRING);
    System.out.println("\n");
    System.out.println(result.toString());
    System.exit(result.getExitStatus());
}
Also used : HashMap(java.util.HashMap) BatchProcess(org.apache.tika.batch.BatchProcess) TikaInputStream(org.apache.tika.io.TikaInputStream) CommandLine(org.apache.commons.cli.CommandLine) ParallelFileProcessingResult(org.apache.tika.batch.ParallelFileProcessingResult) BatchProcessBuilder(org.apache.tika.batch.builders.BatchProcessBuilder) ExecutorService(java.util.concurrent.ExecutorService) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)41 DefaultParser (org.apache.commons.cli.DefaultParser)41 CommandLineParser (org.apache.commons.cli.CommandLineParser)29 ParseException (org.apache.commons.cli.ParseException)28 Options (org.apache.commons.cli.Options)27 HelpFormatter (org.apache.commons.cli.HelpFormatter)13 Option (org.apache.commons.cli.Option)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 Config (com.twitter.heron.spi.common.Config)3 Path (java.nio.file.Path)3 Level (java.util.logging.Level)3 Topology (com.ibm.streamsx.topology.Topology)2 PackingException (com.twitter.heron.spi.packing.PackingException)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 PropertyKey (alluxio.PropertyKey)1