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:correospingtelnet.Telnet.java

public static void main(String[] args) throws Exception {
    FileOutputStream fout = null;

    String remoteip = "64.62.142.154";

    int remoteport = 23;

    try {/* w  ww.  j a  v  a 2  s. c o  m*/
        fout = new FileOutputStream("spy.log", true);
    } catch (IOException e) {
        System.err.println("Exception while opening the spy file: " + e.getMessage());
    }

    tc = new TelnetClient();

    TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler("VT100", false, false, true, false);
    EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true, false);
    SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true, true, true);

    try {
        tc.addOptionHandler(ttopt);
        tc.addOptionHandler(echoopt);
        tc.addOptionHandler(gaopt);
    } catch (InvalidTelnetOptionException e) {
        System.err.println("Error registering option handlers: " + e.getMessage());
    }

    while (true) {
        boolean end_loop = false;
        try {
            tc.connect(remoteip, remoteport);

            Thread reader = new Thread(new Telnet());
            tc.registerNotifHandler(new Telnet());
            System.out.println("TelnetClientExample");
            System.out.println("Type AYT to send an AYT telnet command");
            System.out.println("Type OPT to print a report of status of options (0-24)");
            System.out.println("Type REGISTER to register a new SimpleOptionHandler");
            System.out.println("Type UNREGISTER to unregister an OptionHandler");
            System.out.println("Type SPY to register the spy (connect to port 3333 to spy)");
            System.out.println("Type UNSPY to stop spying the connection");
            System.out.println("Type ^[A-Z] to send the control character; use ^^ to send ^");

            reader.start();
            OutputStream outstr = tc.getOutputStream();

            byte[] buff = new byte[1024];
            int ret_read = 0;

            do {
                try {
                    ret_read = System.in.read(buff);
                    if (ret_read > 0) {
                        final String line = new String(buff, 0, ret_read); // deliberate use of default charset
                        if (line.startsWith("AYT")) {
                            try {
                                System.out.println("Sending AYT");

                                System.out.println("AYT response:" + tc.sendAYT(5000));
                            } catch (IOException e) {
                                System.err.println("Exception waiting AYT response: " + e.getMessage());
                            }
                        } else if (line.startsWith("OPT")) {
                            System.out.println("Status of options:");
                            for (int ii = 0; ii < 25; ii++) {
                                System.out.println("Local Option " + ii + ":" + tc.getLocalOptionState(ii)
                                        + " Remote Option " + ii + ":" + tc.getRemoteOptionState(ii));
                            }
                        } else if (line.startsWith("REGISTER")) {
                            StringTokenizer st = new StringTokenizer(new String(buff));
                            try {
                                st.nextToken();
                                int opcode = Integer.parseInt(st.nextToken());
                                boolean initlocal = Boolean.parseBoolean(st.nextToken());
                                boolean initremote = Boolean.parseBoolean(st.nextToken());
                                boolean acceptlocal = Boolean.parseBoolean(st.nextToken());
                                boolean acceptremote = Boolean.parseBoolean(st.nextToken());
                                SimpleOptionHandler opthand = new SimpleOptionHandler(opcode, initlocal,
                                        initremote, acceptlocal, acceptremote);
                                tc.addOptionHandler(opthand);
                            } catch (Exception e) {
                                if (e instanceof InvalidTelnetOptionException) {
                                    System.err.println("Error registering option: " + e.getMessage());
                                } else {
                                    System.err.println("Invalid REGISTER command.");
                                    System.err.println(
                                            "Use REGISTER optcode initlocal initremote acceptlocal acceptremote");
                                    System.err.println("(optcode is an integer.)");
                                    System.err.println(
                                            "(initlocal, initremote, acceptlocal, acceptremote are boolean)");
                                }
                            }
                        } else if (line.startsWith("UNREGISTER")) {
                            StringTokenizer st = new StringTokenizer(new String(buff));
                            try {
                                st.nextToken();
                                int opcode = (new Integer(st.nextToken())).intValue();
                                tc.deleteOptionHandler(opcode);
                            } catch (Exception e) {
                                if (e instanceof InvalidTelnetOptionException) {
                                    System.err.println("Error unregistering option: " + e.getMessage());
                                } else {
                                    System.err.println("Invalid UNREGISTER command.");
                                    System.err.println("Use UNREGISTER optcode");
                                    System.err.println("(optcode is an integer)");
                                }
                            }
                        } else if (line.startsWith("SPY")) {
                            tc.registerSpyStream(fout);
                        } else if (line.startsWith("UNSPY")) {
                            tc.stopSpyStream();
                        } else if (line.matches("^\\^[A-Z^]\\r?\\n?$")) {
                            byte toSend = buff[1];
                            if (toSend == '^') {
                                outstr.write(toSend);
                            } else {
                                outstr.write(toSend - 'A' + 1);
                            }
                            outstr.flush();
                        } else {
                            try {
                                outstr.write(buff, 0, ret_read);
                                outstr.flush();
                            } catch (IOException e) {
                                end_loop = true;
                            }
                        }
                    }
                } catch (IOException e) {
                    System.err.println("Exception while reading keyboard:" + e.getMessage());
                    end_loop = true;
                }
            } while ((ret_read > 0) && (end_loop == false));

            try {
                tc.disconnect();
            } catch (IOException e) {
                System.err.println("Exception while connecting:" + e.getMessage());
            }
        } catch (IOException e) {
            System.err.println("Exception while connecting:" + e.getMessage());
            System.exit(1);
        }
    }
}

From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java

public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final FilteringTreeModel model = new FilteringTreeModel(createTreeModel());

    // setup text field
    final JTextField filterTextField = new JTextField(30);
    filterTextField.addActionListener(new ActionListener() {

        @Override//from  w w w . j a v a2s  .c o  m
        public void actionPerformed(ActionEvent e) {
            model.viewFilterChanged();
        }
    });

    // setup tree
    final JTree tree = new JTree();
    final IViewFilter<ITreeNode> filter = new AbstractViewFilter<ITreeNode>() {

        @Override
        public boolean isHiddenUnfiltered(ITreeNode node) {
            final String nodeValue = node.toString();
            final String expected = filterTextField.getText();

            final boolean isHidden = !StringUtils.isBlank(nodeValue) && !StringUtils.isBlank(expected)
                    && nodeValue.startsWith("child")
                    && !nodeValue.toLowerCase().contains(expected.toLowerCase());

            System.out.println(nodeValue + " does not match " + expected + " => " + isHidden);
            return isHidden;
        }
    };
    model.setViewFilter(filter);
    tree.setModel(model);

    // set 
    final JPanel panel = new JPanel();

    new GridLayoutBuilder()
            .add(new GridLayoutBuilder.HorizontalGroup(new GridLayoutBuilder.Cell(new JScrollPane(tree)),
                    new GridLayoutBuilder.FixedCell(filterTextField)))
            .addTo(panel);

    frame.getContentPane().add(panel);

    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:net.semanticmetadata.lire.solr.ParallelSolrIndexer.java

public static void main(String[] args) throws IOException {
    BitSampling.readHashFunctions();//from   w w  w . jav  a  2 s  .co m
    ParallelSolrIndexer e = new ParallelSolrIndexer();

    // parse programs args ...
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.startsWith("-i")) {
            // infile ...
            if ((i + 1) < args.length)
                e.setFileList(new File(args[i + 1]));
            else {
                System.err.println("Could not set out file.");
                printHelp();
            }
        } else if (arg.startsWith("-o")) {
            // out file, if it's not set a single file for each input image is created.
            if ((i + 1) < args.length)
                e.setOutFile(new File(args[i + 1]));
            else
                printHelp();
        } else if (arg.startsWith("-m")) {
            // out file
            if ((i + 1) < args.length) {
                try {
                    int s = Integer.parseInt(args[i + 1]);
                    if (s > 10)
                        e.setMaxSideLength(s);
                } catch (NumberFormatException e1) {
                    e1.printStackTrace();
                    printHelp();
                }
            } else
                printHelp();
        } else if (arg.startsWith("-r")) {
            // image data processor class.
            if ((i + 1) < args.length) {
                try {
                    Class<?> imageDataProcessorClass = Class.forName(args[i + 1]);
                    if (imageDataProcessorClass.newInstance() instanceof ImageDataProcessor)
                        e.setImageDataProcessor(imageDataProcessorClass);
                } catch (Exception e1) {
                    System.err.println("Did not find imageProcessor class: " + e1.getMessage());
                    printHelp();
                    System.exit(0);
                }
            } else
                printHelp();
        } else if (arg.startsWith("-f") || arg.startsWith("--force")) {
            e.setForce(true);
        } else if (arg.startsWith("-y") || arg.startsWith("--features")) {
            if ((i + 1) < args.length) {
                // parse and check the features.
                String[] ft = args[i + 1].split(",");
                for (int j = 0; j < ft.length; j++) {
                    String s = ft[j].trim();
                    if (FeatureRegistry.getClassForCode(s) != null) {
                        e.addFeature(FeatureRegistry.getClassForCode(s));
                    }
                }
            }
        } else if (arg.startsWith("-p")) {
            e.setPreprocessing(true);
        } else if (arg.startsWith("-h")) {
            // help
            printHelp();
            System.exit(0);
        } else if (arg.startsWith("-n")) {
            if ((i + 1) < args.length)
                try {
                    ParallelSolrIndexer.numberOfThreads = Integer.parseInt(args[i + 1]);
                } catch (Exception e1) {
                    System.err.println("Could not set number of threads to \"" + args[i + 1] + "\".");
                    e1.printStackTrace();
                }
            else
                printHelp();
        }
    }
    // check if there is an infile, an outfile and some features to extract.
    if (!e.isConfigured()) {
        printHelp();
    } else {
        e.run();
    }
}

From source file:com.sun.faces.generate.HtmlComponentGenerator.java

public static void main(String args[]) throws Exception {

    try {/*  w ww .  java2s  . c o  m*/

        // Perform setup operations
        if (log.isDebugEnabled()) {
            log.debug("Processing command line options");
        }
        Map options = options(args);
        String dtd = (String) options.get("--dtd");
        if (log.isDebugEnabled()) {
            log.debug("Configuring digester instance with public identifiers and DTD '" + dtd + "'");
        }
        StringTokenizer st = new StringTokenizer(dtd, "|");
        int arrayLen = st.countTokens();
        if (arrayLen == 0) {
            // PENDING I18n
            throw new Exception("No DTDs specified");
        }
        String[] dtds = new String[arrayLen];
        int i = 0;
        while (st.hasMoreTokens()) {
            dtds[i] = st.nextToken();
            i++;
        }

        copyright((String) options.get("--copyright"));
        directories((String) options.get("--dir"));
        Digester digester = digester(dtds, false, true, false);
        String config = (String) options.get("--config");
        if (log.isDebugEnabled()) {
            log.debug("Parsing configuration file '" + config + "'");
        }
        digester.push(new FacesConfigBean());
        fcb = parse(digester, config);
        if (log.isInfoEnabled()) {
            log.info("Generating HTML component classes");
        }

        // Generate concrete HTML component classes
        ComponentBean cbs[] = fcb.getComponents();
        for (i = 0; i < cbs.length; i++) {
            String componentClass = cbs[i].getComponentClass();
            if (componentClass.startsWith("javax.faces.component.html.")) {
                cb = cbs[i];
                generate();
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.exit(0);

}

From source file:com.mgreau.jboss.as7.cli.CliLauncher.java

public static void main(String[] args) throws Exception {
    int exitCode = 0;
    CommandContext cmdCtx = null;//from ww w  . j  av  a 2 s .  co  m
    boolean gui = false;
    String appName = "";
    try {
        String argError = null;
        List<String> commands = null;
        File file = null;
        boolean connect = false;
        String defaultControllerProtocol = "http-remoting";
        String defaultControllerHost = null;
        int defaultControllerPort = -1;
        boolean version = false;
        String username = null;
        char[] password = null;
        int connectionTimeout = -1;

        //App deployment
        boolean isAppDeployment = false;
        final Properties props = new Properties();

        for (String arg : args) {
            if (arg.startsWith("--controller=") || arg.startsWith("controller=")) {
                final String fullValue;
                final String value;
                if (arg.startsWith("--")) {
                    fullValue = arg.substring(13);
                } else {
                    fullValue = arg.substring(11);
                }
                final int protocolEnd = fullValue.lastIndexOf("://");
                if (protocolEnd == -1) {
                    value = fullValue;
                } else {
                    value = fullValue.substring(protocolEnd + 3);
                    defaultControllerProtocol = fullValue.substring(0, protocolEnd);
                }

                String portStr = null;
                int colonIndex = value.lastIndexOf(':');
                if (colonIndex < 0) {
                    // default port
                    defaultControllerHost = value;
                } else if (colonIndex == 0) {
                    // default host
                    portStr = value.substring(1);
                } else {
                    final boolean hasPort;
                    int closeBracket = value.lastIndexOf(']');
                    if (closeBracket != -1) {
                        //possible ip v6
                        if (closeBracket > colonIndex) {
                            hasPort = false;
                        } else {
                            hasPort = true;
                        }
                    } else {
                        //probably ip v4
                        hasPort = true;
                    }
                    if (hasPort) {
                        defaultControllerHost = value.substring(0, colonIndex).trim();
                        portStr = value.substring(colonIndex + 1).trim();
                    } else {
                        defaultControllerHost = value;
                    }
                }

                if (portStr != null) {
                    int port = -1;
                    try {
                        port = Integer.parseInt(portStr);
                        if (port < 0) {
                            argError = "The port must be a valid non-negative integer: '" + args + "'";
                        } else {
                            defaultControllerPort = port;
                        }
                    } catch (NumberFormatException e) {
                        argError = "The port must be a valid non-negative integer: '" + arg + "'";
                    }
                }
            } else if ("--connect".equals(arg) || "-c".equals(arg)) {
                connect = true;
            } else if ("--version".equals(arg)) {
                version = true;
            } else if ("--gui".equals(arg)) {
                gui = true;
            } else if (arg.startsWith("--appDeployment=") || arg.startsWith("appDeployment=")) {
                isAppDeployment = true;
                appName = arg.startsWith("--") ? arg.substring(16) : arg.substring(14);
            } else if (arg.startsWith("--file=") || arg.startsWith("file=")) {
                if (file != null) {
                    argError = "Duplicate argument '--file'.";
                    break;
                }
                if (commands != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time.";
                    break;
                }

                final String fileName = arg.startsWith("--") ? arg.substring(7) : arg.substring(5);
                if (!fileName.isEmpty()) {
                    file = new File(fileName);
                    if (!file.exists()) {
                        argError = "File " + file.getAbsolutePath() + " doesn't exist.";
                        break;
                    }
                } else {
                    argError = "Argument '--file' is missing value.";
                    break;
                }
            } else if (arg.startsWith("--commands=") || arg.startsWith("commands=")) {
                if (file != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time.";
                    break;
                }
                if (commands != null) {
                    argError = "Duplicate argument '--command'/'--commands'.";
                    break;
                }
                final String value = arg.startsWith("--") ? arg.substring(11) : arg.substring(9);
                commands = Util.splitCommands(value);
            } else if (arg.startsWith("--command=") || arg.startsWith("command=")) {
                if (file != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time.";
                    break;
                }
                if (commands != null) {
                    argError = "Duplicate argument '--command'/'--commands'.";
                    break;
                }
                final String value = arg.startsWith("--") ? arg.substring(10) : arg.substring(8);
                commands = Collections.singletonList(value);
            } else if (arg.startsWith("--user=")) {
                username = arg.startsWith("--") ? arg.substring(7) : arg.substring(5);
            } else if (arg.startsWith("--password=")) {
                password = (arg.startsWith("--") ? arg.substring(11) : arg.substring(9)).toCharArray();
            } else if (arg.startsWith("--timeout=")) {
                if (connectionTimeout > 0) {
                    argError = "Duplicate argument '--timeout'";
                    break;
                }
                final String value = arg.substring(10);
                try {
                    connectionTimeout = Integer.parseInt(value);
                } catch (final NumberFormatException e) {
                    //
                }
                if (connectionTimeout <= 0) {
                    argError = "The timeout must be a valid positive integer: '" + value + "'";
                }
            } else if (arg.equals("--help") || arg.equals("-h")) {
                commands = Collections.singletonList("help");
            } else if (arg.startsWith("--properties=")) {
                final String value = arg.substring(13);
                final File propertiesFile = new File(value);
                if (!propertiesFile.exists()) {
                    argError = "File doesn't exist: " + propertiesFile.getAbsolutePath();
                    break;
                }

                FileInputStream fis = null;
                try {
                    fis = new FileInputStream(propertiesFile);
                    props.load(fis);
                } catch (FileNotFoundException e) {
                    argError = e.getLocalizedMessage();
                    break;
                } catch (java.io.IOException e) {
                    argError = "Failed to load properties from " + propertiesFile.getAbsolutePath() + ": "
                            + e.getLocalizedMessage();
                    break;
                } finally {
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (java.io.IOException e) {
                        }
                    }
                }
                for (final Object prop : props.keySet()) {
                    AccessController.doPrivileged(new PrivilegedAction<Object>() {
                        public Object run() {
                            System.setProperty((String) prop, (String) props.get(prop));
                            return null;
                        }
                    });
                }
            } else if (!(arg.startsWith("-D") || arg.equals("-XX:"))) {// skip system properties and jvm options
                // assume it's commands
                if (file != null) {
                    argError = "Only one of '--file', '--commands' or '--command' can appear as the argument at a time: "
                            + arg;
                    break;
                }
                if (commands != null) {
                    argError = "Duplicate argument '--command'/'--commands'.";
                    break;
                }
                commands = Util.splitCommands(arg);
            }
        }

        if (argError != null) {
            System.err.println(argError);
            exitCode = 1;
            return;
        }

        if (version) {
            cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                    username, password, false, connect, connectionTimeout);
            VersionHandler.INSTANCE.handle(cmdCtx);
            return;
        }

        if (file != null) {
            cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                    username, password, false, connect, connectionTimeout);
            processFile(file, cmdCtx, isAppDeployment, appName, props);
            return;
        }

        if (commands != null) {
            cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                    username, password, false, connect, connectionTimeout);
            processCommands(commands, cmdCtx);
            return;
        }

        // Interactive mode
        cmdCtx = initCommandContext(defaultControllerProtocol, defaultControllerHost, defaultControllerPort,
                username, password, true, connect, connectionTimeout);
        cmdCtx.interact();
    } catch (Throwable t) {
        t.printStackTrace();
        exitCode = 1;
    } finally {
        if (cmdCtx != null && cmdCtx.getExitCode() != 0) {
            exitCode = cmdCtx.getExitCode();
        }
        if (!gui) {
            System.exit(exitCode);
        }
    }
    System.exit(exitCode);
}

From source file:de.tu_dortmund.ub.data.dswarm.TaskProcessingUnit.java

public static void main(final String[] args) throws Exception {

    // default config
    String configFile = DEFAULT_CONF_FOLDER_NAME + File.separatorChar + DEFAULT_CONFIG_PROPERTIES_FILE_NAME;

    // read program parameters
    if (args.length > 0) {

        for (final String arg : args) {

            LOG.info("arg = " + arg);

            if (arg.startsWith("-conf=")) {

                configFile = arg.split("=")[1];
            }//from w  w w.j  a v  a  2 s .com
        }
    }

    final Properties config;

    // Init properties
    try {

        try (final InputStream inputStream = new FileInputStream(configFile)) {

            try (final BufferedReader reader = new BufferedReader(
                    new InputStreamReader(inputStream, TPUUtil.UTF_8))) {

                config = new Properties();
                config.load(reader);
            }
        }
    } catch (final IOException e) {

        LOG.error("something went wrong", e);
        LOG.error(String.format("FATAL ERROR: Could not read '%s'!", configFile));

        throw e;
    }

    startTPU(configFile, config);
}

From source file:org.kuali.student.git.importer.ApplyManualBranchCleanup.java

/**
 * @param args/*from ww w  .  j a v a 2s.c o  m*/
 */
public static void main(String[] args) {

    if (args.length < 4 || args.length > 7) {
        usage();
    }

    File inputFile = new File(args[0]);

    if (!inputFile.exists())
        usage();

    boolean bare = false;

    if (args[2].trim().equals("1")) {
        bare = true;
    }

    String remoteName = args[3].trim();

    String refPrefix = Constants.R_HEADS;

    if (args.length == 5)
        refPrefix = args[4].trim();

    String userName = null;
    String password = null;

    if (args.length == 6)
        userName = args[5].trim();

    if (args.length == 7)
        password = args[6].trim();

    try {

        Repository repo = GitRepositoryUtils.buildFileRepository(new File(args[1]).getAbsoluteFile(), false,
                bare);

        Git git = new Git(repo);

        RevWalk rw = new RevWalk(repo);

        ObjectInserter objectInserter = repo.newObjectInserter();

        BufferedReader fileReader = new BufferedReader(new FileReader(inputFile));

        String line = fileReader.readLine();

        int lineNumber = 1;

        BatchRefUpdate batch = repo.getRefDatabase().newBatchUpdate();

        List<RefSpec> branchesToDelete = new ArrayList<>();

        while (line != null) {

            if (line.startsWith("#") || line.length() == 0) {
                // skip over comments and blank lines
                line = fileReader.readLine();
                lineNumber++;

                continue;
            }

            String parts[] = line.trim().split(":");

            String branchName = parts[0];

            Ref branchRef = repo.getRef(refPrefix + "/" + branchName);

            if (branchRef == null) {
                log.warn("line: {}, No branch matching {} exists, skipping.", lineNumber, branchName);

                line = fileReader.readLine();
                lineNumber++;

                continue;
            }

            String tagName = null;

            if (parts.length > 1)
                tagName = parts[1];

            if (tagName != null) {

                if (tagName.equals("keep")) {
                    log.info("keeping existing branch for {}", branchName);

                    line = fileReader.readLine();
                    lineNumber++;

                    continue;
                }

                if (tagName.equals("tag")) {

                    /*
                     * Shortcut to say make the tag start with the same name as the branch.
                     */
                    tagName = branchName;
                }
                // create a tag

                RevCommit commit = rw.parseCommit(branchRef.getObjectId());

                ObjectId tag = GitRefUtils.insertTag(tagName, commit, objectInserter);

                batch.addCommand(new ReceiveCommand(null, tag, Constants.R_TAGS + tagName, Type.CREATE));

                log.info("converting branch {} into a tag {}", branchName, tagName);

            }

            if (remoteName.equals("local")) {
                batch.addCommand(
                        new ReceiveCommand(branchRef.getObjectId(), null, branchRef.getName(), Type.DELETE));
            } else {

                // if the branch is remote then remember its name so we can batch delete after we have the full list.
                branchesToDelete.add(new RefSpec(":" + Constants.R_HEADS + branchName));
            }

            line = fileReader.readLine();
            lineNumber++;

        }

        fileReader.close();

        // run the batch update
        batch.execute(rw, new TextProgressMonitor());

        if (!remoteName.equals("local")) {
            // push the tag to the remote right now

            log.info("pushing tags to {}", remoteName);

            PushCommand pushCommand = git.push().setRemote(remoteName).setPushTags()
                    .setProgressMonitor(new TextProgressMonitor());

            if (userName != null)
                pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password));

            Iterable<PushResult> results = pushCommand.call();

            for (PushResult pushResult : results) {

                if (!pushResult.equals(Result.NEW)) {
                    log.warn("failed to push tag " + pushResult.getMessages());
                }
            }

            // delete the branches from the remote

            log.info("pushing branch deletes to remote: {}", remoteName);

            results = git.push().setRemote(remoteName).setRefSpecs(branchesToDelete)
                    .setProgressMonitor(new TextProgressMonitor()).call();
        }

        objectInserter.release();

        rw.release();

    } catch (Exception e) {

        log.error("unexpected Exception ", e);
    }
}

From source file:edu.ku.brc.util.GeoRefConverter.java

/**
 * @param args/*from  w  ww . j  a va  2  s .c  o m*/
 * @throws Exception 
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    String destFormat = GeoRefFormat.DMS_PLUS_MINUS.name();

    String[] inputStrings = new String[] {

            // +/- Deg Min Sec
            "//+/- Deg Min Sec", "0 0 0", "0 0 0.", "-32 45 16.8232", "-32d 45' 16.8232\"", "-32d45'16.8232\"",
            "-3245'16.8232\"", "-32 45' 16.82\"", "-32 45 16.82", "-32 45 6.8232", "-32 45 6.82",
            "-32 45 0.82", "-132 45 16.82151", "-132 45 6.82", "32 45 16.8232", "32 45 16.82", "32 45 6.8232",
            "32 45 6.82", "32 45 0.82", "132 45 16.82151", "132 45 6.82",

            // Deg Min Sec N/S/E/W
            "//Deg Min Sec N/S/E/W", "32 45 16.8232 N", "32 45 16.82 N", "32d45'16.82\" N", "32d45'16.82\"N",
            "32d 45' 16.82\" N", "32 45' 16.82\" N", "32 45 16.82 N", "32 45 6.8232 N", "32 45 6.82 N",
            "32 45 0.82 N", "132 45 16.82151 N", "132 45 6.82 N",

            "32 45 16.8232 S", "32 45 16.82 S", "32 45 6.8232 S", "32 45 6.82 S", "32 45 0.82 S",
            "132 45 16.82151 S", "132 45 6.82 S",

            "32 45 16.8232 E", "32 45 16.82 E", "32 45 6.8232 E", "32 45 6.82 E", "32 45 0.82 E",
            "132 45 16.82151 E", "132 45 6.82 E",

            "32 45 16.8232 W", "32 45 16.82 W", "32 45 6.8232 W", "32 45 6.82 W", "32 45 0.82 W",
            "132 45 16.82151 W", "132 45 6.82 W",

            // +/- Deg Min
            "//+/- Deg Min", "0 0", "0 0.", "-32 16.8232", "-32 16.82", "-32 16.82'", "-3216.82", "-32d 16",
            "-32 16.82", "-32 6.8232", "-32 6.82", "-32 0.82", "-132 16.82151", "-132 6.82", "32 16.8232",
            "32 16.82", "32 6.8232", "32 6.82", "32 0.82", "132 16.82151", "132 6.82",

            // Deg Min N/S/E/W
            "//Deg Min N/S/E/W", "32 16.8232 N", "32 16.82 N", "32 6.8232 N", "32 6.82 N", "32 0.82 N",
            "132 16.82151 N", "132 6.82 N",

            "32 16.8232 S", "32 16.82 S", "32 6.8232 S", "32 6.82 S", "32 0.82 S", "132 16.82151 S",
            "132 6.82 S",

            "32 16.8232 E", "32 16.82 E", "32 6.8232 E", "32 6.82 E", "32 0.82 E", "132 16.82151 E",
            "132 6.82 E",

            "32 16.8232 W", "32 16.82 W", "32 6.8232 W", "32 6.82 W", "32 0.82 W", "132 16.82151 W",
            "132 6.82 W",

            // +/- Decimal Degrees
            "//+/- Decimal Degrees", "0", "0.", "-16.8232", "-16.8232", "-16.82", "-6.8232", "-6.82", "-0.82",
            "-116.82151", "-116.82", "-1.82", "16.8232", "16.82", "6.8232", "6.82", "0.82", "116.82151",
            "116.82", "1.82",

            // Decimal Degrees N/S/E/W
            "//Decimal Degrees N/S/E/W", "16.8232 N", "16.82 N", "16.8232 N", "16.82 N", "16.8232N",
            "16.82N", "6.8232 N", "6.82 N", "0.82 N", "116.82151 N", "116.82 N", "1.82 N",

            "16.8232 S", "16.82 S", "6.8232 S", "6.82 S", "0.82 S", "116.82151 S", "116.82 S", "1.82 S",

            "16.8232 E", "16.82 E", "6.8232 E", "6.82 E", "0.82 E", "116.82151 E", "116.82 E", "1.82 E",

            "16.8232 W", "16.82 W", "6.8232 W", "6.82 W", "0.82 W", "116.82151 W", "116.82 W", "1.82 W",
            "41 43." };

    for (String input : inputStrings) {
        if (input.length() == 0) {
            continue;
        }

        if (input.startsWith("//")) {
            System.out.println();
            System.out.println("----------------------------------");
            System.out.println("----------------------------------");
            System.out.println(input.substring(2));
            System.out.println("----------------------------------");
            System.out.println("----------------------------------");
            continue;
        }

        System.out.println("Input:             " + input);
        BigDecimal degreesPlusMinus = null;
        for (GeoRefFormat format : GeoRefFormat.values()) {
            if (input.matches(format.regex)) {
                System.out.println("Format match:      " + format.name());
                degreesPlusMinus = format.convertToDecimalDegrees(input);
                break;
            }
        }

        // if we weren't able to find a matching format, throw an exception
        if (degreesPlusMinus == null) {
            System.out.println("No matching format found");
            System.out.println("----------------------------------");
            continue;
        }

        int decimalFmtLen = 0;
        int decIndex = input.lastIndexOf('.');
        if (decIndex > -1 && input.length() > decIndex) {
            decimalFmtLen = input.length() - decIndex;
        }

        String convertedVal = null;
        if (destFormat == GeoRefFormat.DMS_PLUS_MINUS.name()) {
            convertedVal = LatLonConverter.convertToSignedDDMMSS(degreesPlusMinus,
                    Math.min(LatLonConverter.DDMMSS_LEN, decimalFmtLen));
        } else if (destFormat == GeoRefFormat.DM_PLUS_MINUS.name()) {
            convertedVal = LatLonConverter.convertToSignedDDMMMM(degreesPlusMinus,
                    Math.min(LatLonConverter.DDMMMM_LEN, decimalFmtLen));
        } else if (destFormat == GeoRefFormat.D_PLUS_MINUS.name()) {
            convertedVal = LatLonConverter.convertToSignedDDDDDD(degreesPlusMinus,
                    Math.min(LatLonConverter.DDDDDD_LEN, decimalFmtLen));
        }

        System.out.println("Converted value:   " + convertedVal);
        System.out.println("----------------------------------");
    }

    GeoRefConverter converter = new GeoRefConverter();
    for (String input : inputStrings) {
        if (input.length() == 0) {
            continue;
        }

        if (input.startsWith("//")) {
            System.out.println();
            System.out.println("----------------------------------");
            System.out.println("----------------------------------");
            System.out.println(input.substring(2));
            System.out.println("----------------------------------");
            System.out.println("----------------------------------");
            continue;
        }

        System.out.println("Input:             " + input);
        String decimalDegrees = converter.convert(input, GeoRefConverter.GeoRefFormat.D_PLUS_MINUS.name());
        System.out.println("Decimal degrees:   " + decimalDegrees);
    }
    System.out.println("----------------------------------");
    System.out.println("----------------------------------");
    System.out.println("----------------------------------");
    System.out.println("----------------------------------");
    System.out.println("----------------------------------");
    System.out.println("----------------------------------");
    System.out.println("----------------------------------");
    System.out.println("----------------------------------");

    String problemString = "41 43 18.";
    System.out.println("input: " + problemString);
    String d = converter.convert(problemString, GeoRefFormat.D_PLUS_MINUS.name());
    String dm = converter.convert(problemString, GeoRefFormat.DM_PLUS_MINUS.name());
    String dms = converter.convert(problemString, GeoRefFormat.DMS_PLUS_MINUS.name());
    System.out.println(d + "   :   " + dm + "   :   " + dms);

    problemString = d;
    System.out.println("input: " + problemString);
    String d2 = converter.convert(problemString, GeoRefFormat.D_PLUS_MINUS.name());
    String dm2 = converter.convert(problemString, GeoRefFormat.DM_PLUS_MINUS.name());
    String dms2 = converter.convert(problemString, GeoRefFormat.DMS_PLUS_MINUS.name());
    System.out.println(d2 + "   :   " + dm2 + "   :   " + dms2);

    problemString = dm;
    System.out.println("input: " + problemString);
    String d3 = converter.convert(problemString, GeoRefFormat.D_PLUS_MINUS.name());
    String dm3 = converter.convert(problemString, GeoRefFormat.DM_PLUS_MINUS.name());
    String dms3 = converter.convert(problemString, GeoRefFormat.DMS_PLUS_MINUS.name());
    System.out.println(d3 + "   :   " + dm3 + "   :   " + dms3);
}

From source file:edu.toronto.cs.xcurator.cli.CLIRunner.java

public static void main(String[] args) {
    Options options = setupOptions();// w  ww . j  a va  2  s  . c o m
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption('t')) {
            fileType = line.getOptionValue('t');
        } else {
            fileType = XML;
        }
        if (line.hasOption('o')) {
            tdbDirectory = line.getOptionValue('o');
            File d = new File(tdbDirectory);
            if (!d.exists() || !d.isDirectory()) {
                throw new Exception("TDB directory does not exist, please create.");
            }
        }
        if (line.hasOption('h')) {
            domain = line.getOptionValue('h');
            try {
                URL url = new URL(domain);
            } catch (MalformedURLException ex) {
                throw new Exception("The domain name is ill-formed");
            }
        } else {
            printHelpAndExit(options);
        }
        if (line.hasOption('m')) {
            serializeMapping = true;
            mappingFilename = line.getOptionValue('m');
        }
        if (line.hasOption('d')) {
            dirLocation = line.getOptionValue('d');
            inputStreams = new ArrayList<>();
            final List<String> files = Util.getFiles(dirLocation);
            for (String inputfile : files) {
                File f = new File(inputfile);
                if (f.isFile() && f.exists()) {
                    System.out.println("Adding document to mapping discoverer: " + inputfile);
                    inputStreams.add(new FileInputStream(f));
                } // If it is a URL download link for the document from SEC
                else if (inputfile.startsWith("http") && inputfile.contains("://")) {
                    // Download
                    System.out.println("Adding remote document to mapping discoverer: " + inputfile);
                    try {
                        URL url = new URL(inputfile);
                        InputStream remoteDocumentStream = url.openStream();
                        inputStreams.add(remoteDocumentStream);
                    } catch (MalformedURLException ex) {
                        throw new Exception("The document URL is ill-formed: " + inputfile);
                    } catch (IOException ex) {
                        throw new Exception("Error in downloading remote document: " + inputfile);
                    }
                } else {
                    throw new Exception("Cannot open XBRL document: " + f.getName());
                }
            }
        }

        if (line.hasOption('f')) {
            fileLocation = line.getOptionValue('f');
            inputStreams = new ArrayList<>();
            File f = new File(fileLocation);
            if (f.isFile() && f.exists()) {
                System.out.println("Adding document to mapping discoverer: " + fileLocation);
                inputStreams.add(new FileInputStream(f));
            } // If it is a URL download link for the document from SEC
            else if (fileLocation.startsWith("http") && fileLocation.contains("://")) {
                // Download
                System.out.println("Adding remote document to mapping discoverer: " + fileLocation);
                try {
                    URL url = new URL(fileLocation);
                    InputStream remoteDocumentStream = url.openStream();
                    inputStreams.add(remoteDocumentStream);
                } catch (MalformedURLException ex) {
                    throw new Exception("The document URL is ill-formed: " + fileLocation);
                } catch (IOException ex) {
                    throw new Exception("Error in downloading remote document: " + fileLocation);
                }
            } else {

                throw new Exception("Cannot open XBRL document: " + f.getName());
            }

        }

        setupDocumentBuilder();
        RdfFactory rdfFactory = new RdfFactory(new RunConfig(domain));
        List<Document> documents = new ArrayList<>();
        for (InputStream inputStream : inputStreams) {
            Document dataDocument = null;
            if (fileType.equals(JSON)) {
                String json = IOUtils.toString(inputStream);
                final String xml = Util.json2xml(json);
                final InputStream xmlInputStream = IOUtils.toInputStream(xml);
                dataDocument = createDocument(xmlInputStream);
            } else {
                dataDocument = createDocument(inputStream);
            }
            documents.add(dataDocument);
        }
        if (serializeMapping) {
            System.out.println("Mapping file will be saved to: " + new File(mappingFilename).getAbsolutePath());
            rdfFactory.createRdfs(documents, tdbDirectory, mappingFilename);
        } else {
            rdfFactory.createRdfs(documents, tdbDirectory);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        System.err.println("Unexpected exception: " + ex.getMessage());
        System.exit(1);
    }
}

From source file:copi.ScalaEntryPoint.java

public static void main(String[] args) {
    /*//from  w  w  w  .ja va 2  s. co  m
       * Set lwjgl library path so that LWJGL finds the natives depending on
       * the OS.
       */
    File libDir = new File(path);

    if (!libDir.exists()) {
        // create native lib folder 
        libDir.mkdir();

        // retrieve os type
        String osName = System.getProperty("os.name");

        // try to determine if the system is 64 bit  
        boolean is64bit = false;
        if (System.getProperty("os.name").contains("Windows")) {
            is64bit = (System.getenv("ProgramFiles(x86)") != null);
        } else {
            is64bit = (System.getProperty("os.arch").indexOf("64") != -1);
        }

        // construct name of native lib file 
        String natLibLWJGL = "";
        if (osName.startsWith("Windows")) {
            natLibLWJGL += "lwjgl";
            if (is64bit)
                natLibLWJGL += "64";
            natLibLWJGL += ".dll";
        } else if (osName.startsWith("Linux")) {
            natLibLWJGL += "liblwjgl";
            if (is64bit)
                natLibLWJGL += "64";
            natLibLWJGL += ".so";
        } else if (osName.startsWith("Mac OS X")) {
            natLibLWJGL += "liblwjgl";
            natLibLWJGL += ".jnilib";
        } else {
            System.out.println("Unsupported OS: " + osName + ". Exiting.");
            System.exit(-1);
        }

        // try to establish an input stream on the native lib inside the jar
        InputStream fis = ScalaEntryPoint.class.getResourceAsStream("/" + natLibLWJGL);
        if (fis == null) {
            System.out.println("Native library file " + natLibLWJGL + " was not found inside JAR.");
            System.exit(-1);
        }

        // establish an output stream on the target file 
        File fOut = new File(path + "/" + natLibLWJGL);
        try (FileOutputStream fos = new FileOutputStream(fOut)) {
            // create file at destination if not already existing
            if (!fOut.exists())
                fOut.createNewFile();

            // making buffer for copy operation 
            byte[] buffer = new byte[1024];
            int readBytes;

            // Open output stream and copy data between source file in JAR and the temporary file
            try {
                while ((readBytes = fis.read(buffer)) != -1) {
                    fos.write(buffer, 0, readBytes);
                }
            } finally {
                fos.close();
                fis.close();
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
            System.exit(-1);
        }

        // register shutdown hook
        JVMShutdownHook jvmShutdownHook = new JVMShutdownHook();
        Runtime.getRuntime().addShutdownHook(jvmShutdownHook);

    }

    // set lwjgl native library path
    System.setProperty("org.lwjgl.librarypath", libDir.getAbsolutePath());

    // start COPI
    System.out.println("Starting COPI ...");
    (new SICApplicationLogic()).render();
}