Example usage for java.lang String substring

List of usage examples for java.lang String substring

Introduction

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

Prototype

public String substring(int beginIndex, int endIndex) 

Source Link

Document

Returns a string that is a substring of this string.

Usage

From source file:MainServer.java

public static void main(String[] args) {
    int port = 1234;
    String filepath = "";
    String complete_path = "";
    String connection_type = "";
    String ip_address = "";
    int port_out = 0;
    int delay = 20; //20 by default

    //parse commands using getOpt (cli)
    //add Options
    Options options = new Options();

    options.addOption("p", true, "port_to_listen_on");
    options.addOption("d", true, "directory");
    options.addOption("T", false, "TCP mode");
    options.addOption("U", false, "UDP mode");
    options.addOption("s", true, "iPAddress");
    options.addOption("P", true, "port_to_connect_to");
    options.addOption("D", true, "delay");

    CommandLineParser clp = new DefaultParser();
    try {/*from  w  ww .j a va2 s .co  m*/
        CommandLine cl = clp.parse(options, args);

        //options for the server
        if (cl.hasOption("p")) {
            port = Integer.parseInt(cl.getOptionValue("p"));
        } else {
            System.err.println("No valid port selected.");
            return;
        }

        if (cl.hasOption("d")) {
            filepath = cl.getOptionValue("d");
            //if there a '/' in front, remove it to make it a valid directory
            if (filepath.substring(0, 1).equalsIgnoreCase("/")) {
                filepath = filepath.substring(1);
            }
        } else {
            System.err.println("No valid directory given.");
            return;
        }

        if (cl.hasOption("D")) {
            delay = Integer.parseInt(cl.getOptionValue("D"));
        }

        //options for the client
        if (cl.hasOption("T")) {
            connection_type = "T";
        } else if (cl.hasOption("U")) {
            connection_type = "U";
        }

        if (cl.hasOption("s")) {
            ip_address = cl.getOptionValue("s");
        }

        if (cl.hasOption("P")) {
            port_out = Integer.parseInt(cl.getOptionValue("P"));
        }

    } catch (ParseException e) {
        //TODO: handle exception
    }

    //create directory (if it doesn't already exist)
    try {
        Files.createDirectories(Paths.get(filepath));
    } catch (Exception e) {
        //TODO: handle exception
        System.err.println("Couldn't create directory");
        System.err.println(filepath);
    }

    //read in required files (create them if they dont already exist)
    try {
        Files.createFile(Paths.get(filepath + "/gossip.txt"));
        Files.createFile(Paths.get(filepath + "/peers.txt"));
    } catch (Exception e) {
        //TODO: handle exception
    }
    WriteToFiles.readFiles(filepath);

    //start the servers
    TCPServerSock tcpServer = new TCPServerSock(port, filepath, delay);
    UDPServer udpServer = new UDPServer(port, filepath);

    Thread tcpThread = new Thread(tcpServer);
    Thread udpThread = new Thread(udpServer);

    tcpThread.start();
    udpThread.start();

    //start the client
    if (!connection_type.equals("") && port_out != 0 && !ip_address.equals("")) {
        Client client = new Client(ip_address, port_out, connection_type);
        Thread clientThread = new Thread(client);
        clientThread.start();
    }

    //Start thread to forget peers
    ForgetPeer forgetPeer = new ForgetPeer(filepath + "/peers.txt", delay);
    Thread forgetPeerThread = new Thread(forgetPeer);
    forgetPeerThread.start();
}

From source file:com.github.s4ke.moar.cli.Main.java

public static void main(String[] args) throws ParseException, IOException {
    // create Options object
    Options options = new Options();

    options.addOption("rf", true,
            "file containing the regexes to test against (multiple regexes are separated by one empty line)");
    options.addOption("r", true, "regex to test against");

    options.addOption("mf", true, "file/folder to read the MOA from");
    options.addOption("mo", true, "folder to export the MOAs to (overwrites if existent)");

    options.addOption("sf", true, "file to read the input string(s) from");
    options.addOption("s", true, "string to test the MOA/Regex against");

    options.addOption("m", false, "multiline matching mode (search in string for regex)");

    options.addOption("ls", false, "treat every line of the input string file as one string");
    options.addOption("t", false, "trim lines if -ls is set");

    options.addOption("d", false, "only do determinism check");

    options.addOption("help", false, "prints this dialog");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (args.length == 0 || cmd.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("moar-cli", options);
        return;/*from  w  ww  . jav a  2 s  .  c o  m*/
    }

    List<String> patternNames = new ArrayList<>();
    List<MoaPattern> patterns = new ArrayList<>();
    List<String> stringsToCheck = new ArrayList<>();

    if (cmd.hasOption("r")) {
        String regexStr = cmd.getOptionValue("r");
        try {
            patterns.add(MoaPattern.compile(regexStr));
            patternNames.add(regexStr);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    if (cmd.hasOption("rf")) {
        String fileName = cmd.getOptionValue("rf");
        List<String> regexFileContents = readFileContents(new File(fileName));
        int emptyLineCountAfterRegex = 0;
        StringBuilder regexStr = new StringBuilder();
        for (String line : regexFileContents) {
            if (emptyLineCountAfterRegex >= 1) {
                if (regexStr.length() > 0) {
                    patterns.add(MoaPattern.compile(regexStr.toString()));
                    patternNames.add(regexStr.toString());
                }
                regexStr.setLength(0);
                emptyLineCountAfterRegex = 0;
            }
            if (line.trim().equals("")) {
                if (regexStr.length() > 0) {
                    ++emptyLineCountAfterRegex;
                }
            } else {
                regexStr.append(line);
            }
        }
        if (regexStr.length() > 0) {
            try {
                patterns.add(MoaPattern.compile(regexStr.toString()));
                patternNames.add(regexStr.toString());
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return;
            }
            regexStr.setLength(0);
        }
    }

    if (cmd.hasOption("mf")) {
        String fileName = cmd.getOptionValue("mf");
        File file = new File(fileName);
        if (file.isDirectory()) {
            System.out.println(fileName + " is a directory, using all *.moar files as patterns");
            File[] moarFiles = file.listFiles(pathname -> pathname.getName().endsWith(".moar"));
            for (File moar : moarFiles) {
                String jsonString = readWholeFile(moar);
                patterns.add(MoarJSONSerializer.fromJSON(jsonString));
                patternNames.add(moar.getAbsolutePath());
            }
        } else {
            System.out.println(fileName + " is a single file. using it directly (no check for *.moar suffix)");
            String jsonString = readWholeFile(file);
            patterns.add(MoarJSONSerializer.fromJSON(jsonString));
            patternNames.add(fileName);
        }
    }

    if (cmd.hasOption("s")) {
        String str = cmd.getOptionValue("s");
        stringsToCheck.add(str);
    }

    if (cmd.hasOption("sf")) {
        boolean treatLineAsString = cmd.hasOption("ls");
        boolean trim = cmd.hasOption("t");
        String fileName = cmd.getOptionValue("sf");
        StringBuilder stringBuilder = new StringBuilder();
        boolean firstLine = true;
        for (String str : readFileContents(new File(fileName))) {
            if (treatLineAsString) {
                if (trim) {
                    str = str.trim();
                    if (str.length() == 0) {
                        continue;
                    }
                }
                stringsToCheck.add(str);
            } else {
                if (!firstLine) {
                    stringBuilder.append("\n");
                }
                if (firstLine) {
                    firstLine = false;
                }
                stringBuilder.append(str);
            }
        }
        if (!treatLineAsString) {
            stringsToCheck.add(stringBuilder.toString());
        }
    }

    if (cmd.hasOption("d")) {
        //at this point we have already built the Patterns
        //so just give the user a short note.
        System.out.println("All Regexes seem to be deterministic.");
        return;
    }

    if (patterns.size() == 0) {
        System.out.println("no patterns to check");
        return;
    }

    if (cmd.hasOption("mo")) {
        String folder = cmd.getOptionValue("mo");
        File folderFile = new File(folder);
        if (!folderFile.exists()) {
            System.out.println(folder + " does not exist. creating...");
            if (!folderFile.mkdirs()) {
                System.out.println("folder " + folder + " could not be created");
            }
        }
        int cnt = 0;
        for (MoaPattern pattern : patterns) {
            String patternAsJSON = MoarJSONSerializer.toJSON(pattern);
            try (BufferedWriter writer = new BufferedWriter(
                    new FileWriter(new File(folderFile, "pattern" + ++cnt + ".moar")))) {
                writer.write(patternAsJSON);
            }
        }
        System.out.println("stored " + cnt + " patterns in " + folder);
    }

    if (stringsToCheck.size() == 0) {
        System.out.println("no strings to check");
        return;
    }

    boolean multiline = cmd.hasOption("m");

    for (String string : stringsToCheck) {
        int curPattern = 0;
        for (MoaPattern pattern : patterns) {
            MoaMatcher matcher = pattern.matcher(string);
            if (!multiline) {
                if (matcher.matches()) {
                    System.out.println("\"" + patternNames.get(curPattern) + "\" matches \"" + string + "\"");
                } else {
                    System.out.println(
                            "\"" + patternNames.get(curPattern) + "\" does not match \"" + string + "\"");
                }
            } else {
                StringBuilder buffer = new StringBuilder(string);
                int additionalCharsPerMatch = ("<match>" + "</match>").length();
                int matchCount = 0;
                while (matcher.nextMatch()) {
                    buffer.replace(matcher.getStart() + matchCount * additionalCharsPerMatch,
                            matcher.getEnd() + matchCount * additionalCharsPerMatch,
                            "<match>" + string.substring(matcher.getStart(), matcher.getEnd()) + "</match>");
                    ++matchCount;
                }
                System.out.println(buffer.toString());
            }
        }
        ++curPattern;
    }
}

From source file:com.cloud.test.utils.SubmitCert.java

public static void main(String[] args) {
    // Parameters
    List<String> argsList = Arrays.asList(args);
    Iterator<String> iter = argsList.iterator();
    while (iter.hasNext()) {
        String arg = iter.next();

        if (arg.equals("-c")) {
            certFileName = iter.next();//from www. j  a  v  a2  s .  c  om
        }

        if (arg.equals("-s")) {
            secretKey = iter.next();
        }

        if (arg.equals("-a")) {
            apiKey = iter.next();
        }

        if (arg.equals("-action")) {
            url = "Action=" + iter.next();
        }
    }

    Properties prop = new Properties();
    try {
        prop.load(new FileInputStream("conf/tool.properties"));
    } catch (IOException ex) {
        s_logger.error("Error reading from conf/tool.properties", ex);
        System.exit(2);
    }

    host = prop.getProperty("host");
    port = prop.getProperty("port");

    if (url.equals("Action=SetCertificate") && certFileName == null) {
        s_logger.error("Please set path to certificate (including file name) with -c option");
        System.exit(1);
    }

    if (secretKey == null) {
        s_logger.error("Please set secretkey  with -s option");
        System.exit(1);
    }

    if (apiKey == null) {
        s_logger.error("Please set apikey with -a option");
        System.exit(1);
    }

    if (host == null) {
        s_logger.error("Please set host in tool.properties file");
        System.exit(1);
    }

    if (port == null) {
        s_logger.error("Please set port in tool.properties file");
        System.exit(1);
    }

    TreeMap<String, String> param = new TreeMap<String, String>();

    String req = "GET\n" + host + ":" + prop.getProperty("port") + "\n/" + prop.getProperty("accesspoint")
            + "\n";
    String temp = "";

    if (certFileName != null) {
        cert = readCert(certFileName);
        param.put("cert", cert);
    }

    param.put("AWSAccessKeyId", apiKey);
    param.put("Expires", prop.getProperty("expires"));
    param.put("SignatureMethod", prop.getProperty("signaturemethod"));
    param.put("SignatureVersion", "2");
    param.put("Version", prop.getProperty("version"));

    StringTokenizer str1 = new StringTokenizer(url, "&");
    while (str1.hasMoreTokens()) {
        String newEl = str1.nextToken();
        StringTokenizer str2 = new StringTokenizer(newEl, "=");
        String name = str2.nextToken();
        String value = str2.nextToken();
        param.put(name, value);
    }

    //sort url hash map by key
    Set c = param.entrySet();
    Iterator it = c.iterator();
    while (it.hasNext()) {
        Map.Entry me = (Map.Entry) it.next();
        String key = (String) me.getKey();
        String value = (String) me.getValue();
        try {
            temp = temp + key + "=" + URLEncoder.encode(value, "UTF-8") + "&";
        } catch (Exception ex) {
            s_logger.error("Unable to set parameter " + value + " for the command " + param.get("command"), ex);
        }

    }
    temp = temp.substring(0, temp.length() - 1);
    String requestToSign = req + temp;
    String signature = UtilsForTest.signRequest(requestToSign, secretKey);
    String encodedSignature = "";
    try {
        encodedSignature = URLEncoder.encode(signature, "UTF-8");
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    String url = "http://" + host + ":" + prop.getProperty("port") + "/" + prop.getProperty("accesspoint") + "?"
            + temp + "&Signature=" + encodedSignature;
    s_logger.info("Sending request with url:  " + url + "\n");
    sendRequest(url);
}

From source file:SIFT_Volume_Stitching.java

public static void main(String[] args) {
    // set the plugins.dir property to make the plugin appear in the Plugins menu
    Class<?> clazz = SIFT_Volume_Stitching.class;
    String url = clazz.getResource("/" + clazz.getName().replace('.', '/') + ".class").toString();
    String pluginsDir = url.substring("file:".length(),
            url.length() - clazz.getName().length() - ".class".length());
    System.setProperty("plugins.dir", pluginsDir);

    // start ImageJ
    new ImageJ();

    // open the Clown sample
    ImagePlus image1 = IJ.openImage("https://www.creatis.insa-lyon.fr/~frindel/BackStack115.tif");
    ImagePlus image2 = IJ.openImage("https://www.creatis.insa-lyon.fr/~frindel/FrontStack.tif");
    image1.show();//from  w  w w  .j  a  v  a2  s . c o  m
    image2.show();

    // run the plugin
    IJ.runPlugIn(clazz.getName(), "");
}

From source file:TwoFourTree.java

/**
 * The main method which the program executes from and which handles all
 * testing and input/output./*from  w  ww.  j a va 2 s . c om*/
 * 
 * @param args String[]
 */
public static void main(String[] args) throws IOException {
    Comparator myComp = new IntegerComparator();
    TwoFourTree myTree = new TwoFourTree(myComp);
    TwoFourTree firstTree = new TwoFourTree(myComp);
    TwoFourTree secondTree = new TwoFourTree(myComp);
    BufferedReader myReader = new BufferedReader(new InputStreamReader(System.in));
    String input;
    boolean go = true;

    while (go == true) {
        System.out.print(
                "Format like this:  -a 37 to add a 37 to the tree. -r 37 to remove a 37 from the tree: ");
        input = myReader.readLine();

        if (input.substring(0, 2).equals("-a")) {
            Integer myInt = new Integer(input.substring(3, input.length()));
            myTree.insertElement(myInt, myInt);
            myTree.printAllElements();
        } else if (input.substring(0, 2).equals("-r")) {
            Integer myInt = new Integer(input.substring(3, input.length()));
            myTree.removeElement(myInt);
            myTree.printAllElements();
        } else
            System.out.print("\nYou're bad!");

        System.out.print("\n");

    }

    /*System.out.println("Loading firstTree with values ...");
            
    Integer firstInt1 = new Integer(20);
    firstTree.insertElement(firstInt1, firstInt1);
    Integer firstInt2 = new Integer(50);
    firstTree.insertElement(firstInt2, firstInt2);
    Integer firstInt3 = new Integer(30);
    firstTree.insertElement(firstInt3, firstInt3);
    Integer firstInt4 = new Integer(40);
    firstTree.insertElement(firstInt4, firstInt4);
    Integer firstInt5 = new Integer(15);
    firstTree.insertElement(firstInt5, firstInt5);
    Integer firstInt6 = new Integer(35);
    firstTree.insertElement(firstInt6, firstInt6);
    Integer firstInt7 = new Integer(55);
    firstTree.insertElement(firstInt7, firstInt7);
    Integer firstInt8 = new Integer(38);
    firstTree.insertElement(firstInt8, firstInt8);
    Integer firstInt9 = new Integer(17);
    firstTree.insertElement(firstInt9, firstInt9);
    Integer firstInt10 = new Integer(37);
    firstTree.insertElement(firstInt10, firstInt10);
    Integer firstInt11 = new Integer(16);
    firstTree.insertElement(firstInt11, firstInt11);
    Integer firstInt12 = new Integer(36);
    firstTree.insertElement(firstInt12, firstInt12);
    Integer firstInt13 = new Integer(15);
    firstTree.insertElement(firstInt13, firstInt13);
    Integer firstInt14 = new Integer(36);
    firstTree.insertElement(firstInt14, firstInt14);
    Integer firstInt15 = new Integer(30);
    firstTree.insertElement(firstInt15, firstInt15);
    Integer firstInt16 = new Integer(34);
    firstTree.insertElement(firstInt16, firstInt16);
    Integer firstInt17 = new Integer(34);
    firstTree.insertElement(firstInt17, firstInt17);
    Integer firstInt18 = new Integer(30);
    firstTree.insertElement(firstInt18, firstInt18);
    Integer firstInt19 = new Integer(30);
    firstTree.insertElement(firstInt18, firstInt18);
            
    System.out.println("firstTree is fully loaded as follows:");
    firstTree.printAllElements();
    System.out.println("Checking parent/child connections ...");
    firstTree.checkTree(firstTree.root());
    System.out.println("All parent/child connections valid.");
            
    System.out.println("\nRemove 30");
    firstTree.removeElement(30);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 30");
    firstTree.removeElement(30);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 30");
    firstTree.removeElement(30);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 30");
    firstTree.removeElement(30);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 15");
    firstTree.removeElement(15);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 55");
    firstTree.removeElement(55);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 35");
    firstTree.removeElement(35);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 38");
    firstTree.removeElement(38);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 40");
    firstTree.removeElement(40);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 36");
    firstTree.removeElement(36);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 17");
    firstTree.removeElement(17);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 34");
    firstTree.removeElement(34);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 34");
    firstTree.removeElement(34);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 36");
    firstTree.removeElement(36);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 20");
    firstTree.removeElement(20);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 37");
    firstTree.removeElement(37);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 16");
    firstTree.removeElement(16);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 50");
    firstTree.removeElement(50);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 15");
    firstTree.removeElement(15);
    System.out.println("Removed successfully. Print new tree:");
    firstTree.printAllElements();
    System.out.println("done");
            
    System.out.println("\n\nLoading secondTree with values ...");
            
    Integer secondInt1 = new Integer(47);
    secondTree.insertElement(secondInt1, secondInt1);
    Integer secondInt2 = new Integer(83);
    secondTree.insertElement(secondInt2, secondInt2);
    Integer secondInt3 = new Integer(22);
    secondTree.insertElement(secondInt3, secondInt3);
    Integer secondInt4 = new Integer(16);
    secondTree.insertElement(secondInt4, secondInt4);
    Integer secondInt5 = new Integer(49);
    secondTree.insertElement(secondInt5, secondInt5);
    Integer secondInt6 = new Integer(100);
    secondTree.insertElement(secondInt6, secondInt6);
    Integer secondInt7 = new Integer(38);
    secondTree.insertElement(secondInt7, secondInt7);
    Integer secondInt8 = new Integer(3);
    secondTree.insertElement(secondInt8, secondInt8);
    Integer secondInt9 = new Integer(53);
    secondTree.insertElement(secondInt9, secondInt9);
    Integer secondInt10 = new Integer(66);
    secondTree.insertElement(secondInt10, secondInt10);
    Integer secondInt11 = new Integer(19);
    secondTree.insertElement(secondInt11, secondInt11);
    Integer secondInt12 = new Integer(23);
    secondTree.insertElement(secondInt12, secondInt12);
    Integer secondInt13 = new Integer(24);
    secondTree.insertElement(secondInt13, secondInt13);
    Integer secondInt14 = new Integer(88);
    secondTree.insertElement(secondInt14, secondInt14);
    Integer secondInt15 = new Integer(1);
    secondTree.insertElement(secondInt15, secondInt15);
    Integer secondInt16 = new Integer(97);
    secondTree.insertElement(secondInt16, secondInt16);
    Integer secondInt17 = new Integer(94);
    secondTree.insertElement(secondInt17, secondInt17);
    Integer secondInt18 = new Integer(35);
    secondTree.insertElement(secondInt18, secondInt18);
    Integer secondInt19 = new Integer(51);
    secondTree.insertElement(secondInt19, secondInt19);
            
    System.out.println("firstTree is fully loaded as follows:");
    secondTree.printAllElements();
    System.out.println("Checking parent/child connections ...");
    secondTree.checkTree(secondTree.root());
    System.out.println("All parent/child connections valid.");
            
    System.out.println("\nRemove 19");
    secondTree.removeElement(19);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 3");
    secondTree.removeElement(3);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 66");
    secondTree.removeElement(66);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 88");
    secondTree.removeElement(88);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 94");
    secondTree.removeElement(94);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 100");
    secondTree.removeElement(100);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 97");
    secondTree.removeElement(97);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 47");
    secondTree.removeElement(47);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 53");
    secondTree.removeElement(53);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 38");
    secondTree.removeElement(38);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 24");
    secondTree.removeElement(24);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 83");
    secondTree.removeElement(83);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 49");
    secondTree.removeElement(49);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 23");
    secondTree.removeElement(23);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 51");
    secondTree.removeElement(51);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 1");
    secondTree.removeElement(1);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 22");
    secondTree.removeElement(22);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 16");
    secondTree.removeElement(16);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("");
    System.out.println("Remove 35");
    secondTree.removeElement(35);
    System.out.println("Removed successfully. Print new tree:");
    secondTree.printAllElements();
    System.out.println("done");*/
}

From source file:com.joliciel.jochre.Jochre.java

public static void main(String[] args) throws Exception {
    Map<String, String> argMap = new HashMap<String, String>();

    for (String arg : args) {
        int equalsPos = arg.indexOf('=');
        String argName = arg.substring(0, equalsPos);
        String argValue = arg.substring(equalsPos + 1);
        argMap.put(argName, argValue);//  w  ww .ja  va 2 s.  c  o  m
    }

    Jochre jochre = new Jochre();
    jochre.execute(argMap);
}

From source file:net.sf.freecol.FreeCol.java

/**
 * The entrypoint./*from w w  w  .jav a 2  s  .  c om*/
 *
 * @param args The command-line arguments.
 * @throws IOException 
 * @throws FontFormatException 
 */
public static void main(String[] args) throws FontFormatException, IOException {
    freeColRevision = FREECOL_VERSION;
    JarURLConnection juc;
    try {
        juc = getJarURLConnection(FreeCol.class);
    } catch (IOException ioe) {
        juc = null;
        System.err.println("Unable to open class jar: " + ioe.getMessage());
    }
    if (juc != null) {
        try {
            String revision = readVersion(juc);
            if (revision != null) {
                freeColRevision += " (Revision: " + revision + ")";
            }
        } catch (Exception e) {
            System.err.println("Unable to load Manifest: " + e.getMessage());
        }
        try {
            splashStream = getDefaultSplashStream(juc);
        } catch (Exception e) {
            System.err.println("Unable to open default splash: " + e.getMessage());
        }
    }

    // Java bug #7075600 causes BR#2554.  The workaround is to set
    // the following property.  Remove if/when they fix Java.
    System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");

    // We can not even emit localized error messages until we find
    // the data directory, which might have been specified on the
    // command line.
    String dataDirectoryArg = findArg("--freecol-data", args);
    String err = FreeColDirectories.setDataDirectory(dataDirectoryArg);
    if (err != null)
        fatal(err); // This must not fail.

    // Now we have the data directory, establish the base locale.
    // Beware, the locale may change!
    String localeArg = findArg("--default-locale", args);
    if (localeArg == null) {
        locale = Locale.getDefault();
    } else {
        int index = localeArg.indexOf('.'); // Strip encoding if present
        if (index > 0)
            localeArg = localeArg.substring(0, index);
        locale = Messages.getLocale(localeArg);
    }
    Messages.loadMessageBundle(locale);

    // Now that we can emit error messages, parse the other
    // command line arguments.
    handleArgs(args);

    // Do the potentially fatal system checks as early as possible.
    if (javaCheck && JAVA_VERSION_MIN.compareTo(JAVA_VERSION) > 0) {
        fatal(StringTemplate.template("main.javaVersion").addName("%version%", JAVA_VERSION)
                .addName("%minVersion%", JAVA_VERSION_MIN));
    }
    if (memoryCheck && MEMORY_MAX < MEMORY_MIN * 1000000) {
        fatal(StringTemplate.template("main.memory").addAmount("%memory%", MEMORY_MAX).addAmount("%minMemory%",
                MEMORY_MIN));
    }

    // Having parsed the command line args, we know where the user
    // directories should be, so we can set up the rest of the
    // file/directory structure.
    String userMsg = FreeColDirectories.setUserDirectories();

    // Now we have the log file path, start logging.
    final Logger baseLogger = Logger.getLogger("");
    final Handler[] handlers = baseLogger.getHandlers();
    for (Handler handler : handlers) {
        baseLogger.removeHandler(handler);
    }
    String logFile = FreeColDirectories.getLogFilePath();
    try {
        baseLogger.addHandler(new DefaultHandler(consoleLogging, logFile));
        Logger freecolLogger = Logger.getLogger("net.sf.freecol");
        freecolLogger.setLevel(logLevel);
    } catch (FreeColException e) {
        System.err.println("Logging initialization failure: " + e.getMessage());
        e.printStackTrace();
    }
    Thread.setDefaultUncaughtExceptionHandler((Thread thread, Throwable e) -> {
        baseLogger.log(Level.WARNING, "Uncaught exception from thread: " + thread, e);
    });

    // Now we can find the client options, allow the options
    // setting to override the locale, if no command line option
    // had been specified.
    // We have users whose machines default to Finnish but play
    // FreeCol in English.
    // If the user has selected automatic language selection, do
    // nothing, since we have already set up the default locale.
    if (localeArg == null) {
        String clientLanguage = ClientOptions.getLanguageOption();
        Locale clientLocale;
        if (clientLanguage != null && !Messages.AUTOMATIC.equalsIgnoreCase(clientLanguage)
                && (clientLocale = Messages.getLocale(clientLanguage)) != locale) {
            locale = clientLocale;
            Messages.loadMessageBundle(locale);
            logger.info("Loaded messages for " + locale);
        }
    }

    // Now we have the user mods directory and the locale is now
    // stable, load the mods and their messages.
    Mods.loadMods();
    Messages.loadModMessageBundle(locale);

    // Report on where we are.
    if (userMsg != null)
        logger.info(Messages.message(userMsg));
    logger.info(getConfiguration().toString());

    // Ready to specialize into client or server.
    if (standAloneServer) {
        startServer();
    } else {
        startClient(userMsg);
    }
    startYourAddition();
}

From source file:MainGeneratePicasaIniFile.java

public static void main(String[] args) {
    try {/*www  . ja  v  a 2  s  .  com*/

        Calendar start = Calendar.getInstance();

        start.set(1899, 11, 30, 0, 0);

        PicasawebService myService = new PicasawebService("My Application");
        myService.setUserCredentials(args[0], args[1]);

        // Get a list of all entries
        URL metafeedUrl = new URL("http://picasaweb.google.com/data/feed/api/user/" + args[0] + "?kind=album");
        System.out.println("Getting Picasa Web Albums entries...\n");
        UserFeed resultFeed = myService.getFeed(metafeedUrl, UserFeed.class);

        // resultFeed.

        File root = new File(args[2]);
        File[] albuns = root.listFiles();

        int j = 0;
        List<GphotoEntry> entries = resultFeed.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            GphotoEntry entry = entries.get(i);
            String href = entry.getHtmlLink().getHref();

            String name = entry.getTitle().getPlainText();

            for (File album : albuns) {
                if (album.getName().equals(name) && !href.contains("02?")) {
                    File picasaini = new File(album, "Picasa.ini");

                    if (!picasaini.exists()) {
                        StringBuilder builder = new StringBuilder();

                        builder.append("\n");
                        builder.append("[Picasa]\n");
                        builder.append("name=");
                        builder.append(name);
                        builder.append("\n");
                        builder.append("location=");
                        Collection<Extension> extensions = entry.getExtensions();

                        for (Extension extension : extensions) {

                            if (extension instanceof GphotoLocation) {
                                GphotoLocation location = (GphotoLocation) extension;
                                if (location.getValue() != null) {
                                    builder.append(location.getValue());
                                }
                            }
                        }
                        builder.append("\n");
                        builder.append("category=Folders on Disk");
                        builder.append("\n");
                        builder.append("date=");
                        String source = name.substring(0, 10);

                        DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");

                        Date date = formater.parse(source);

                        Calendar end = Calendar.getInstance();

                        end.setTime(date);

                        builder.append(daysBetween(start, end));
                        builder.append(".000000");
                        builder.append("\n");
                        builder.append(args[0]);
                        builder.append("_lh=");
                        builder.append(entry.getGphotoId());
                        builder.append("\n");
                        builder.append("P2category=Folders on Disk");
                        builder.append("\n");

                        URL feedUrl = new URL("https://picasaweb.google.com/data/feed/api/user/" + args[0]
                                + "/albumid/" + entry.getGphotoId());

                        AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);

                        for (GphotoEntry photo : feed.getEntries()) {
                            builder.append("\n");
                            builder.append("[");
                            builder.append(photo.getTitle().getPlainText());
                            builder.append("]");
                            builder.append("\n");
                            long id = Long.parseLong(photo.getGphotoId());

                            builder.append("IIDLIST_");
                            builder.append(args[0]);
                            builder.append("_lh=");
                            builder.append(Long.toHexString(id));
                            builder.append("\n");
                        }

                        System.out.println(builder.toString());
                        IOUtils.write(builder.toString(), new FileOutputStream(picasaini));
                        j++;
                    }
                }

            }

        }
        System.out.println(j);
        System.out.println("\nTotal Entries: " + entries.size());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques.java

/**
 * @param args//from   w  ww.j a v  a  2 s.  c  o m
 * @throws ParseException 
 */
@SuppressWarnings({ "deprecation" })
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

    Options options = new Options();

    Option forceOption = new Option("f", "force", false,
            "force the computation of the relationship " + "even if files already exist");
    forceOption.setRequired(false);
    options.addOption(forceOption);

    Option g1Option = new Option("g1", "first-group", true, "set first group of datasets");
    g1Option.setRequired(true);
    g1Option.setArgName("FIRST GROUP");
    g1Option.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(g1Option);

    Option g2Option = new Option("g2", "second-group", true, "set second group of datasets");
    g2Option.setRequired(false);
    g2Option.setArgName("SECOND GROUP");
    g2Option.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(g2Option);

    Option machineOption = new Option("m", "machine", true, "machine identifier");
    machineOption.setRequired(true);
    machineOption.setArgName("MACHINE");
    machineOption.setArgs(1);
    options.addOption(machineOption);

    Option nodesOption = new Option("n", "nodes", true, "number of nodes");
    nodesOption.setRequired(true);
    nodesOption.setArgName("NODES");
    nodesOption.setArgs(1);
    options.addOption(nodesOption);

    Option s3Option = new Option("s3", "s3", false, "data on Amazon S3");
    s3Option.setRequired(false);
    options.addOption(s3Option);

    Option awsAccessKeyIdOption = new Option("aws_id", "aws-id", true,
            "aws access key id; " + "this is required if the execution is on aws");
    awsAccessKeyIdOption.setRequired(false);
    awsAccessKeyIdOption.setArgName("AWS-ACCESS-KEY-ID");
    awsAccessKeyIdOption.setArgs(1);
    options.addOption(awsAccessKeyIdOption);

    Option awsSecretAccessKeyOption = new Option("aws_key", "aws-id", true,
            "aws secrect access key; " + "this is required if the execution is on aws");
    awsSecretAccessKeyOption.setRequired(false);
    awsSecretAccessKeyOption.setArgName("AWS-SECRET-ACCESS-KEY");
    awsSecretAccessKeyOption.setArgs(1);
    options.addOption(awsSecretAccessKeyOption);

    Option bucketOption = new Option("b", "s3-bucket", true,
            "bucket on s3; " + "this is required if the execution is on aws");
    bucketOption.setRequired(false);
    bucketOption.setArgName("S3-BUCKET");
    bucketOption.setArgs(1);
    options.addOption(bucketOption);

    Option helpOption = new Option("h", "help", false, "display this message");
    helpOption.setRequired(false);
    options.addOption(helpOption);

    HelpFormatter formatter = new HelpFormatter();
    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        formatter.printHelp(
                "hadoop jar data-polygamy.jar "
                        + "edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques",
                options, true);
        System.exit(0);
    }

    if (cmd.hasOption("h")) {
        formatter.printHelp(
                "hadoop jar data-polygamy.jar "
                        + "edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques",
                options, true);
        System.exit(0);
    }

    boolean s3 = cmd.hasOption("s3");
    String s3bucket = "";
    String awsAccessKeyId = "";
    String awsSecretAccessKey = "";

    if (s3) {
        if ((!cmd.hasOption("aws_id")) || (!cmd.hasOption("aws_key")) || (!cmd.hasOption("b"))) {
            System.out.println(
                    "Arguments 'aws_id', 'aws_key', and 'b'" + " are mandatory if execution is on AWS.");
            formatter.printHelp(
                    "hadoop jar data-polygamy.jar "
                            + "edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques",
                    options, true);
            System.exit(0);
        }
        s3bucket = cmd.getOptionValue("b");
        awsAccessKeyId = cmd.getOptionValue("aws_id");
        awsSecretAccessKey = cmd.getOptionValue("aws_key");
    }

    boolean snappyCompression = false;
    boolean bzip2Compression = false;
    String machine = cmd.getOptionValue("m");
    int nbNodes = Integer.parseInt(cmd.getOptionValue("n"));

    Configuration s3conf = new Configuration();
    if (s3) {
        s3conf.set("fs.s3.awsAccessKeyId", awsAccessKeyId);
        s3conf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey);
        s3conf.set("bucket", s3bucket);
    }

    Path path = null;
    FileSystem fs = FileSystem.get(new Configuration());

    ArrayList<String> shortDataset = new ArrayList<String>();
    ArrayList<String> firstGroup = new ArrayList<String>();
    ArrayList<String> secondGroup = new ArrayList<String>();
    HashMap<String, String> datasetAgg = new HashMap<String, String>();

    boolean removeExistingFiles = cmd.hasOption("f");

    String[] firstGroupCmd = cmd.getOptionValues("g1");
    String[] secondGroupCmd = cmd.hasOption("g2") ? cmd.getOptionValues("g2") : new String[0];
    addDatasets(firstGroupCmd, firstGroup, shortDataset, datasetAgg, path, fs, s3conf, s3, s3bucket);
    addDatasets(secondGroupCmd, secondGroup, shortDataset, datasetAgg, path, fs, s3conf, s3, s3bucket);

    if (shortDataset.size() == 0) {
        System.out.println("No datasets to process.");
        System.exit(0);
    }

    if (firstGroup.isEmpty()) {
        System.out.println("First group of datasets (G1) is empty. " + "Doing G1 = G2.");
        firstGroup.addAll(secondGroup);
    }

    if (secondGroup.isEmpty()) {
        System.out.println("Second group of datasets (G2) is empty. " + "Doing G2 = G1.");
        secondGroup.addAll(firstGroup);
    }

    // getting dataset ids

    String datasetNames = "";
    String datasetIds = "";
    HashMap<String, String> datasetId = new HashMap<String, String>();
    Iterator<String> it = shortDataset.iterator();
    while (it.hasNext()) {
        datasetId.put(it.next(), null);
    }

    if (s3) {
        path = new Path(s3bucket + FrameworkUtils.datasetsIndexDir);
        fs = FileSystem.get(path.toUri(), s3conf);
    } else {
        path = new Path(fs.getHomeDirectory() + "/" + FrameworkUtils.datasetsIndexDir);
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(path)));
    String line = br.readLine();
    while (line != null) {
        String[] dt = line.split("\t");
        if (datasetId.containsKey(dt[0])) {
            datasetId.put(dt[0], dt[1]);
            datasetNames += dt[0] + ",";
            datasetIds += dt[1] + ",";
        }
        line = br.readLine();
    }
    br.close();
    if (s3)
        fs.close();

    datasetNames = datasetNames.substring(0, datasetNames.length() - 1);
    datasetIds = datasetIds.substring(0, datasetIds.length() - 1);
    it = shortDataset.iterator();
    while (it.hasNext()) {
        String dataset = it.next();
        if (datasetId.get(dataset) == null) {
            System.out.println("No dataset id for " + dataset);
            System.exit(0);
        }
    }

    String firstGroupStr = "";
    String secondGroupStr = "";
    for (String dataset : firstGroup) {
        firstGroupStr += datasetId.get(dataset) + ",";
    }
    for (String dataset : secondGroup) {
        secondGroupStr += datasetId.get(dataset) + ",";
    }
    firstGroupStr = firstGroupStr.substring(0, firstGroupStr.length() - 1);
    secondGroupStr = secondGroupStr.substring(0, secondGroupStr.length() - 1);

    FrameworkUtils.createDir(s3bucket + FrameworkUtils.correlationTechniquesDir, s3conf, s3);

    String dataAttributesInputDirs = "";
    String noRelationship = "";

    HashSet<String> dirs = new HashSet<String>();

    String dataset1;
    String dataset2;
    String datasetId1;
    String datasetId2;
    for (int i = 0; i < firstGroup.size(); i++) {
        for (int j = 0; j < secondGroup.size(); j++) {

            if (Integer.parseInt(datasetId.get(firstGroup.get(i))) < Integer
                    .parseInt(datasetId.get(secondGroup.get(j)))) {
                dataset1 = firstGroup.get(i);
                dataset2 = secondGroup.get(j);
            } else {
                dataset1 = secondGroup.get(j);
                dataset2 = firstGroup.get(i);
            }

            datasetId1 = datasetId.get(dataset1);
            datasetId2 = datasetId.get(dataset2);

            if (dataset1.equals(dataset2))
                continue;
            String correlationOutputFileName = s3bucket + FrameworkUtils.correlationTechniquesDir + "/"
                    + dataset1 + "-" + dataset2 + "/";

            if (removeExistingFiles) {
                FrameworkUtils.removeFile(correlationOutputFileName, s3conf, s3);
            }
            if (!FrameworkUtils.fileExists(correlationOutputFileName, s3conf, s3)) {
                dirs.add(s3bucket + FrameworkUtils.aggregatesDir + "/" + dataset1);
                dirs.add(s3bucket + FrameworkUtils.aggregatesDir + "/" + dataset2);
            } else {
                noRelationship += datasetId1 + "-" + datasetId2 + ",";
            }
        }
    }

    if (dirs.isEmpty()) {
        System.out.println("All the relationships were already computed.");
        System.out.println("Use -f in the beginning of the command line to force the computation.");
        System.exit(0);
    }

    for (String dir : dirs) {
        dataAttributesInputDirs += dir + ",";
    }

    Configuration conf = new Configuration();
    Machine machineConf = new Machine(machine, nbNodes);

    String jobName = "correlation";
    String correlationOutputDir = s3bucket + FrameworkUtils.correlationTechniquesDir + "/tmp/";

    FrameworkUtils.removeFile(correlationOutputDir, s3conf, s3);

    for (int i = 0; i < shortDataset.size(); i++) {
        conf.set("dataset-" + datasetId.get(shortDataset.get(i)) + "-agg", datasetAgg.get(shortDataset.get(i)));
    }
    for (int i = 0; i < shortDataset.size(); i++) {
        conf.set("dataset-" + datasetId.get(shortDataset.get(i)) + "-agg-size",
                Integer.toString(datasetAgg.get(shortDataset.get(i)).split(",").length));
    }
    conf.set("dataset-keys", datasetIds);
    conf.set("dataset-names", datasetNames);
    conf.set("first-group", firstGroupStr);
    conf.set("second-group", secondGroupStr);
    conf.set("main-dataset-id", datasetId.get(shortDataset.get(0)));
    if (noRelationship.length() > 0) {
        conf.set("no-relationship", noRelationship.substring(0, noRelationship.length() - 1));
    }

    conf.set("mapreduce.tasktracker.map.tasks.maximum", String.valueOf(machineConf.getMaximumTasks()));
    conf.set("mapreduce.tasktracker.reduce.tasks.maximum", String.valueOf(machineConf.getMaximumTasks()));
    conf.set("mapreduce.jobtracker.maxtasks.perjob", "-1");
    conf.set("mapreduce.reduce.shuffle.parallelcopies", "20");
    conf.set("mapreduce.input.fileinputformat.split.minsize", "0");
    conf.set("mapreduce.task.io.sort.mb", "200");
    conf.set("mapreduce.task.io.sort.factor", "100");
    conf.set("mapreduce.task.timeout", "2400000");

    if (s3) {
        machineConf.setMachineConfiguration(conf);
        conf.set("fs.s3.awsAccessKeyId", awsAccessKeyId);
        conf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey);
        conf.set("bucket", s3bucket);
    }

    if (snappyCompression) {
        conf.set("mapreduce.map.output.compress", "true");
        conf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec");
        //conf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec");
    }
    if (bzip2Compression) {
        conf.set("mapreduce.map.output.compress", "true");
        conf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec");
        //conf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec");
    }

    Job job = new Job(conf);
    job.setJobName(jobName);

    job.setMapOutputKeyClass(PairAttributeWritable.class);
    job.setMapOutputValueClass(SpatioTemporalValueWritable.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    job.setMapperClass(CorrelationTechniquesMapper.class);
    job.setReducerClass(CorrelationTechniquesReducer.class);
    job.setNumReduceTasks(machineConf.getNumberReduces());

    job.setInputFormatClass(SequenceFileInputFormat.class);
    LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class);

    FileInputFormat.setInputDirRecursive(job, true);
    FileInputFormat.setInputPaths(job,
            dataAttributesInputDirs.substring(0, dataAttributesInputDirs.length() - 1));
    FileOutputFormat.setOutputPath(job, new Path(correlationOutputDir));

    job.setJarByClass(CorrelationTechniques.class);

    long start = System.currentTimeMillis();
    job.submit();
    job.waitForCompletion(true);
    System.out.println(jobName + "\t" + (System.currentTimeMillis() - start));

    // moving files to right place
    for (int i = 0; i < firstGroup.size(); i++) {
        for (int j = 0; j < secondGroup.size(); j++) {

            if (Integer.parseInt(datasetId.get(firstGroup.get(i))) < Integer
                    .parseInt(datasetId.get(secondGroup.get(j)))) {
                dataset1 = firstGroup.get(i);
                dataset2 = secondGroup.get(j);
            } else {
                dataset1 = secondGroup.get(j);
                dataset2 = firstGroup.get(i);
            }

            if (dataset1.equals(dataset2))
                continue;

            String from = s3bucket + FrameworkUtils.correlationTechniquesDir + "/tmp/" + dataset1 + "-"
                    + dataset2 + "/";
            String to = s3bucket + FrameworkUtils.correlationTechniquesDir + "/" + dataset1 + "-" + dataset2
                    + "/";
            FrameworkUtils.renameFile(from, to, s3conf, s3);
        }
    }
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Run the Uploader as a stand-alone application.
 *
 * @param args/*from  w ww .j  a  v  a2s.  c o m*/
 * @throws Exception
 */
public static void main(String args[]) throws Exception {
    JFrame ownerFrame = new JFrame("JetS3t Uploader");
    ownerFrame.addWindowListener(new WindowListener() {
        public void windowOpened(WindowEvent e) {
        }

        public void windowClosing(WindowEvent e) {
            e.getWindow().dispose();
        }

        public void windowClosed(WindowEvent e) {
        }

        public void windowIconified(WindowEvent e) {
        }

        public void windowDeiconified(WindowEvent e) {
        }

        public void windowActivated(WindowEvent e) {
        }

        public void windowDeactivated(WindowEvent e) {
        }
    });

    // Read arguments as properties of the form: <propertyName>'='<propertyValue>
    Properties argumentProperties = new Properties();
    if (args.length > 0) {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            int delimIndex = arg.indexOf("=");
            if (delimIndex >= 0) {
                String name = arg.substring(0, delimIndex);
                String value = arg.substring(delimIndex + 1);
                argumentProperties.put(name, value);
            } else {
                System.out.println("Ignoring property argument with incorrect format: " + arg);
            }
        }
    }

    new Uploader(ownerFrame, argumentProperties);
}