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:org.wso2.carbon.sample.atmstats.ATMTransactionStatsClient.java

public static void main(String[] args) throws XMLStreamException {
    System.out.println(xmlMsgs.get(1));
    System.out.println(xmlMsgs.get(2));
    System.out.println(xmlMsgs.get(3));
    KeyStoreUtil.setTrustStoreParams();/* w ww .  j  a  va2  s.  c o  m*/
    String url = args[0];
    String username = args[1];
    String password = args[2];

    HttpClient httpClient = new SystemDefaultHttpClient();

    try {
        HttpPost method = new HttpPost(url);

        for (String xmlElement : xmlMsgs) {
            StringEntity entity = new StringEntity(xmlElement);
            method.setEntity(entity);
            if (url.startsWith("https")) {
                processAuthentication(method, username, password);
            }
            httpClient.execute(method).getEntity().getContent().close();
        }
        Thread.sleep(500); // We need to wait some time for the message to be sent

    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.jgaap.backend.CLI.java

/**
 * Parses the arguments passed to jgaap from the command line. Will either
 * display the help or run jgaap on an experiment.
 * /* w  w  w  . j  a va 2 s .co  m*/
 * @param args
 *            command line arguments
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    CommandLineParser parser = new GnuParser();
    CommandLine cmd = parser.parse(options, args);
    if (cmd.hasOption('h')) {
        String command = cmd.getOptionValue('h');
        if (command == null) {
            HelpFormatter helpFormatter = new HelpFormatter();
            helpFormatter.setLeftPadding(5);
            helpFormatter.setWidth(100);
            helpFormatter.printHelp(
                    "jgaap -c [canon canon ...] -es [event] -ec [culler culler ...] -a [analysis] <-d [distance]> -l [file] <-s [file]>",
                    "Welcome to JGAAP the Java Graphical Authorship Attribution Program.\nMore information can be found at http://jgaap.com",
                    options, "Copyright 2013 Evaluating Variation in Language Lab, Duquesne University");
        } else {
            List<Displayable> list = new ArrayList<Displayable>();
            if (command.equalsIgnoreCase("c")) {
                list.addAll(Canonicizers.getCanonicizers());
            } else if (command.equalsIgnoreCase("es")) {
                list.addAll(EventDrivers.getEventDrivers());
            } else if (command.equalsIgnoreCase("ec")) {
                list.addAll(EventCullers.getEventCullers());
            } else if (command.equalsIgnoreCase("a")) {
                list.addAll(AnalysisDrivers.getAnalysisDrivers());
            } else if (command.equalsIgnoreCase("d")) {
                list.addAll(DistanceFunctions.getDistanceFunctions());
            } else if (command.equalsIgnoreCase("lang")) {
                list.addAll(Languages.getLanguages());
            }
            for (Displayable display : list) {
                if (display.showInGUI())
                    System.out.println(display.displayName() + " - " + display.tooltipText());
            }
            if (list.isEmpty()) {
                System.out.println("Option " + command + " was not found.");
                System.out.println("Please use c, es, d, a, or lang");
            }
        }
    } else if (cmd.hasOption('v')) {
        System.out.println("Java Graphical Authorship Attribution Program version 5.2.0");
    } else if (cmd.hasOption("ee")) {
        String eeFile = cmd.getOptionValue("ee");
        String lang = cmd.getOptionValue("lang");
        ExperimentEngine.runExperiment(eeFile, lang);
        System.exit(0);
    } else {
        JGAAP.commandline = true;
        API api = API.getPrivateInstance();
        String documentsFilePath = cmd.getOptionValue('l');
        if (documentsFilePath == null) {
            throw new Exception("No Documents CSV specified");
        }
        List<Document> documents;
        if (documentsFilePath.startsWith(JGAAPConstants.JGAAP_RESOURCE_PACKAGE)) {
            documents = Utils.getDocumentsFromCSV(
                    CSVIO.readCSV(com.jgaap.JGAAP.class.getResourceAsStream(documentsFilePath)));
        } else {
            documents = Utils.getDocumentsFromCSV(CSVIO.readCSV(documentsFilePath));
        }
        for (Document document : documents) {
            api.addDocument(document);
        }
        String language = cmd.getOptionValue("lang", "english");
        api.setLanguage(language);
        String[] canonicizers = cmd.getOptionValues('c');
        if (canonicizers != null) {
            for (String canonicizer : canonicizers) {
                api.addCanonicizer(canonicizer);
            }
        }
        String[] events = cmd.getOptionValues("es");
        if (events == null) {
            throw new Exception("No EventDriver specified");
        }
        for (String event : events) {
            api.addEventDriver(event);
        }
        String[] eventCullers = cmd.getOptionValues("ec");
        if (eventCullers != null) {
            for (String eventCuller : eventCullers) {
                api.addEventCuller(eventCuller);
            }
        }
        String analysis = cmd.getOptionValue('a');
        if (analysis == null) {
            throw new Exception("No AnalysisDriver specified");
        }
        AnalysisDriver analysisDriver = api.addAnalysisDriver(analysis);
        String distanceFunction = cmd.getOptionValue('d');
        if (distanceFunction != null) {
            api.addDistanceFunction(distanceFunction, analysisDriver);
        }
        api.execute();
        List<Document> unknowns = api.getUnknownDocuments();
        OutputStreamWriter outputStreamWriter;
        String saveFile = cmd.getOptionValue('s');
        if (saveFile == null) {
            outputStreamWriter = new OutputStreamWriter(System.out);
        } else {
            outputStreamWriter = new OutputStreamWriter(new FileOutputStream(saveFile));
        }
        Writer writer = new BufferedWriter(outputStreamWriter);
        for (Document unknown : unknowns) {
            writer.append(unknown.getFormattedResult(analysisDriver));
        }
        writer.append('\n');
    }
}

From source file:examples.tftp.java

public final static void main(String[] args) {
    boolean receiveFile = true, closed;
    int transferMode = TFTP.BINARY_MODE, argc;
    String arg, hostname, localFilename, remoteFilename;
    TFTPClient tftp;//from   w w w. j  av a2 s .  c o m

    // Parse options
    for (argc = 0; argc < args.length; argc++) {
        arg = args[argc];
        if (arg.startsWith("-")) {
            if (arg.equals("-r"))
                receiveFile = true;
            else if (arg.equals("-s"))
                receiveFile = false;
            else if (arg.equals("-a"))
                transferMode = TFTP.ASCII_MODE;
            else if (arg.equals("-b"))
                transferMode = TFTP.BINARY_MODE;
            else {
                System.err.println("Error: unrecognized option.");
                System.err.print(USAGE);
                System.exit(1);
            }
        } else
            break;
    }

    // Make sure there are enough arguments
    if (args.length - argc != 3) {
        System.err.println("Error: invalid number of arguments.");
        System.err.print(USAGE);
        System.exit(1);
    }

    // Get host and file arguments
    hostname = args[argc];
    localFilename = args[argc + 1];
    remoteFilename = args[argc + 2];

    // Create our TFTP instance to handle the file transfer.
    tftp = new TFTPClient();

    // We want to timeout if a response takes longer than 60 seconds
    tftp.setDefaultTimeout(60000);

    // Open local socket
    try {
        tftp.open();
    } catch (SocketException e) {
        System.err.println("Error: could not open local UDP socket.");
        System.err.println(e.getMessage());
        System.exit(1);
    }

    // We haven't closed the local file yet.
    closed = false;

    // If we're receiving a file, receive, otherwise send.
    if (receiveFile) {
        FileOutputStream output = null;
        File file;

        file = new File(localFilename);

        // If file exists, don't overwrite it.
        if (file.exists()) {
            System.err.println("Error: " + localFilename + " already exists.");
            System.exit(1);
        }

        // Try to open local file for writing
        try {
            output = new FileOutputStream(file);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for writing.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to receive remote file via TFTP
        try {
            tftp.receiveFile(remoteFilename, transferMode, output, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while receiving file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and output file
            tftp.close();
            try {
                output.close();
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed)
            System.exit(1);

    } else {
        // We're sending a file
        FileInputStream input = null;

        // Try to open local file for reading
        try {
            input = new FileInputStream(localFilename);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for reading.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to send local file via TFTP
        try {
            tftp.sendFile(remoteFilename, transferMode, input, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while sending file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and input file
            tftp.close();
            try {
                input.close();
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed)
            System.exit(1);

    }

}

From source file:examples.tftp.java

public final static void main(String[] args) {
    boolean receiveFile = true, closed;
    int transferMode = TFTP.BINARY_MODE, argc;
    String arg, hostname, localFilename, remoteFilename;
    TFTPClient tftp;/*from  w w w  .j ava  2s.c o m*/

    // Parse options
    for (argc = 0; argc < args.length; argc++) {
        arg = args[argc];
        if (arg.startsWith("-")) {
            if (arg.equals("-r"))
                receiveFile = true;
            else if (arg.equals("-s"))
                receiveFile = false;
            else if (arg.equals("-a"))
                transferMode = TFTP.ASCII_MODE;
            else if (arg.equals("-b"))
                transferMode = TFTP.BINARY_MODE;
            else {
                System.err.println("Error: unrecognized option.");
                System.err.print(USAGE);
                System.exit(1);
            }
        } else
            break;
    }

    // Make sure there are enough arguments
    if (args.length - argc != 3) {
        System.err.println("Error: invalid number of arguments.");
        System.err.print(USAGE);
        System.exit(1);
    }

    // Get host and file arguments
    hostname = args[argc];
    localFilename = args[argc + 1];
    remoteFilename = args[argc + 2];

    // Create our TFTP instance to handle the file transfer.
    tftp = new TFTPClient();

    // We want to timeout if a response takes longer than 60 seconds
    tftp.setDefaultTimeout(60000);

    // Open local socket
    try {
        tftp.open();
    } catch (SocketException e) {
        System.err.println("Error: could not open local UDP socket.");
        System.err.println(e.getMessage());
        System.exit(1);
    }

    // We haven't closed the local file yet.
    closed = false;

    // If we're receiving a file, receive, otherwise send.
    if (receiveFile) {
        FileOutputStream output = null;
        File file;

        file = new File(localFilename);

        // If file exists, don't overwrite it.
        if (file.exists()) {
            System.err.println("Error: " + localFilename + " already exists.");
            System.exit(1);
        }

        // Try to open local file for writing
        try {
            output = new FileOutputStream(file);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for writing.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to receive remote file via TFTP
        try {
            tftp.receiveFile(remoteFilename, transferMode, output, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while receiving file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and output file
            tftp.close();
            try {
                output.close();
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed)
            System.exit(1);

    } else {
        // We're sending a file
        FileInputStream input = null;

        // Try to open local file for reading
        try {
            input = new FileInputStream(localFilename);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for reading.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to send local file via TFTP
        try {
            tftp.sendFile(remoteFilename, transferMode, input, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while sending file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and input file
            tftp.close();
            try {
                input.close();
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed)
            System.exit(1);

    }

}

From source file:TFTPExample.java

public static void main(String[] args) {
    boolean receiveFile = true, closed;
    int transferMode = TFTP.BINARY_MODE, argc;
    String arg, hostname, localFilename, remoteFilename;
    TFTPClient tftp;/*from  w w  w  . j  a v  a2  s .  c o  m*/

    // Parse options
    for (argc = 0; argc < args.length; argc++) {
        arg = args[argc];
        if (arg.startsWith("-")) {
            if (arg.equals("-r")) {
                receiveFile = true;
            } else if (arg.equals("-s")) {
                receiveFile = false;
            } else if (arg.equals("-a")) {
                transferMode = TFTP.ASCII_MODE;
            } else if (arg.equals("-b")) {
                transferMode = TFTP.BINARY_MODE;
            } else {
                System.err.println("Error: unrecognized option.");
                System.err.print(USAGE);
                System.exit(1);
            }
        } else {
            break;
        }
    }

    // Make sure there are enough arguments
    if (args.length - argc != 3) {
        System.err.println("Error: invalid number of arguments.");
        System.err.print(USAGE);
        System.exit(1);
    }

    // Get host and file arguments
    hostname = args[argc];
    localFilename = args[argc + 1];
    remoteFilename = args[argc + 2];

    // Create our TFTP instance to handle the file transfer.
    tftp = new TFTPClient();

    // We want to timeout if a response takes longer than 60 seconds
    tftp.setDefaultTimeout(60000);

    // Open local socket
    try {
        tftp.open();
    } catch (SocketException e) {
        System.err.println("Error: could not open local UDP socket.");
        System.err.println(e.getMessage());
        System.exit(1);
    }

    // We haven't closed the local file yet.
    closed = false;

    // If we're receiving a file, receive, otherwise send.
    if (receiveFile) {
        FileOutputStream output = null;
        File file;

        file = new File(localFilename);

        // If file exists, don't overwrite it.
        if (file.exists()) {
            System.err.println("Error: " + localFilename + " already exists.");
            System.exit(1);
        }

        // Try to open local file for writing
        try {
            output = new FileOutputStream(file);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for writing.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to receive remote file via TFTP
        try {
            tftp.receiveFile(remoteFilename, transferMode, output, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while receiving file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and output file
            tftp.close();
            try {
                if (output != null) {
                    output.close();
                }
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed) {
            System.exit(1);
        }

    } else {
        // We're sending a file
        FileInputStream input = null;

        // Try to open local file for reading
        try {
            input = new FileInputStream(localFilename);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for reading.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to send local file via TFTP
        try {
            tftp.sendFile(remoteFilename, transferMode, input, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while sending file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and input file
            tftp.close();
            try {
                if (input != null) {
                    input.close();
                }
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed) {
            System.exit(1);
        }
    }
}

From source file:com.xiangzhurui.util.ftp.TFTPExample.java

public static void main(String[] args) {
    boolean receiveFile = true, closed;
    int transferMode = TFTP.BINARY_MODE, argc;
    String arg, hostname, localFilename, remoteFilename;
    TFTPClient tftp;/* w w  w.j ava  2 s . c  om*/

    // Parse options
    for (argc = 0; argc < args.length; argc++) {
        arg = args[argc];
        if (arg.startsWith("-")) {
            if (arg.equals("-r")) {
                receiveFile = true;
            } else if (arg.equals("-s")) {
                receiveFile = false;
            } else if (arg.equals("-a")) {
                transferMode = TFTP.ASCII_MODE;
            } else if (arg.equals("-b")) {
                transferMode = TFTP.BINARY_MODE;
            } else {
                System.err.println("Error: unrecognized option.");
                System.err.print(USAGE);
                System.exit(1);
            }
        } else {
            break;
        }
    }

    // Make sure there are enough arguments
    if (args.length - argc != 3) {
        System.err.println("Error: invalid number of arguments.");
        System.err.print(USAGE);
        System.exit(1);
    }

    // Get host and file arguments
    hostname = args[argc];
    localFilename = args[argc + 1];
    remoteFilename = args[argc + 2];

    // Create our TFTP instance to handle the file transfer.
    tftp = new TFTPClient();

    // We want to timeout if a response takes longer than 60 seconds
    tftp.setDefaultTimeout(60000);

    // Open local socket
    try {
        tftp.open();
    } catch (SocketException e) {
        System.err.println("Error: could not open local UDP socket.");
        System.err.println(e.getMessage());
        System.exit(1);
    }

    // We haven't closed the local file yet.
    closed = false;

    // If we're receiving a file, receive, otherwise send.
    if (receiveFile) {
        FileOutputStream output = null;
        File file;

        file = new File(localFilename);

        // If file exists, don't overwrite it.
        if (file.exists()) {
            System.err.println("Error: " + localFilename + " already exists.");
            System.exit(1);
        }

        // Try to open local file for writing
        try {
            output = new FileOutputStream(file);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for writing.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to receive remote file via TFTP
        try {
            tftp.receiveFile(remoteFilename, transferMode, output, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while receiving file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and output file
            tftp.close();
            try {
                if (output != null) {
                    output.close();
                }
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed) {
            System.exit(1);
        }

    } else {
        // We're sending a file
        FileInputStream input = null;

        // Try to open local file for reading
        try {
            input = new FileInputStream(localFilename);
        } catch (IOException e) {
            tftp.close();
            System.err.println("Error: could not open local file for reading.");
            System.err.println(e.getMessage());
            System.exit(1);
        }

        // Try to send local file via TFTP
        try {
            tftp.sendFile(remoteFilename, transferMode, input, hostname);
        } catch (UnknownHostException e) {
            System.err.println("Error: could not resolve hostname.");
            System.err.println(e.getMessage());
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Error: I/O exception occurred while sending file.");
            System.err.println(e.getMessage());
            System.exit(1);
        } finally {
            // Close local socket and input file
            tftp.close();
            try {
                if (input != null) {
                    input.close();
                }
                closed = true;
            } catch (IOException e) {
                closed = false;
                System.err.println("Error: error closing file.");
                System.err.println(e.getMessage());
            }
        }

        if (!closed) {
            System.exit(1);
        }

    }

}

From source file:net.schweerelos.parrot.CombinedParrotApp.java

/**
 * @param args/*from w w w.j a  va2s . co  m*/
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    CommandLineParser parser = new PosixParser();
    // create the Options
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("help")
            .withDescription("Shows usage information and quits the program").create("h"));

    options.addOption(
            OptionBuilder.withLongOpt("datafile").withDescription("The file with instances to use (required)")
                    .hasArg().withArgName("file").isRequired().create("f"));

    options.addOption(OptionBuilder.withLongOpt("properties")
            .withDescription("Properties file to use. Default: " + System.getProperty("user.home")
                    + File.separator + ".digital-parrot" + File.separator + "parrot.properties")
            .hasArg().withArgName("prop").create("p"));
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("h")) {
            // this is only executed when all required options are present _and_ the help option is specified!
            printHelp(options);
            return;
        }

        String datafile = line.getOptionValue("f");
        if (!datafile.startsWith("file:") || !datafile.startsWith("http:")) {
            datafile = "file:" + datafile;
        }

        String propertiesPath = System.getProperty("user.home") + File.separator + ".digital-parrot"
                + File.separator + "parrot.properties";
        if (line.hasOption("p")) {
            propertiesPath = line.getOptionValue("p");
        }
        final Properties properties = new Properties();
        File propertiesFile = new File(propertiesPath);
        if (propertiesFile.exists() && propertiesFile.canRead()) {
            try {
                properties.load(new FileReader(propertiesFile));
            } catch (FileNotFoundException e) {
                e.printStackTrace(System.err);
                System.exit(1);
            } catch (IOException e) {
                e.printStackTrace(System.err);
                System.exit(1);
            }
        }

        final String url = datafile; // we need a "final" var for the anonymous class
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                CombinedParrotApp inst = null;
                try {
                    inst = new CombinedParrotApp(properties);
                    inst.loadModel(url);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null,
                            "There has been an error while starting the program.\nThe program will exit now.",
                            APP_TITLE + "  Error", JOptionPane.ERROR_MESSAGE);
                    e.printStackTrace(System.err);
                    System.exit(1);
                }
                if (inst != null) {
                    inst.setLocationRelativeTo(null);
                    inst.setVisible(true);
                }
            }
        });
    } catch (ParseException exp) {
        printHelp(options);
    }
}

From source file:au.org.ands.vocabs.toolkit.db.PopulateAccessPoints.java

/**
 * Main program./* w  w w  .j  a  v a  2s.c  om*/
 * @param args Command-line arguments
 */
public static void main(final String[] args) {
    // Create prefixes that both end with a slash, so that
    // they can be substituted for each other.
    String sparqlPrefix = sparqlPrefixProperty;
    if (!sparqlPrefix.endsWith("/")) {
        sparqlPrefix += "/";
    }
    String sesamePrefix = sesamePrefixProperty;
    if (!sesamePrefix.endsWith("/")) {
        sesamePrefix += "/";
    }
    sesamePrefix += "repositories/";
    System.out.println("sparqlPrefix: " + sparqlPrefix);
    System.out.println("sesamePrefix: " + sesamePrefix);
    List<Version> versions = VersionUtils.getAllVersions();
    for (Version version : versions) {
        System.out.println(version.getId());
        System.out.println(version.getTitle());
        String data = version.getData();
        System.out.println(data);
        JsonNode dataJson = TaskUtils.jsonStringToTree(data);
        JsonNode accessPoints = dataJson.get("access_points");
        if (accessPoints != null) {
            System.out.println(accessPoints);
            System.out.println(accessPoints.size());
            for (JsonNode accessPoint : accessPoints) {
                System.out.println(accessPoint);
                AccessPoint ap = new AccessPoint();
                ap.setVersionId(version.getId());
                String type = accessPoint.get("type").asText();
                JsonObjectBuilder jobPortal = Json.createObjectBuilder();
                JsonObjectBuilder jobToolkit = Json.createObjectBuilder();
                String uri;
                switch (type) {
                case AccessPoint.FILE_TYPE:
                    ap.setType(type);
                    // Get the path from the original access point.
                    String filePath = accessPoint.get("uri").asText();
                    // Save the last component of the path to use
                    // in the portal URI.
                    String downloadFilename = Paths.get(filePath).getFileName().toString();
                    if (!filePath.startsWith("/")) {
                        // Relative path that we need to fix up manually.
                        filePath = "FIXME " + filePath;
                    }
                    jobToolkit.add("path", filePath);
                    ap.setPortalData("");
                    ap.setToolkitData(jobToolkit.build().toString());
                    // Persist what we have ...
                    AccessPointUtils.saveAccessPoint(ap);
                    // ... so that now we can get access to the
                    // ID of the persisted object with ap2.getId().
                    String format;
                    if (downloadFilename.endsWith(".trig")) {
                        // Force TriG. This is needed for some legacy
                        // cases where the filename is ".trig" but
                        // the format has been incorrectly recorded
                        // as RDF/XML.
                        format = "TriG";
                    } else {
                        format = accessPoint.get("format").asText();
                    }
                    jobPortal.add("format", format);
                    jobPortal.add("uri", downloadPrefixProperty + ap.getId() + "/" + downloadFilename);
                    ap.setPortalData(jobPortal.build().toString());
                    AccessPointUtils.updateAccessPoint(ap);
                    break;
                case AccessPoint.API_SPARQL_TYPE:
                    ap.setType(type);
                    uri = accessPoint.get("uri").asText();
                    jobPortal.add("uri", uri);
                    if (uri.startsWith(sparqlPrefix)) {
                        // One of ours, so also add a sesameDownload
                        // endpoint.
                        AccessPoint ap2 = new AccessPoint();
                        ap2.setVersionId(version.getId());
                        ap2.setType(AccessPoint.SESAME_DOWNLOAD_TYPE);
                        ap2.setPortalData("");
                        ap2.setToolkitData("");
                        // Persist what we have ...
                        AccessPointUtils.saveAccessPoint(ap2);
                        // ... so that now we can get access to the
                        // ID of the persisted object with ap2.getId().
                        JsonObjectBuilder job2Portal = Json.createObjectBuilder();
                        JsonObjectBuilder job2Toolkit = Json.createObjectBuilder();
                        job2Portal.add("uri", downloadPrefixProperty + ap2.getId() + "/"
                                + Download.downloadFilename(ap2, ""));
                        job2Toolkit.add("uri", uri.replaceFirst(sparqlPrefix, sesamePrefix));
                        ap2.setPortalData(job2Portal.build().toString());
                        ap2.setToolkitData(job2Toolkit.build().toString());
                        AccessPointUtils.updateAccessPoint(ap2);
                        jobPortal.add("source", AccessPoint.SYSTEM_SOURCE);
                    } else {
                        jobPortal.add("source", AccessPoint.USER_SOURCE);
                    }
                    ap.setPortalData(jobPortal.build().toString());
                    ap.setToolkitData(jobToolkit.build().toString());
                    AccessPointUtils.saveAccessPoint(ap);
                    break;
                case AccessPoint.WEBPAGE_TYPE:
                    uri = accessPoint.get("uri").asText();
                    if (uri.endsWith("concept/topConcepts")) {
                        ap.setType(AccessPoint.SISSVOC_TYPE);
                        jobPortal.add("source", AccessPoint.SYSTEM_SOURCE);
                        jobPortal.add("uri", uri.replaceFirst("/concept/topConcepts$", ""));
                    } else {
                        ap.setType(type);
                        jobPortal.add("uri", uri);
                    }
                    ap.setPortalData(jobPortal.build().toString());
                    ap.setToolkitData(jobToolkit.build().toString());
                    AccessPointUtils.saveAccessPoint(ap);
                    break;
                default:
                }
                System.out.println("type is: " + ap.getType());
                System.out.println("portal_data: " + ap.getPortalData());
                System.out.println("toolkit_data: " + ap.getToolkitData());
            }
        }
    }
}

From source file:com.genentech.chemistry.openEye.apps.SdfRMSDNNFinder.java

public static void main(String[] args) throws IOException {
    Options options = new Options();
    Option opt = new Option(OPT_INFILE, true,
            "input file oe-supported Use .sdf|.smi to specify the file type.");
    opt.setRequired(true);//from   w  w  w  .  j a  v a 2  s . c  o m
    options.addOption(opt);

    opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_REFFILE, true, "Reference file containing poses from reference docking run. " + "If "
            + OPT_REFFILE + " not specified, program uses the input file " + "(internal NN analysis)");
    options.addOption(opt);

    opt = new Option(OPT_MOLIdTag, true, "Name of the field containing the molecule identifier. "
            + " Assumption: Ref file uses the same field name.");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option(OPT_DONotOpt, false,
            "If specified the RMSD is computed without trying to optimize the alignment.");
    options.addOption(opt);

    opt = new Option(OPT_MIRROR, false, "For non-chiral molecules also try mirror image");
    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 (args.length != 0) {
        ; //error message
    }

    String inFile = cmd.getOptionValue(OPT_INFILE);
    String outFile = cmd.getOptionValue(OPT_OUTFILE);

    String refFile = cmd.getOptionValue(OPT_REFFILE);
    boolean noRefFile = false;
    if (refFile == null) {
        if (inFile.startsWith("."))
            inFile = writeRefMolPosesToTempFile(inFile);
        refFile = inFile;
        noRefFile = true;
    }

    String molIdTag = cmd.getOptionValue(OPT_MOLIdTag);
    boolean doOptimize = !cmd.hasOption(OPT_DONotOpt);
    boolean doMirror = cmd.hasOption(OPT_MIRROR);

    SdfRMSDNNFinder nnFinder = new SdfRMSDNNFinder(refFile, outFile, molIdTag, doMirror, doOptimize, noRefFile);

    nnFinder.run(inFile);
    nnFinder.close();
}

From source file:VerboseGC.java

public static void main(String[] args) {
    if (args.length < 1) {
        usage();//from   w  w  w.  j  av  a  2 s . com
    }

    String hostname = "";
    int port = -1;
    long interval = 5000; // default is 5 second interval
    long mins = 5;
    for (int argIndex = 0; argIndex < args.length; argIndex++) {
        String arg = args[argIndex];
        if (args[argIndex].startsWith("-")) {
            if (arg.equals("-h") || arg.equals("-help") || arg.equals("-?")) {
                usage();
            } else if (arg.startsWith("-interval=")) {
                try {
                    interval = Integer.parseInt(arg.substring(10)) * 1000;
                } catch (NumberFormatException ex) {
                    usage();
                }
            } else if (arg.startsWith("-duration=")) {
                try {
                    mins = Integer.parseInt(arg.substring(10));
                } catch (NumberFormatException ex) {
                    usage();
                }
            } else {
                // Unknown switch
                System.err.println("Unrecognized option: " + arg);
                usage();
            }
        } else {
            String[] arg2 = arg.split(":");
            if (arg2.length != 2) {
                usage();
            }
            hostname = arg2[0];
            try {
                port = Integer.parseInt(arg2[1]);
            } catch (NumberFormatException x) {
                usage();
            }
            if (port < 0) {
                usage();
            }
        }
    }

    // get full thread dump and perform deadlock detection
    VerboseGC vgc = new VerboseGC(hostname, port);
    long samples = (mins * 60 * 1000) / interval;
    vgc.dump(interval, samples);

}