Example usage for java.lang String startsWith

List of usage examples for java.lang String startsWith

Introduction

In this page you can find the example usage for java.lang String startsWith.

Prototype

public boolean startsWith(String prefix) 

Source Link

Document

Tests if this string starts with the specified prefix.

Usage

From source file:com.github.xmltopdf.JasperPdfGenerator.java

/**.
 * @param args//from ww w.  j  a v  a  2 s.com
 *            the arguments
 * @throws IOException in case IO error
 */
public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        LOG.info(null, USAGE);
        return;
    }
    List<String> templates = new ArrayList<String>();
    List<String> xmls = new ArrayList<String>();
    List<String> types = new ArrayList<String>();
    for (String arg : args) {
        if (arg.endsWith(".jrxml")) {
            templates.add(arg);
        } else if (arg.endsWith(".xml")) {
            xmls.add(arg);
        } else if (arg.startsWith(DOC_TYPE)) {
            types = Arrays
                    .asList(arg.substring(DOC_TYPE.length()).replaceAll("\\s+", "").toUpperCase().split(","));
        }
    }
    if (templates.isEmpty()) {
        LOG.info(null, USAGE);
        return;
    }
    if (types.isEmpty()) {
        types.add("PDF");
    }
    for (String type : types) {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        if (DocType.valueOf(type) != null) {
            new JasperPdfGenerator().createDocument(templates, xmls, os, DocType.valueOf(type));
            os.writeTo(
                    new FileOutputStream(templates.get(0).replaceFirst("\\.jrxml$", "." + type.toLowerCase())));
        }
    }
}

From source file:cc.wikitools.lucene.IndexWikipediaDump.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 ww w  .  j  a  v  a 2s . 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(IndexWikipediaDump.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");
    WikiClean cleaner = new WikiCleanBuilder().withTitle(true).build();

    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");

    try {
        WikipediaBz2DumpInputStream stream = new WikipediaBz2DumpInputStream(path);

        ExecutorService executor = Executors.newFixedThreadPool(threads);
        int cnt = 0;
        String page;
        while ((page = stream.readNext()) != null) {
            String title = cleaner.getTitle(page);

            // These are heuristic specifically for filtering out non-articles in enwiki-20120104.
            if (title.startsWith("Wikipedia:") || title.startsWith("Portal:") || title.startsWith("File:")) {
                continue;
            }

            if (page.contains("#REDIRECT") || page.contains("#redirect") || page.contains("#Redirect")) {
                continue;
            }

            Runnable worker = new AddDocumentRunnable(writer, cleaner, page);
            executor.execute(worker);

            cnt++;
            if (cnt % 10000 == 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();
    }
}

From source file:cz.muni.fi.xklinec.zipstream.App.java

/**
 * Entry point. //from  www .ja  v a2s  .c o  m
 * 
 * @param args
 * @throws FileNotFoundException
 * @throws IOException
 * @throws NoSuchFieldException
 * @throws ClassNotFoundException
 * @throws NoSuchMethodException 
 */
public static void main(String[] args) throws FileNotFoundException, IOException, NoSuchFieldException,
        ClassNotFoundException, NoSuchMethodException, InterruptedException {
    OutputStream fos = null;
    InputStream fis = null;

    if ((args.length != 0 && args.length != 2)) {
        System.err.println(String.format("Usage: app.jar source.apk dest.apk"));
        return;
    } else if (args.length == 2) {
        System.err.println(
                String.format("Will use file [%s] as input file and [%s] as output file", args[0], args[1]));
        fis = new FileInputStream(args[0]);
        fos = new FileOutputStream(args[1]);
    } else if (args.length == 0) {
        System.err.println(String.format("Will use file [STDIN] as input file and [STDOUT] as output file"));
        fis = System.in;
        fos = System.out;
    }

    final Deflater def = new Deflater(9, true);
    ZipArchiveInputStream zip = new ZipArchiveInputStream(fis);

    // List of postponed entries for further "processing".
    List<PostponedEntry> peList = new ArrayList<PostponedEntry>(6);

    // Output stream
    ZipArchiveOutputStream zop = new ZipArchiveOutputStream(fos);
    zop.setLevel(9);

    // Read the archive
    ZipArchiveEntry ze = zip.getNextZipEntry();
    while (ze != null) {

        ZipExtraField[] extra = ze.getExtraFields(true);
        byte[] lextra = ze.getLocalFileDataExtra();
        UnparseableExtraFieldData uextra = ze.getUnparseableExtraFieldData();
        byte[] uextrab = uextra != null ? uextra.getLocalFileDataData() : null;

        // ZipArchiveOutputStream.DEFLATED
        // 

        // Data for entry
        byte[] byteData = Utils.readAll(zip);
        byte[] deflData = new byte[0];
        int infl = byteData.length;
        int defl = 0;

        // If method is deflated, get the raw data (compress again).
        if (ze.getMethod() == ZipArchiveOutputStream.DEFLATED) {
            def.reset();
            def.setInput(byteData);
            def.finish();

            byte[] deflDataTmp = new byte[byteData.length * 2];
            defl = def.deflate(deflDataTmp);

            deflData = new byte[defl];
            System.arraycopy(deflDataTmp, 0, deflData, 0, defl);
        }

        System.err.println(String.format(
                "ZipEntry: meth=%d " + "size=%010d isDir=%5s " + "compressed=%07d extra=%d lextra=%d uextra=%d "
                        + "comment=[%s] " + "dataDesc=%s " + "UTF8=%s " + "infl=%07d defl=%07d " + "name [%s]",
                ze.getMethod(), ze.getSize(), ze.isDirectory(), ze.getCompressedSize(),
                extra != null ? extra.length : -1, lextra != null ? lextra.length : -1,
                uextrab != null ? uextrab.length : -1, ze.getComment(),
                ze.getGeneralPurposeBit().usesDataDescriptor(), ze.getGeneralPurposeBit().usesUTF8ForNames(),
                infl, defl, ze.getName()));

        final String curName = ze.getName();

        // META-INF files should be always on the end of the archive, 
        // thus add postponed files right before them
        if (curName.startsWith("META-INF") && peList.size() > 0) {
            System.err.println(
                    "Now is the time to put things back, but at first, I'll perform some \"facelifting\"...");

            // Simulate som evil being done
            Thread.sleep(5000);

            System.err.println("OK its done, let's do this.");
            for (PostponedEntry pe : peList) {
                System.err.println(
                        "Adding postponed entry at the end of the archive! deflSize=" + pe.deflData.length
                                + "; inflSize=" + pe.byteData.length + "; meth: " + pe.ze.getMethod());

                pe.dump(zop, false);
            }

            peList.clear();
        }

        // Capturing interesting files for us and store for later.
        // If the file is not interesting, send directly to the stream.
        if ("classes.dex".equalsIgnoreCase(curName) || "AndroidManifest.xml".equalsIgnoreCase(curName)) {
            System.err.println("### Interesting file, postpone sending!!!");

            PostponedEntry pe = new PostponedEntry(ze, byteData, deflData);
            peList.add(pe);
        } else {
            // Write ZIP entry to the archive
            zop.putArchiveEntry(ze);
            // Add file data to the stream
            zop.write(byteData, 0, infl);
            zop.closeArchiveEntry();
        }

        ze = zip.getNextZipEntry();
    }

    // Cleaning up stuff
    zip.close();
    fis.close();

    zop.finish();
    zop.close();
    fos.close();

    System.err.println("THE END!");
}

From source file:TransactedTalk.java

/** Main program entry point. */
public static void main(String argv[]) {

    // Is there anything to do?
    if (argv.length == 0) {
        printUsage();/*from ww  w  .java2 s.  c  o  m*/
        System.exit(1);
    }

    // Values to be read from parameters
    String broker = DEFAULT_BROKER_NAME;
    String username = null;
    String password = DEFAULT_PASSWORD;
    String qSender = null;
    String qReceiver = null;

    // Check parameters
    for (int i = 0; i < argv.length; i++) {
        String arg = argv[i];

        // Options
        if (!arg.startsWith("-")) {
            System.err.println("error: unexpected argument - " + arg);
            printUsage();
            System.exit(1);
        } else {
            if (arg.equals("-b")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing broker name:port");
                    System.exit(1);
                }
                broker = argv[++i];
                continue;
            }

            if (arg.equals("-u")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing user name");
                    System.exit(1);
                }
                username = argv[++i];
                continue;
            }

            if (arg.equals("-p")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing password");
                    System.exit(1);
                }
                password = argv[++i];
                continue;
            }

            if (arg.equals("-qr")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing receive queue parameter");
                    System.exit(1);
                }
                qReceiver = argv[++i];
                continue;
            }

            if (arg.equals("-qs")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing send queue parameter");
                    System.exit(1);
                }
                qSender = argv[++i];
                continue;
            }

            if (arg.equals("-h")) {
                printUsage();
                System.exit(1);
            }
        }
    }

    // Check values read in.
    if (username == null) {
        System.err.println("error: user name must be supplied");
        printUsage();
        System.exit(1);
    }

    if (qReceiver == null && qSender == null) {
        System.err.println("error: receive queue, or send queue, must be supplied");
        printUsage();
        System.exit(1);
    }

    // Start the JMS client for the "Talk".
    TransactedTalk tranTalk = new TransactedTalk();
    tranTalk.talker(broker, username, password, qReceiver, qSender);

}

From source file:examples.mail.IMAPImportMbox.java

public static void main(String[] args) throws IOException {
    if (args.length < 2) {
        System.err.println(/*  w w  w. ja  va  2s . c  o m*/
                "Usage: IMAPImportMbox imap[s]://user:password@host[:port]/folder/path <mboxfile> [selectors]");
        System.err.println("\tWhere: a selector is a list of numbers/number ranges - 1,2,3-10"
                + " - or a list of strings to match in the initial From line");
        System.exit(1);
    }

    final URI uri = URI.create(args[0]);
    final String file = args[1];

    final File mbox = new File(file);
    if (!mbox.isFile() || !mbox.canRead()) {
        throw new IOException("Cannot read mailbox file: " + mbox);
    }

    String path = uri.getPath();
    if (path == null || path.length() < 1) {
        throw new IllegalArgumentException("Invalid folderPath: '" + path + "'");
    }
    String folder = path.substring(1); // skip the leading /

    List<String> contains = new ArrayList<String>(); // list of strings to find
    BitSet msgNums = new BitSet(); // list of message numbers

    for (int i = 2; i < args.length; i++) {
        String arg = args[i];
        if (arg.matches("\\d+(-\\d+)?(,\\d+(-\\d+)?)*")) { // number,m-n
            for (String entry : arg.split(",")) {
                String[] parts = entry.split("-");
                if (parts.length == 2) { // m-n
                    int low = Integer.parseInt(parts[0]);
                    int high = Integer.parseInt(parts[1]);
                    for (int j = low; j <= high; j++) {
                        msgNums.set(j);
                    }
                } else {
                    msgNums.set(Integer.parseInt(entry));
                }
            }
        } else {
            contains.add(arg); // not a number/number range
        }
    }
    //        System.out.println(msgNums.toString());
    //        System.out.println(java.util.Arrays.toString(contains.toArray()));

    // Connect and login
    final IMAPClient imap = IMAPUtils.imapLogin(uri, 10000, null);

    int total = 0;
    int loaded = 0;
    try {
        imap.setSoTimeout(6000);

        final BufferedReader br = new BufferedReader(new FileReader(file)); // TODO charset?

        String line;
        StringBuilder sb = new StringBuilder();
        boolean wanted = false; // Skip any leading rubbish
        while ((line = br.readLine()) != null) {
            if (line.startsWith("From ")) { // start of message; i.e. end of previous (if any)
                if (process(sb, imap, folder, total)) { // process previous message (if any)
                    loaded++;
                }
                sb.setLength(0);
                total++;
                wanted = wanted(total, line, msgNums, contains);
            } else if (startsWith(line, PATFROM)) { // Unescape ">+From " in body text
                line = line.substring(1);
            }
            // TODO process first Received: line to determine arrival date?
            if (wanted) {
                sb.append(line);
                sb.append(CRLF);
            }
        }
        br.close();
        if (wanted && process(sb, imap, folder, total)) { // last message (if any)
            loaded++;
        }
    } catch (IOException e) {
        System.out.println(imap.getReplyString());
        e.printStackTrace();
        System.exit(10);
        return;
    } finally {
        imap.logout();
        imap.disconnect();
    }
    System.out.println("Processed " + total + " messages, loaded " + loaded);
}

From source file:mlbench.pagerank.PagerankNaive.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, InterruptedException {
    try {/*from ww w  . java 2s  .com*/
        parseArgs(args);
        HashMap<String, String> conf = new HashMap<String, String>();
        initConf(conf);
        MPI_D.Init(args, MPI_D.Mode.Common, conf);

        JobConf jobConf = new JobConf(confPath);
        if (MPI_D.COMM_BIPARTITE_O != null) {
            // O communicator
            int rank = MPI_D.Comm_rank(MPI_D.COMM_BIPARTITE_O);
            int size = MPI_D.Comm_size(MPI_D.COMM_BIPARTITE_O);
            if (rank == 0) {
                LOG.info(PagerankNaive.class.getSimpleName() + " O start.");
            }
            FileSplit[] inputs1 = DataMPIUtil.HDFSDataLocalLocator.getTaskInputs(MPI_D.COMM_BIPARTITE_O,
                    jobConf, edgeDir, rank);
            FileSplit[] inputs2 = DataMPIUtil.HDFSDataLocalLocator.getTaskInputs(MPI_D.COMM_BIPARTITE_O,
                    jobConf, vecDir, rank);
            FileSplit[] inputs = (FileSplit[]) ArrayUtils.addAll(inputs2, inputs1);
            for (int i = 0; i < inputs.length; i++) {
                FileSplit fsplit = inputs[i];
                LineRecordReader kvrr = new LineRecordReader(jobConf, fsplit);

                LongWritable key = kvrr.createKey();
                Text value = kvrr.createValue();
                {
                    IntWritable k = new IntWritable();
                    Text v = new Text();
                    while (kvrr.next(key, value)) {
                        String line_text = value.toString();
                        // ignore comments in edge file
                        if (line_text.startsWith("#"))
                            continue;

                        final String[] line = line_text.split("\t");
                        if (line.length < 2)
                            continue;

                        // vector : ROWID VALUE('vNNNN')
                        if (line[1].charAt(0) == 'v') {
                            k.set(Integer.parseInt(line[0]));
                            v.set(line[1]);
                            MPI_D.Send(k, v);
                        } else {
                            /*
                             * In other matrix-vector multiplication, we
                            * output (dst, src) here However, In PageRank,
                            * the matrix-vector computation formula is M^T
                            * * v. Therefore, we output (src,dst) here.
                            */
                            int src_id = Integer.parseInt(line[0]);
                            int dst_id = Integer.parseInt(line[1]);
                            k.set(src_id);
                            v.set(line[1]);
                            MPI_D.Send(k, v);

                            if (make_symmetric == 1) {
                                k.set(dst_id);
                                v.set(line[0]);
                                MPI_D.Send(k, v);
                            }
                        }
                    }
                }
            }

        } else if (MPI_D.COMM_BIPARTITE_A != null) {
            // A communicator
            int rank = MPI_D.Comm_rank(MPI_D.COMM_BIPARTITE_A);
            if (rank == 0) {
                LOG.info(PagerankNaive.class.getSimpleName() + " A start.");
            }

            HadoopWriter<IntWritable, Text> outrw = HadoopIOUtil.getNewWriter(jobConf, outDir,
                    IntWritable.class, Text.class, TextOutputFormat.class, null, rank, MPI_D.COMM_BIPARTITE_A);

            IntWritable oldKey = null;
            int i;
            double cur_rank = 0;
            ArrayList<Integer> dst_nodes_list = new ArrayList<Integer>();
            Object[] keyValue = MPI_D.Recv();
            while (keyValue != null) {
                IntWritable key = (IntWritable) keyValue[0];
                Text value = (Text) keyValue[1];
                if (oldKey == null) {
                    oldKey = key;
                }
                // A new key arrives
                if (!key.equals(oldKey)) {
                    outrw.write(oldKey, new Text("s" + cur_rank));
                    int outdeg = dst_nodes_list.size();
                    if (outdeg > 0) {
                        cur_rank = cur_rank / (double) outdeg;
                    }
                    for (i = 0; i < outdeg; i++) {
                        outrw.write(new IntWritable(dst_nodes_list.get(i)), new Text("v" + cur_rank));
                    }
                    oldKey = key;
                    cur_rank = 0;
                    dst_nodes_list = new ArrayList<Integer>();
                }
                // common record
                String line_text = value.toString();
                final String[] line = line_text.split("\t");
                if (line.length == 1) {
                    if (line_text.charAt(0) == 'v') { // vector : VALUE
                        cur_rank = Double.parseDouble(line_text.substring(1));
                    } else { // edge : ROWID
                        dst_nodes_list.add(Integer.parseInt(line[0]));
                    }
                }
                keyValue = MPI_D.Recv();
            }
            // write the left part
            if (cur_rank != 0) {
                outrw.write(oldKey, new Text("s" + cur_rank));
                int outdeg = dst_nodes_list.size();
                if (outdeg > 0) {
                    cur_rank = cur_rank / (double) outdeg;
                }
                for (i = 0; i < outdeg; i++) {
                    outrw.write(new IntWritable(dst_nodes_list.get(i)), new Text("v" + cur_rank));
                }
            }
            outrw.close();
        }
        MPI_D.Finalize();
    } catch (MPI_D_Exception e) {
        e.printStackTrace();
    }
}

From source file:SelectorTalk.java

/** Main program entry point. */
public static void main(String argv[]) {

    // Is there anything to do?
    if (argv.length == 0) {
        printUsage();/*from   ww  w.  j  a va  2s.  co m*/
        System.exit(1);
    }

    // Values to be read from parameters
    String broker = DEFAULT_BROKER_NAME;
    String username = null;
    String password = DEFAULT_PASSWORD;
    String qSender = null;
    String qReceiver = null;
    String selection = null;

    // Check parameters
    for (int i = 0; i < argv.length; i++) {
        String arg = argv[i];

        // Options
        if (!arg.startsWith("-")) {
            System.err.println("error: unexpected argument - " + arg);
            printUsage();
            System.exit(1);
        } else {
            if (arg.equals("-b")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing broker name:port");
                    System.exit(1);
                }
                broker = argv[++i];
                continue;
            }

            if (arg.equals("-u")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing user name");
                    System.exit(1);
                }
                username = argv[++i];
                continue;
            }

            if (arg.equals("-p")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing password");
                    System.exit(1);
                }
                password = argv[++i];
                continue;
            }

            if (arg.equals("-qr")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing receive queue parameter");
                    System.exit(1);
                }
                qReceiver = argv[++i];
                continue;
            }

            if (arg.equals("-qs")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing send queue parameter");
                    System.exit(1);
                }
                qSender = argv[++i];
                continue;
            }

            if (arg.equals("-s")) {
                if (i == argv.length - 1 || argv[i + 1].startsWith("-")) {
                    System.err.println("error: missing selectiion");
                    System.exit(1);
                }
                selection = argv[++i];
                continue;
            }

            if (arg.equals("-h")) {
                printUsage();
                System.exit(1);
            }
        }
    }

    // Check values read in.
    if (username == null) {
        System.err.println("error: user name must be supplied");
        printUsage();
        System.exit(1);
    }

    if (qReceiver == null && qSender == null) {
        System.err.println("error: receive queue, or send queue, must be supplied");
        printUsage();
        System.exit(1);
    }

    if (selection == null) {
        System.err.println("error: selection must be supplied (e.g. -s SALES)\n");
        printUsage();
        System.exit(1);
    }

    // Start the JMS client for the "Talk".
    SelectorTalk talk = new SelectorTalk();
    talk.talker(broker, username, password, qReceiver, qSender, selection);

}

From source file:com.marklogic.client.tutorial.util.Bootstrapper.java

/**
 * Command-line invocation./*from www  .  jav  a2 s  . c o  m*/
 * @param args   command-line arguments specifying the configuration and REST server
 */
public static void main(String[] args)
        throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError {
    Properties properties = new Properties();
    for (int i = 0; i < args.length; i++) {
        String name = args[i];
        if (name.startsWith("-") && name.length() > 1 && ++i < args.length) {
            name = name.substring(1);
            if ("properties".equals(name)) {
                InputStream propsStream = Bootstrapper.class.getClassLoader().getResourceAsStream(name);
                if (propsStream == null)
                    throw new IOException("Could not read bootstrapper properties");
                Properties props = new Properties();
                props.load(propsStream);
                props.putAll(properties);
                properties = props;
            } else {
                properties.put(name, args[i]);
            }
        } else {
            System.err.println("invalid argument: " + name);
            System.err.println(getUsage());
            System.exit(1);
        }
    }

    String invalid = joinList(listInvalidKeys(properties));
    if (invalid != null && invalid.length() > 0) {
        System.err.println("invalid arguments: " + invalid);
        System.err.println(getUsage());
        System.exit(1);
    }

    new Bootstrapper().makeServer(properties);

    System.out.println("Created " + properties.getProperty("restserver") + " server on "
            + properties.getProperty("restport") + " port for " + properties.getProperty("restdb")
            + " database");
}

From source file:com.marklogic.client.example.util.Bootstrapper.java

/**
 * Command-line invocation./*w  w w  .j av  a  2  s  .co  m*/
 * @param args   command-line arguments specifying the configuration and REST server
 */
public static void main(String[] args) throws ClientProtocolException, IOException, FactoryConfigurationError {
    Properties properties = new Properties();
    for (int i = 0; i < args.length; i++) {
        String name = args[i];
        if (name.startsWith("-") && name.length() > 1 && ++i < args.length) {
            name = name.substring(1);
            if ("properties".equals(name)) {
                InputStream propsStream = Bootstrapper.class.getClassLoader().getResourceAsStream(name);
                if (propsStream == null)
                    throw new IOException("Could not read bootstrapper properties");
                Properties props = new Properties();
                props.load(propsStream);
                props.putAll(properties);
                properties = props;
            } else {
                properties.put(name, args[i]);
            }
        } else {
            System.err.println("invalid argument: " + name);
            System.err.println(getUsage());
            System.exit(1);
        }
    }

    String invalid = joinList(listInvalidKeys(properties));
    if (invalid != null && invalid.length() > 0) {
        System.err.println("invalid arguments: " + invalid);
        System.err.println(getUsage());
        System.exit(1);
    }

    // TODO: catch invalid argument exceptions and provide feedback
    new Bootstrapper().makeServer(properties);

    System.out.println("Created " + properties.getProperty("restserver") + " server on "
            + properties.getProperty("restport") + " port for " + properties.getProperty("restdb")
            + " database");
}

From source file:com.netthreads.mavenize.Pommel.java

/**
 * Arguments: <source dir> <target dir> <project type> [Optional parameter 
 * can be intellij, netbeans]/*from  w w w  .j  av a2s  .  c o  m*/
 * 
 * @param args
 */
public static void main(String[] args) {
    if (args.length > 1) {
        String sourcePath = "";
        String mapFilePath = "";

        boolean isInput = false;
        boolean isMap = false;
        for (String arg : args) {
            try {
                if (arg.startsWith(ARG_INPUT)) {
                    sourcePath = arg.substring(ARG_INPUT.length());
                    isInput = true;
                } else if (arg.startsWith(ARG_MAP)) {
                    mapFilePath = arg.substring(ARG_MAP.length());
                    isMap = true;
                }
            } catch (Exception e) {
                logger.error("Can't process argument, " + arg + ", " + e.getMessage());
            }
        }

        // Execute mapping.
        try {
            if (isInput && isMap) {
                Pommel pommel = new Pommel();

                pommel.process(sourcePath, mapFilePath);
            } else {
                System.out.println(APP_MESSAGE + ARGS_MESSAGE);
            }
        } catch (PommelException e) {
            System.out.println("Application error, " + e.getMessage());
        }
    } else {
        System.out.println(APP_MESSAGE + ARGS_MESSAGE);
    }
}