Example usage for java.lang String length

List of usage examples for java.lang String length

Introduction

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

Prototype

public int length() 

Source Link

Document

Returns the length of this string.

Usage

From source file:markov.java

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

    // hack: eclipse don't support IO redirection worth a shit
    // try {
    // System.setIn(new FileInputStream("./json"));
    // } catch (FileNotFoundException e1) {
    // // TODO Auto-generated catch block
    // e1.printStackTrace();
    // }

    boolean graphMode = false;
    boolean jsonMode = false;
    boolean jsonRecoverMode = false;
    boolean endNode = false;

    int count = -1;

    long n = 0;
    long sumOfSqr = 0;
    long sum = 0;

    for (String s : args) {

        if (!s.matches("^-[vegjJh]*(c[0-9]*)?$")) {
            System.out.println("invalid argument");
            return;
        }

        if (s.matches("^-.*h.*")) {
            System.out.println(HELP);
            return;
        }
        if (s.matches("^-.*v.*")) {
            verbose = true;
            log("verbose mode");
        }
        if (s.matches("^-.*g.*")) {
            graphMode = true;
            log("graph mode");
        }
        if (s.matches("^-.*j.*")) {
            jsonMode = true;
            log("json mode");
        }
        if (s.matches("^-.*J.*")) {
            jsonRecoverMode = true;
            log("json recover mode");
        }
        if (s.matches("^-.*e.*")) {
            endNode = true;
            log("include end node");
        }
        if (s.matches("^-.*c[0-9]*$")) {
            log("counted output mode");
            count = Integer.parseInt(s.replaceAll("^-.*c", ""));
        }

        boolean error = (graphMode == true && jsonMode == true);
        if (!error) {
            error = (count > -1) && (graphMode == true || jsonMode == true);
        }

        if (error) {
            System.err.println("[error] switches j, g and, c are mutualy exclusive.");
            return;
        }

    }

    StateTransitionDiagram<Character> std;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    try {
        if (!jsonRecoverMode) {
            Trainer<Character> trainer = new Trainer<Character>();
            String s = br.readLine();
            while (s != null) {
                trainer.train(string2List(s));
                n++;
                sumOfSqr += s.length() * s.length();
                sum += s.length();
                s = br.readLine();
            }
            if (n == 0) {
                System.err
                        .println("Invalid corpus: At least one sample is required, two to make it interesting");
                return;
            }
            std = trainer.getTransitionDiagram();
        } else {
            std = new StateTransitionDiagram<Character>();
            GsonStub gstub = new Gson().fromJson(br, GsonStub.class);
            n = gstub.meta.n;
            sum = gstub.meta.sum;
            sumOfSqr = gstub.meta.sumOfSqr;

            for (Entry<String, StateStub> entry : gstub.states.entrySet()) {
                State<Character> state;
                if (entry.getKey().equals("null")) {
                    state = std.getGuard();
                } else {
                    state = std.getState(Character.valueOf(entry.getKey().charAt(0)));
                }
                for (Entry<String, Integer> transitions : entry.getValue().transitions.entrySet()) {
                    State<Character> tranny;
                    if (transitions.getKey().equals("null")) {
                        tranny = std.getGuard();
                    } else {
                        tranny = std.getState(Character.valueOf(transitions.getKey().charAt(0)));
                    }

                    state.addTransition(tranny.getValue(), transitions.getValue());
                }
            }
        }
        if (graphMode) {
            if (endNode) {
                System.out.println(std.toString());
            } else {
                System.out.println(std.removeEndGuards().toString());
            }
            return;
        }
        if (jsonMode) {
            Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

            String partialJson;
            if (endNode) {
                partialJson = gson.toJson(std);
            } else {
                partialJson = gson.toJson(std.removeEndGuards());
            }
            GsonStub gstub = new Gson().fromJson(partialJson, GsonStub.class);
            gstub.meta = new Meta();
            gstub.meta.n = n;
            gstub.meta.sum = sum;
            gstub.meta.sumOfSqr = sumOfSqr;

            System.out.println(gson.toJson(gstub));
            return;
        }

        Generator<Character> generator;
        if (endNode) {
            generator = new EndTagGenerator<Character>(std);
        } else {
            double sd = ((double) sumOfSqr - (double) (sum * sum) / (double) n) / (double) (n - 1);
            double mean = (double) sum / (double) n;
            log(String.format("mean: %.4f sd: %.4f", mean, sd));
            NormalDistributionImpl dist = new NormalDistributionImpl(mean, sd);
            generator = new NormalizedGenerator<Character>(std.removeEndGuards(), dist);
        }
        if (count >= 0) {
            for (int c = 0; c < count; c++) {
                output(generator);
            }
        } else {
            while (true) {
                output(generator);
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:implementation.java

public static void main(String[] args) throws IOException {
    // Network Variables
    KUSOCKET ClientSocket = new KUSOCKET();
    ENDPOINT ClientAddress = new ENDPOINT("0.0.0.0", 0);
    ENDPOINT BroadcastAddress = new ENDPOINT("255.255.255.255", TokenAccess.SERVER_PORT_NUMBER);
    ENDPOINT AnyAddress = new ENDPOINT("0.0.0.0", 0);

    ENDPOINT ServerAddress = new ENDPOINT();
    MESSAGE OutgoingMessage = new MESSAGE();
    MESSAGE IncomingMessage = new MESSAGE();

    // Output variables         
    int CommentLength = TokenAccess.COMMENT_LENGTH;
    String Comment = new String();

    // Protocol variables
    Timer firstnode = new Timer();
    Timer tokentimer = new Timer();
    Timer tokenlost = new Timer();
    Timer exit = new Timer();
    int DialogueNumber = 0;
    int numRetries = 0;
    Integer addressIP[] = new Integer[2];
    int trigger = 0;
    String lanAddress = "192.168.1.67";
    // Create socket and await connection ///////////////////////////////////////

    // --------------------------------------------------------------------------
    // FINITE STATE MACHINE
    // --------------------------------------------------------------------------

    System.err.println("FSM Started ===================" + '\n');

    // FSM variables
    TokenAccess.STATES state = TokenAccess.STATES.STATE_INITIAL; // Initial STATE
    TokenAccess.STATES lastState = state; // Last STATE
    boolean bContinueEventWait = false;
    boolean bContinueStateLoop = true;
    String last = null;//ww w  . j ava2  s.c o m
    ClientSocket.CreateUDPSocket(ClientAddress);
    while (bContinueStateLoop) {

        switch (state) {
        case STATE_INITIAL:

            firstnode.Start(TokenAccess.firstnode);
            state = TokenAccess.STATES.STATE_STARTED;
            bContinueEventWait = false; // Stop Events loop
            break;

        case STATE_STARTED:

            ClientSocket.MakeConnection(AnyAddress);

            if (firstnode.isExpired()) {
                tokentimer.Start(TokenAccess.tokentimer);

                System.out.println("implementation.main()");
                // adding  local host ip to array
                String t = InetAddress.getLocalHost().getHostAddress();
                String[] split = t.split("\\.");
                addressIP[0] = Integer.parseInt(split[3]);
                System.out.println(split[3]);
                state = TokenAccess.STATES.STATE_TOKENED;
                bContinueEventWait = false;// Stop Events loop

            }
            boolean isMessageQueued = false;

            isMessageQueued = ClientSocket.RetrieveQueuedMessage(TokenAccess.READ_INTERVAL, IncomingMessage,
                    ServerAddress);

            if (isMessageQueued && (IncomingMessage.Type == TokenAccess.PDU_CONNECT)) {
                System.out.println("ring exists");
                //pdu_connect used instead of ring exisits 
                state = TokenAccess.STATES.STATE_tokenLess;
                bContinueEventWait = false;

            }

        case STATE_tokenLess:
            ClientSocket.MakeConnection(AnyAddress);
            while (state == TokenAccess.STATES.STATE_tokenLess) {
                // Instructs the socket to accept

                // building ip address message
                OutgoingMessage.BuildMessage(++DialogueNumber, TokenAccess.PDU_CONNECT,
                        InetAddress.getLocalHost().getHostAddress(),
                        InetAddress.getLocalHost().getHostAddress().length());
                //broadcasting ip address
                ClientSocket.DeliverMessage(OutgoingMessage, BroadcastAddress);
                //     System.out.println("broadcasting address");

                isMessageQueued = ClientSocket.RetrieveQueuedMessage(TokenAccess.READ_INTERVAL, IncomingMessage,
                        ServerAddress);

                //will trigger if used on a 192 network i didnt know how to use regex for any number and a dot
                if (isMessageQueued == true && (IncomingMessage.Type == TokenAccess.PDU_CLOSE)) {
                    System.out.println("pdu close");
                    String ipaddress = IncomingMessage.Buffer;

                    for (int n : addressIP) {
                        if (addressIP[n] == Integer.parseInt(ipaddress)) {
                            String a;
                            a = Integer.toString(addressIP[n]);
                            OutgoingMessage.BuildMessage(++DialogueNumber, TokenAccess.PDU_ACK,
                                    InetAddress.getLocalHost().getHostAddress(),
                                    InetAddress.getLocalHost().getHostAddress().length());
                            ENDPOINT exitAddress = new ENDPOINT(a, TokenAccess.SERVER_PORT_NUMBER);

                            ClientSocket.DeliverMessage(OutgoingMessage, exitAddress);
                            addressIP = ArrayUtils.removeElement(addressIP, n);
                        }

                    }
                }

                if (last != null && tokenlost.bRunning == false) {
                    tokenlost.Start(TokenAccess.tokenlost);
                    last = null;
                    System.out.println("token lost timer started");
                }

                if (isMessageQueued == true && (IncomingMessage.Type == TokenAccess.CMD_CONNECT)) {
                    System.out.println("token lost timer stopped");
                    tokenlost.Stop();
                }

                if (tokenlost.isExpired()) {

                    System.out.println("token lost");

                    for (int n = 0; n < addressIP.length; n++) {
                        String ipaddress = InetAddress.getLocalHost().toString();
                        int lastdot = ipaddress.lastIndexOf(".") + 1;
                        ipaddress = ipaddress.substring(lastdot, ipaddress.length());
                        System.out.println(n);
                        if (addressIP[n] == null) {

                        } else {
                            if (addressIP[n] == Integer.parseInt(ipaddress)) {

                                String a;
                                a = Integer.toString(addressIP[n]);
                                System.out.println("variable a " + a);
                                OutgoingMessage.BuildMessage(++DialogueNumber, TokenAccess.PDU_ACK,
                                        InetAddress.getLocalHost().getHostAddress(),
                                        InetAddress.getLocalHost().getHostAddress().length());
                                ENDPOINT exitAddress = new ENDPOINT(lanAddress, TokenAccess.SERVER_PORT_NUMBER);

                                ClientSocket.DeliverMessage(OutgoingMessage, exitAddress);

                                OutgoingMessage.BuildMessage(++DialogueNumber, TokenAccess.PDU_TOKEN,
                                        InetAddress.getLocalHost().getHostAddress(),
                                        InetAddress.getLocalHost().getHostAddress().length());
                                String b = Integer.toString(addressIP[n]);
                                b = lanAddress;
                                System.out.println(b);

                                ENDPOINT exitAddresss = new ENDPOINT(b, TokenAccess.SERVER_PORT_NUMBER);
                                ClientSocket.DeliverMessage(OutgoingMessage, exitAddresss);

                            }
                        }
                    }

                }

                if (exit.isExpired()) {
                    OutgoingMessage.BuildMessage(++DialogueNumber, TokenAccess.PDU_CLOSE,
                            InetAddress.getLocalHost().getHostAddress(),
                            InetAddress.getLocalHost().getHostAddress().length());
                    exit.Start(30);
                }

                if (isMessageQueued && (IncomingMessage.Type == TokenAccess.PDU_TOKEN)) {
                    tokenlost.Stop();
                    System.out.println(IncomingMessage.Type);
                    state = TokenAccess.STATES.STATE_TOKENED;
                    tokentimer.Start(TokenAccess.tokentimer);
                    break;
                }

            }

        case STATE_TOKENED:
            while (state == TokenAccess.STATES.STATE_TOKENED) {

                //send data
                OutgoingMessage.BuildMessage(0, 0, "ALIVE", CommentLength);
                ClientSocket.DeliverMessage(OutgoingMessage, BroadcastAddress);
                tokenlost.Stop();
                while (trigger == 0) {
                    System.out.println("TOKENED");
                    trigger++;
                }

                if (tokentimer.isExpired()) {
                    trigger = 0;
                    System.out.println("token expired");
                    String ipaddress = InetAddress.getLocalHost().toString();
                    //  System.out.println( "System name : "+ipaddress);

                    for (int n = 0; n < addressIP.length; n++) {
                        // System.out.println(n);
                        int lastdot = ipaddress.lastIndexOf(".") + 1;
                        ipaddress = ipaddress.substring(lastdot, ipaddress.length());
                        // System.out.println("IP address: "+ipaddress);
                        int address1 = Integer.parseInt(ipaddress);

                        System.out.println("made it to line 214");
                        System.out.println(n);
                        System.out.println(addressIP[0]);

                        if (addressIP[n] == address1) {
                            String a;
                            a = Integer.toString(addressIP[n]);
                            System.out.println("variable a = " + a);

                            String ip = InetAddress.getLocalHost().getHostAddress();
                            System.out.println("line 226");
                            System.out.println(ip);

                            OutgoingMessage.BuildMessage(++DialogueNumber, TokenAccess.PDU_TOKEN,
                                    InetAddress.getLocalHost().getHostAddress(),
                                    InetAddress.getLocalHost().getHostAddress().length());
                            String b;

                            System.out.println("line 222");
                            if (n + 1 >= addressIP.length) {
                                b = (ip);
                                //   System.out.println(b);
                            } else {
                                b = ip;

                            }

                            System.out.println(b);

                            //b = InetAddress.getLocalHost().toString().substring(0, lastdot); 
                            // int slash =   b.indexOf("/");
                            System.out.println(b);
                            ENDPOINT exitAddresss = new ENDPOINT(b, TokenAccess.SERVER_PORT_NUMBER);
                            ClientSocket.DeliverMessage(OutgoingMessage, exitAddresss);
                            System.out.println("exiting tokened state");
                            state = TokenAccess.STATES.STATE_tokenLess;
                            last = "1";
                        }
                        break;
                    }
                }
            }

        case STATE_EXIT:
            while (state == TokenAccess.STATES.STATE_EXIT) {
                System.exit(0);

            }

        }

    }

}

From source file:com.kactech.otj.examples.App_otj.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    String command = null;//  ww w .  j  ava2  s  . c o m
    String hisacct = null;
    String hisacctName = null;
    String hisacctAsset = null;
    String asset = null;
    String assetName = null;
    List<String> argList = null;
    boolean newAccount = false;
    File dir = null;
    ConnectionInfo connection = null;
    List<ScriptFilter> filters = null;

    CommandLineParser parser = new GnuParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println("Command-line parsing error: " + e.getMessage());
        help();
        System.exit(-1);
    }
    if (cmd.hasOption('h')) {
        help();
        System.exit(0);
    }
    @SuppressWarnings("unchecked")
    List<String> list = cmd.getArgList();
    if (list.size() > 1) {
        System.err.println("only one command is supported, you've typed " + list);
        help();
        System.exit(-1);
    }
    if (list.size() > 0)
        command = list.get(0).trim();

    List<SampleAccount> accounts = ExamplesUtils.getSampleAccounts();

    if (cmd.hasOption('s')) {
        String v = cmd.getOptionValue('s').trim();
        connection = ExamplesUtils.findServer(v);
        if (connection == null) {
            System.err.println("unknown server: " + v);
            System.exit(-1);
        }
    } else {
        connection = ExamplesUtils.findServer(DEF_SERVER_NAME);
        if (connection == null) {
            System.err.println("default server not found server: " + DEF_SERVER_NAME);
            System.exit(-1);
        }
    }

    if (cmd.hasOption('t')) {
        String v = cmd.getOptionValue('t');
        for (SampleAccount ac : accounts)
            if (ac.accountName.startsWith(v)) {
                hisacct = ac.accountID;
                hisacctName = ac.accountName;
                hisacctAsset = ac.assetID;
                break;
            }
        if (hisacct == null)
            if (mayBeValid(v))
                hisacct = v;
            else {
                System.err.println("invalid hisacct: " + v);
                System.exit(-1);
            }
    }
    if (cmd.hasOption('p')) {
        String v = cmd.getOptionValue('p');
        for (SampleAccount ac : accounts)
            if (ac.assetName.startsWith(v)) {
                asset = ac.assetID;
                assetName = ac.assetName;
                break;
            }
        if (asset == null)
            if (mayBeValid(v))
                asset = v;
            else {
                System.err.println("invalid asset: " + v);
                System.exit(-1);
            }
    }

    if (cmd.hasOption('a')) {
        String v = cmd.getOptionValue('a');
        argList = new ArrayList<String>();
        boolean q = false;
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < v.length(); i++) {
            char c = v.charAt(i);
            if (c == '"') {
                if (q) {
                    argList.add(b.toString());
                    b = null;
                    q = false;
                    continue;
                }
                if (b != null)
                    argList.add(b.toString());
                b = new StringBuilder();
                q = true;
                continue;
            }
            if (c == ' ' || c == '\t') {
                if (q) {
                    b.append(c);
                    continue;
                }
                if (b != null)
                    argList.add(b.toString());
                b = null;
                continue;
            }
            if (b == null)
                b = new StringBuilder();
            b.append(c);
        }
        if (b != null)
            argList.add(b.toString());
        if (q) {
            System.err.println("unclosed quote in args: " + v);
            System.exit(-1);
        }
    }

    dir = new File(cmd.hasOption('d') ? cmd.getOptionValue('d') : DEF_CLIENT_DIR);

    if (cmd.hasOption('x'))
        del(dir);

    newAccount = cmd.hasOption('n');

    if (cmd.hasOption('f')) {
        filters = new ArrayList<ScriptFilter>();
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        Compilable compilingEngine = (Compilable) engine;
        for (String fn : cmd.getOptionValue('f').split(",")) {
            fn = fn.trim();
            if (fn.isEmpty())
                continue;
            fn += ".js";
            Reader r = null;
            try {
                r = new InputStreamReader(new FileInputStream(new File("filters", fn)), Utils.UTF8);
            } catch (Exception e) {
                try {
                    r = new InputStreamReader(
                            App_otj.class.getResourceAsStream("/com/kactech/otj/examples/filters/" + fn));
                } catch (Exception e2) {
                }
            }
            if (r == null) {
                System.err.println("filter not found: " + fn);
                System.exit(-1);
            } else
                try {
                    CompiledScript compiled = compilingEngine.compile(r);
                    ScriptFilter sf = new ScriptFilter(compiled);
                    filters.add(sf);
                } catch (Exception ex) {
                    System.err.println("error while loading " + fn + ": " + ex);
                    System.exit(-1);
                }
        }
    }

    System.out.println("server: " + connection.getEndpoint() + " " + connection.getID());
    System.out.println("command: '" + command + "'");
    System.out.println("args: " + argList);
    System.out.println("hisacct: " + hisacct);
    System.out.println("hisacctName: " + hisacctName);
    System.out.println("hisacctAsset: " + hisacctAsset);
    System.out.println("asset: " + asset);
    System.out.println("assetName: " + assetName);

    if (asset != null && hisacctAsset != null && !asset.equals(hisacctAsset)) {
        System.err.println("asset differs from hisacctAsset");
        System.exit(-1);
    }

    EClient client = new EClient(dir, connection);
    client.setAssetType(asset != null ? asset : hisacctAsset);
    client.setCreateNewAccount(newAccount);
    if (filters != null)
        client.setFilters(filters);

    try {
        Utils.init();
        Client.DEBUG_JSON = true;
        client.init();

        if ("balance".equals(command))
            System.out.println("Balance: " + client.getAccount().getBalance().getAmount());
        else if ("acceptall".equals(command))
            client.processInbox();
        else if ("transfer".equals(command)) {
            if (hisacct == null)
                System.err.println("please specify --hisacct");
            else {
                int idx = argList != null ? argList.indexOf("amount") : -1;
                if (idx < 0)
                    System.err.println("please specify amount");
                else if (idx == argList.size())
                    System.err.println("amount argument needs value");
                else {
                    Long amount = -1l;
                    try {
                        amount = new Long(argList.get(idx + 1));
                    } catch (Exception e) {

                    }
                    if (amount <= 0)
                        System.err.println("invalid amount");
                    else {
                        client.notarizeTransaction(hisacct, amount);
                    }
                }
            }
        } else if ("reload".equals(command))
            client.reloadState();
        else if ("procnym".equals(command))
            client.processNymbox();
    } finally {
        client.saveState();
        client.close();
    }
}

From source file:com.hp.test.framework.Reporting.Utlis.java

public static void main(String ar[]) throws IOException {

    ArrayList<String> runs_list = new ArrayList<String>();
    String basepath = replacelogs();
    String path = basepath + "ATU Reports\\Results";
    File directory = new File(path);
    File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    String htmlReport = basepath + "HTML_Design_Files\\CSS\\HtmlReport.html";
    for (File dir : subdirs) {

        runs_list.add(dir.getName());//from   w w  w  . j a  va2 s.co m
    }
    String Reports_path = basepath + "ATU Reports\\";
    int LatestRun = Utlis.getLastRun(Reports_path);
    String Last_run_path = Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "\\";

    HtmlParse.replaceMainTable(false, new File(Last_run_path + "/CurrentRun.html"));
    HtmlParse.replaceCountsinJSFile(new File("HTML_Design_Files/JS/3dChart.js"), Last_run_path);
    UpdateTestCaseDesciption.basepath = Last_run_path;
    UpdateTestCaseDesciption.getTestCaseHtmlPath(Last_run_path + "/CurrentRun.html");
    UpdateTestCaseDesciption.replaceDetailsTable(Last_run_path + "/CurrentRun.html");
    //   GenerateFailReport.genarateFailureReport(new File(htmlReport), Reports_path + "Results\\Run_" + String.valueOf(LatestRun));
    genarateFailureReport(new File(htmlReport), Reports_path + "Results\\");
    Map<String, List<String>> runCounts = GetCountsrunsWise(runs_list, path);

    int success = replaceCounts(runCounts, path);

    if (success == 0) {
        File SourceFile = new File(path + "\\lineChart_temp.js");
        File RenameFile = new File(path + "\\lineChart.js");

        renameOriginalFile(SourceFile, RenameFile);

        File SourceFile1 = new File(path + "\\barChart_temp.js");
        File RenameFile1 = new File(path + "\\barChart.js");

        renameOriginalFile(SourceFile1, RenameFile1);

        Utlis.getpaths(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun));
        try {
            Utlis.replaceMainTable(false, new File(Reports_path + "index.html"));
            Utlis.replaceMainTable(true, new File(Reports_path + "results\\" + "ConsolidatedPage.html"));
            Utlis.replaceMainTable(true,
                    new File(Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));

            fileList.add(
                    new File(Reports_path + "\\Results\\Run_" + String.valueOf(LatestRun) + "CurrentRun.html"));
            for (File f : fileList) {
                Utlis.replaceMainTable(true, f);
            }

        } catch (Exception ex) {
            log.info("Error in updating Report format" + ex.getMessage());
        }

        Last_run_path = Reports_path + "Results\\Run_" + String.valueOf(LatestRun) + "\\";

        //   HtmlParse.replaceMainTable(false, new File(Last_run_path + "/CurrentRun.html"));
        //   HtmlParse.replaceCountsinJSFile(new File("../HTML_Design_Files/JS/3dChart.js"), Last_run_path);
        ArrayList<String> to_list = new ArrayList<String>();
        ReportingProperties reportingproperties = new ReportingProperties();
        String temp_eml = reportingproperties.getProperty("TOLIST");
        String JenkinsURL = reportingproperties.getProperty("JENKINSURL");

        String ScreenShotsDir = reportingproperties.getProperty("ScreenShotsDirectory");
        Boolean cleanScreenshotsDir = Boolean.valueOf(reportingproperties.getProperty("CleanPreScreenShots"));
        Boolean generatescreenshots = Boolean.valueOf(reportingproperties.getProperty("GenerateScreenShots"));
        String HtmlreportFilePrefix = reportingproperties.getProperty("HtmlreportFilePrefix");

        if (cleanScreenshotsDir) {
            if (!CleanFilesinDir(ScreenShotsDir)) {
                log.error("Not able to Clean the Previous Run Details in the paht" + ScreenShotsDir);
            } else {
                log.info("Cleaning Previous Run Details in the paht" + ScreenShotsDir + "Sucess");
            }
        }
        List<String> scr_fileList;
        List<String> html_fileList;
        if (generatescreenshots) {
            scr_fileList = GetFileListinDir(ScreenShotsDir, "png");

            int len = scr_fileList.size();
            len = len + 1;

            screenshot.generatescreenshot(Last_run_path + "CurrentRun.html",
                    ScreenShotsDir + "screenshot_" + len + ".png");
            File source = new File(Reports_path + "Results\\HtmlReport.html");
            File dest = new File(ScreenShotsDir + HtmlreportFilePrefix + "_HtmlReport.html");
            //  Files.copy(f.toPath(), (new File((ScreenShotsDir+HtmlreportFilePrefix+"_HtmlReport.html").toPath(),StandardCopyOption.REPLACE_EXISTING);
            FileUtils.copyFile(source, dest);
            scr_fileList.clear();

        }

        scr_fileList = GetFileListinDir(ScreenShotsDir, "png");
        html_fileList = GetFileListinDir(ScreenShotsDir, "html");

        if (temp_eml.length() > 1) {
            String[] to_list_temp = temp_eml.split(",");

            if (to_list_temp.length > 0) {
                for (String to_list_temp1 : to_list_temp) {
                    to_list.add(to_list_temp1);
                }
            }
            if (to_list.size() > 0) {
                screenshot.generatescreenshot(Last_run_path + "CurrentRun.html",
                        Last_run_path + "screenshot.png");

                //    cleanTempDir.cleanandCreate(Reports_path, LatestRun);
                // ZipUtils.ZipFolder(Reports_path + "temp", Reports_path + "ISTF_Reports.zip");
                if (generatescreenshots) {
                    SendingEmail.sendmail(to_list, JenkinsURL, scr_fileList, html_fileList);
                } else {
                    SendingEmail.sendmail(to_list, JenkinsURL, Reports_path + "/Results/HtmlReport.html",
                            Last_run_path + "screenshot.png");
                }

                //  FileUtils.deleteQuietly(new File(Reports_path + "ISTF_Reports.zip"));
                // FileUtils.deleteDirectory(new File(Reports_path + "temp"));
            }
        }
    }
}

From source file:me.gloriouseggroll.quorrabot.Quorrabot.java

public static void main(String[] args) throws IOException {
    String user = "";
    String oauth = "";
    String apioauth = "";
    String channelName = "";
    String webauth = "";
    String webauthro = "";
    String clientid = "";
    String owner = "";
    String hostname = "";
    int baseport = 25300;
    InetAddress ip = InetAddress.getByName("127.0.0.1");
    int port = 0;
    double msglimit30 = 18.75;
    String datastore = "";
    String datastoreconfig = "";
    String youtubekey = "";
    String gamewispauth = "";
    String gamewisprefresh = "";
    String twitchalertstoken = "";
    String lastfmuser = "";
    String tpetoken = "";
    String twittertoken = "";
    String twittertokensecret = "";
    String streamtiptoken = "";
    String streamtipid = "";
    boolean webenable = true;
    boolean musicenable = true;
    boolean usehttps = false;
    String keystorepath = "";
    String keystorepassword = "";
    String timeZone = "";
    String mySqlConn = "";
    String mySqlHost = "";
    String mySqlPort = "";
    String mySqlName = "";
    String mySqlUser = "";
    String mySqlPass = "";
    FollowersCache followersCache;/*from w w w.ja  va 2s.  c om*/
    ChannelUsersCache channelUsersCache;
    ChannelHostCache hostCache;
    SubscribersCache subscribersCache;
    String discordToken = "";
    String discordMainChannel = "";

    boolean changed = false;

    try {
        if (new File("./botlogin.txt").exists()) {
            String data = FileUtils.readFileToString(new File("./botlogin.txt"));
            String[] lines = data.replaceAll("\\r", "").split("\\n");

            for (String line : lines) {

                if (line.startsWith("logtimezone=") && line.length() >= 15) {
                    timeZone = line.substring(12);
                }
                if (line.startsWith("websocketircab")) {
                    Quorrabot.webSocketIRCAB = true;
                }
                if (line.startsWith("user=") && line.length() > 8) {
                    user = line.substring(5);
                }
                if (line.startsWith("oauth=") && line.length() > 9) {
                    oauth = line.substring(6);
                }
                if (line.startsWith("apioauth=") && line.length() > 12) {
                    apioauth = line.substring(9);
                }
                if (line.startsWith("clientid=") && line.length() > 12) {
                    clientid = line.substring(9);
                }
                if (line.startsWith("channel=") && line.length() > 11) {
                    channelName = line.substring(8);
                }
                if (line.startsWith("owner=") && line.length() > 9) {
                    owner = line.substring(6);
                }
                if (line.startsWith("baseport=") && line.length() > 10) {
                    baseport = Integer.parseInt(line.substring(9));
                }
                if (line.startsWith("ip=") && line.length() > 4) {
                    ip = InetAddress.getByName(line.substring(3));
                }
                if (line.startsWith("hostname=") && line.length() > 10) {
                    hostname = line.substring(9);
                }
                if (line.startsWith("port=") && line.length() > 6) {
                    port = Integer.parseInt(line.substring(5));
                }
                if (line.startsWith("msglimit30=") && line.length() > 12) {
                    msglimit30 = Double.parseDouble(line.substring(11));
                }
                if (line.startsWith("datastore=") && line.length() > 11) {
                    datastore = line.substring(10);
                }
                if (line.startsWith("youtubekey=") && line.length() > 12) {
                    youtubekey = line.substring(11);
                }
                if (line.startsWith("gamewispauth=") && line.length() > 14) {
                    gamewispauth = line.substring(13);
                }
                if (line.startsWith("gamewisprefresh=") && line.length() > 17) {
                    gamewisprefresh = line.substring(16);
                }
                if (line.startsWith("twitchalertstoken=") && line.length() > 19) {
                    twitchalertstoken = line.substring(18);
                }
                if (line.startsWith("lastfmuser=") && line.length() > 12) {
                    lastfmuser = line.substring(11);
                }
                if (line.startsWith("tpetoken=") && line.length() > 10) {
                    tpetoken = line.substring(9);
                }
                if (line.startsWith("twittertoken=") && line.length() > 14) {
                    twittertoken = line.substring(13);
                }
                if (line.startsWith("twittertokensecret=") && line.length() > 20) {
                    twittertokensecret = line.substring(19);
                }
                if (line.startsWith("streamtiptoken=") && line.length() > 16) {
                    streamtiptoken = line.substring(15);
                }
                if (line.startsWith("streamtipid=") && line.length() > 13) {
                    streamtipid = line.substring(12);
                }
                if (line.startsWith("webenable=") && line.length() > 11) {
                    webenable = Boolean.valueOf(line.substring(10));
                }
                if (line.startsWith("musicenable=") && line.length() > 13) {
                    musicenable = Boolean.valueOf(line.substring(12));
                }
                if (line.startsWith("usehttps=") && line.length() > 10) {
                    usehttps = Boolean.valueOf(line.substring(9));
                }
                if (line.startsWith("mysqlhost=") && line.length() > 11) {
                    mySqlHost = line.substring(10);
                }
                if (line.startsWith("mysqlport=") && line.length() > 11) {
                    mySqlPort = line.substring(10);
                }
                if (line.startsWith("mysqlname=") && line.length() > 11) {
                    mySqlName = line.substring(10);
                }
                if (line.startsWith("mysqluser=") && line.length() > 11) {
                    mySqlUser = line.substring(10);
                }
                if (line.startsWith("mysqlpass=") && line.length() > 11) {
                    mySqlPass = line.substring(10);
                }
                if (line.startsWith("keystorepath=") && line.length() > 14) {
                    keystorepath = line.substring(13);
                }
                if (line.startsWith("keystorepassword=") && line.length() > 18) {
                    keystorepassword = line.substring(17);
                }
                if (line.startsWith("webauth=") && line.length() > 9) {
                    webauth = line.substring(8);
                }
                if (line.startsWith("webauthro=") && line.length() > 11) {
                    webauthro = line.substring(10);
                }
                if (line.startsWith("discordtoken=") && line.length() >= 14) {
                    discordToken = line.substring(13);
                }
                if (line.startsWith("discordmainchannel=") && line.length() >= 20) {
                    discordMainChannel = line.substring(19);
                }
            }
        }
    } catch (IOException ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }

    /**
     * Check to see if there's a soundboardauth set
     */
    if (webauth.isEmpty()) {
        webauth = generateWebAuth();
        com.gmt2001.Console.debug.println("New webauth key has been generated for botlogin.txt");
        changed = true;
    }
    /**
     * Check to see if there's a soundboardauthread set
     */
    if (webauthro.isEmpty()) {
        webauthro = generateWebAuth();
        com.gmt2001.Console.debug.println("New webauth read-only key has been generated for botlogin.txt");
        changed = true;
    }

    try {
        if (user.isEmpty()) {
            com.gmt2001.Console.out.print("Please enter the bot's twitch username: ");
            user = System.console().readLine().trim().toLowerCase();
            changed = true;
        }
        if (oauth.isEmpty()) {
            com.gmt2001.Console.out.println(
                    "Visit http://quorrabot.com/pages/twitchapi/ to generate oAuth tokens for both the bot and the channel owner accounts (including 'oauth:') & type it below.");
            com.gmt2001.Console.out
                    .println("IMPORTANT: This MUST be done while logged in as the BOT account!" + "\n");
            com.gmt2001.Console.out.println("Please enter the bot's tmi oauth token: ");
            oauth = System.console().readLine().trim();
            changed = true;
        }
        if (channelName.isEmpty()) {
            com.gmt2001.Console.out.print(
                    "Please enter the name of the twitch channel the bot should join (not the url, just the name): ");
            channelName = System.console().readLine().trim().toLowerCase();
            changed = true;
        }
        if (apioauth.isEmpty()) {
            com.gmt2001.Console.out.println(
                    "Visit http://quorrabot.com/pages/twitchapi/ to generate oAuth tokens for both the bot and the channel owner accounts (including 'oauth:') & type it below.");
            com.gmt2001.Console.out.println(
                    "IMPORTANT: This MUST be done while logged in on the CHANNEL OWNER account!" + "\n");
            com.gmt2001.Console.out.println("Please enter the channel owner's tmi oauth token: ");
            apioauth = System.console().readLine().trim();
            changed = true;
        }
    } catch (NullPointerException ex) {
        com.gmt2001.Console.err.printStackTrace(ex);
    }

    if (owner.isEmpty()) {
        owner = channelName;

        changed = true;
    }

    if (args.length > 0) {
        for (String arg : args) {
            if (arg.equalsIgnoreCase("printlogin")) {
                com.gmt2001.Console.out.println("user='" + user + "'");
                com.gmt2001.Console.out.println("oauth='" + oauth + "'");
                com.gmt2001.Console.out.println("apioauth='" + apioauth + "'");
                com.gmt2001.Console.out.println("clientid='" + clientid + "'");
                com.gmt2001.Console.out.println("channel='" + channelName + "'");
                com.gmt2001.Console.out.println("owner='" + owner + "'");
                com.gmt2001.Console.out.println("baseport='" + baseport + "'");
                com.gmt2001.Console.out.println("ip='" + ip.getHostAddress() + "'");
                com.gmt2001.Console.out.println("hostname='" + hostname + "'");
                com.gmt2001.Console.out.println("port='" + port + "'");
                com.gmt2001.Console.out.println("msglimit30='" + msglimit30 + "'");
                com.gmt2001.Console.out.println("datastore='" + datastore + "'");
                com.gmt2001.Console.out.println("youtubekey='" + youtubekey + "'");
                com.gmt2001.Console.out.println("gamewispauth=" + gamewispauth + "'");
                com.gmt2001.Console.out.println("gamewisprefresh=" + gamewisprefresh + "'");
                com.gmt2001.Console.out.println("twitchalertstoken='" + twitchalertstoken + "'");
                com.gmt2001.Console.out.println("lastfmuser='" + lastfmuser + "'");
                com.gmt2001.Console.out.println("tpetoken='" + tpetoken + "'");
                com.gmt2001.Console.out.println("twittertoken='" + twittertoken + "'");
                com.gmt2001.Console.out.println("twittertokensecret='" + twittertokensecret + "'");
                com.gmt2001.Console.out.println("streamtiptoken='" + streamtiptoken + "'");
                com.gmt2001.Console.out.println("streamtipid='" + streamtipid + "'");
                com.gmt2001.Console.out.println("webenable=" + webenable);
                com.gmt2001.Console.out.println("musicenable=" + musicenable);
                com.gmt2001.Console.out.println("usehttps=" + usehttps);
                com.gmt2001.Console.out.println("keystorepath='" + keystorepath + "'");
                com.gmt2001.Console.out.println("keystorepassword='" + keystorepassword + "'");
                com.gmt2001.Console.out.println("discordtoken='" + discordToken + "'");
                com.gmt2001.Console.out.println("discordmainchannel='" + discordMainChannel + "'");
            }
            if (arg.equalsIgnoreCase("debugon")) {
                Quorrabot.enableDebugging = true;
            }
            if (arg.equalsIgnoreCase("ini2sqlite")) {
                com.gmt2001.Console.out.println("Converting default IniStore to default SqliteStore...");
                ini2sqlite(false);
                com.gmt2001.Console.out.println("Operation complete. The bot will now exit");
                System.exit(0);
                return;
            }
            if (arg.toLowerCase().startsWith("user=") && arg.length() > 8) {
                if (!user.equals(arg.substring(5))) {
                    user = arg.substring(5).toLowerCase();
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("oauth=") && arg.length() > 9) {
                if (!oauth.equals(arg.substring(6))) {
                    oauth = arg.substring(6);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("apioauth=") && arg.length() > 12) {
                if (!apioauth.equals(arg.substring(9))) {
                    apioauth = arg.substring(9);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("mysqlhost=") && arg.length() > 11) {
                if (!mySqlHost.equals(arg.substring(10))) {
                    mySqlHost = arg.substring(10);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("mysqlport=") && arg.length() > 11) {
                if (!mySqlPort.equals(arg.substring(10))) {
                    mySqlPort = arg.substring(10);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("mysqlname=") && arg.length() > 11) {
                if (!mySqlName.equals(arg.substring(10))) {
                    mySqlName = arg.substring(10);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("mysqluser=") && arg.length() > 11) {
                if (!mySqlUser.equals(arg.substring(14))) {
                    mySqlUser = arg.substring(10);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("mysqlpass=") && arg.length() > 11) {
                if (!mySqlPass.equals(arg.substring(10))) {
                    mySqlPass = arg.substring(10);
                    changed = true;
                }
            }

            if (arg.toLowerCase().startsWith("clientid=") && arg.length() > 12) {
                if (!clientid.equals(arg.substring(9))) {
                    clientid = arg.substring(9);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("channel=") && arg.length() > 11) {
                if (!channelName.equals(arg.substring(8))) {
                    channelName = arg.substring(8).toLowerCase();
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("owner=") && arg.length() > 9) {
                if (!owner.equals(arg.substring(6))) {
                    owner = arg.substring(6).toLowerCase();
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("baseport=") && arg.length() > 10) {
                if (baseport != Integer.parseInt(arg.substring(9))) {
                    baseport = Integer.parseInt(arg.substring(9));
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("ip=") && arg.length() > 4) {
                if (ip != InetAddress.getByName(arg.substring(3))) {
                    ip = InetAddress.getByName(arg.substring(3));
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("hostname=") && arg.length() > 10) {
                if (!hostname.equals(arg.substring(9))) {
                    hostname = arg.substring(9);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("port=") && arg.length() > 6) {
                if (port != Integer.parseInt(arg.substring(5))) {
                    port = Integer.parseInt(arg.substring(5));
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("msglimit30=") && arg.length() > 12) {
                if (msglimit30 != Double.parseDouble(arg.substring(11))) {
                    msglimit30 = Double.parseDouble(arg.substring(11));
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("datastore=") && arg.length() > 11) {
                if (!datastore.equals(arg.substring(10))) {
                    datastore = arg.substring(10);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("datastoreconfig=") && arg.length() > 17) {
                datastoreconfig = arg.substring(16);
            }
            if (arg.toLowerCase().startsWith("youtubekey=") && arg.length() > 12) {
                if (!youtubekey.equals(arg.substring(11))) {
                    youtubekey = arg.substring(11);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("gamewispauth=") && arg.length() > 14) {
                if (!gamewispauth.equals(arg.substring(13))) {
                    gamewispauth = arg.substring(13);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("gamewisprefresh=") && arg.length() > 17) {
                if (!gamewisprefresh.equals(arg.substring(16))) {
                    gamewisprefresh = arg.substring(16);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("twitchalertstoken=") && arg.length() > 19) {
                if (!twitchalertstoken.equals(arg.substring(18))) {
                    twitchalertstoken = arg.substring(18);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("lastfmuser=") && arg.length() > 12) {
                if (!lastfmuser.equals(arg.substring(11))) {
                    lastfmuser = arg.substring(11);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("tpetoken=") && arg.length() > 10) {
                if (!tpetoken.equals(arg.substring(9))) {
                    tpetoken = arg.substring(9);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("twittertoken=") && arg.length() > 14) {
                if (!twittertoken.equals(arg.substring(13))) {
                    twittertoken = arg.substring(13);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("twittertokensecret=") && arg.length() > 20) {
                if (!twittertokensecret.equals(arg.substring(19))) {
                    twittertokensecret = arg.substring(19);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("streamtiptoken=") && arg.length() > 16) {
                if (!streamtiptoken.equals(arg.substring(15))) {
                    streamtiptoken = arg.substring(15);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("streamtipid=") && arg.length() > 13) {
                if (!streamtipid.equals(arg.substring(12))) {
                    streamtipid = arg.substring(12);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("webenable=") && arg.length() > 11) {
                if (webenable != Boolean.valueOf(arg.substring(10))) {
                    webenable = Boolean.valueOf(arg.substring(10));
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("musicenable=") && arg.length() > 13) {
                if (musicenable != Boolean.valueOf(arg.substring(12))) {
                    musicenable = Boolean.valueOf(arg.substring(12));
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("usehttps=") && arg.length() > 10) {
                if (usehttps != Boolean.valueOf(arg.substring(9))) {
                    usehttps = Boolean.valueOf(arg.substring(9));
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("keystorepath=") && arg.length() > 14) {
                if (!keystorepath.equals(arg.substring(13))) {
                    keystorepath = arg.substring(13);
                    changed = true;
                }
            }
            if (arg.toLowerCase().startsWith("keystorepassword=") && arg.length() > 18) {
                if (!keystorepassword.equals(arg.substring(17))) {
                    keystorepassword = arg.substring(17);
                    changed = true;
                }
            }

            if (arg.equalsIgnoreCase("help") || arg.equalsIgnoreCase("--help") || arg.equalsIgnoreCase("-h")
                    || arg.equalsIgnoreCase("-?")) {
                com.gmt2001.Console.out.println(
                        "Usage: java -Dfile.encoding=UTF-8 -jar QuorraBot.jar [printlogin] [user=<bot username>] "
                                + "[oauth=<bot irc oauth>] [apioauth=<editor oauth>] [clientid=<oauth clientid>] [channel=<channel to join>] "
                                + "[owner=<bot owner username>] [baseport=<bot webserver port, music server will be +1>] [ip=<IP address (optional) to bind to>] [hostname=<custom irc server>] "
                                + "[port=<custom irc port>] [msglimit30=<message limit per 30 seconds>] "
                                + "[datastore=<DataStore type, for a list, run java -jar QuorraBot.jar storetypes>] "
                                + "[datastoreconfig=<Optional DataStore config option, different for each DataStore type>] "
                                + "[youtubekey=<youtube api key>] [webenable=<true | false>] [musicenable=<true | false>] "
                                + "[gamewispauth=<gamewisp oauth>] "
                                + "[gamewisprefresh=<gamewisp refresh key>] "
                                + "[twitchalertstoken=<TwitchAlerts access token>] "
                                + "[lastfmuser=<Last.FM username>] " + "[tpetoken=<Tipeeestream access token>] "
                                + "[streamtiptoken=<StreamTip access token>] "
                                + "[streamtipid=<StreamTip Client ID>] "
                                + "[twittertoken=<Twitter access token>] "
                                + "[twittertokensecret=<Twitter access token secret>]");

                return;
            }
            if (arg.equalsIgnoreCase("storetypes")) {
                com.gmt2001.Console.out.println(
                        "DataStore types: IniStore (datastoreconfig parameter is folder name, stores in .ini files), "
                                + "TempStore (Stores in memory, lost on shutdown), "
                                + "SqliteStore (Default, Stores in a SQLite3 database, datastoreconfig parameter is a config file");
                return;
            }
        }
    }

    if (changed) {
        String data = "";
        data += "user=" + user + "\r\n";
        data += "oauth=" + oauth + "\r\n";
        data += "apioauth=" + apioauth + "\r\n";
        data += "clientid=" + clientid + "\r\n";
        data += "webauth=" + webauth + "\r\n";
        data += "webauthro=" + webauthro + "\r\n";
        data += "channel=" + channelName + "\r\n";
        data += "owner=" + owner + "\r\n";
        data += "baseport=" + baseport + "\r\n";
        data += "ip=" + ip.getHostAddress() + "\r\n";
        data += "hostname=" + hostname + "\r\n";
        data += "port=" + port + "\r\n";
        data += "msglimit30=" + msglimit30 + "\r\n";
        data += "datastore=" + datastore + "\r\n";
        data += "youtubekey=" + youtubekey + "\r\n";
        data += "gamewispauth=" + gamewispauth + "\r\n";
        data += "gamewisprefresh=" + gamewisprefresh + "\r\n";
        data += "twitchalertstoken=" + twitchalertstoken + "\r\n";
        data += "lastfmuser=" + lastfmuser + "\r\n";
        data += "tpetoken=" + tpetoken + "\r\n";
        data += "twittertoken=" + twittertoken + "\r\n";
        data += "twittertokensecret=" + twittertokensecret + "\r\n";
        data += "streamtiptoken=" + streamtiptoken + "\r\n";
        data += "streamtipid=" + streamtipid + "\r\n";
        data += "webenable=" + webenable + "\r\n";
        data += "musicenable=" + musicenable + "\r\n";
        data += "usehttps=" + usehttps + "\r\n";
        data += "logtimezone=" + timeZone + "\r\n";
        data += "mysqlhost=" + mySqlHost + "\r\n";
        data += "mysqlport=" + mySqlPort + "\r\n";
        data += "mysqlname=" + mySqlName + "\r\n";
        data += "mysqluser=" + mySqlUser + "\r\n";
        data += "mysqlpass=" + mySqlPass + "\r\n";
        data += "keystorepath=" + keystorepath + "\r\n";
        data += "keystorepassword=" + keystorepassword + "\r\n";
        data += "discordtoken=" + discordToken + "\r\n";
        data += "discordmainchannel=" + discordMainChannel;

        Files.write(Paths.get("./botlogin.txt"), data.getBytes(StandardCharsets.UTF_8),
                StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
    }
    channelUsersCache = ChannelUsersCache.instance(owner);
    followersCache = FollowersCache.instance(owner);
    hostCache = ChannelHostCache.instance(owner);
    subscribersCache = SubscribersCache.instance(owner);

    Quorrabot.instance = new Quorrabot(user, oauth, apioauth, clientid, channelName, owner, baseport, ip,
            hostname, port, msglimit30, datastore, datastoreconfig, youtubekey, gamewispauth, gamewisprefresh,
            twitchalertstoken, lastfmuser, tpetoken, twittertoken, twittertokensecret, streamtiptoken,
            streamtipid, webenable, webauth, webauthro, musicenable, usehttps, timeZone, mySqlHost, mySqlPort,
            mySqlConn, mySqlPass, mySqlUser, mySqlName, keystorepath, followersCache, hostCache,
            channelUsersCache, subscribersCache, discordToken, discordMainChannel);
}

From source file:main.java.RMDupper.java

public static void main(String[] args) throws IOException {
    System.err.println("DeDup v" + VERSION);
    // the command line parameters
    Options helpOptions = new Options();
    helpOptions.addOption("h", "help", false, "show this help page");
    Options options = new Options();
    options.addOption("h", "help", false, "show this help page");
    options.addOption("i", "input", true,
            "the input file if this option is not specified,\nthe input is expected to be piped in");
    options.addOption("o", "output", true, "the output folder. Has to be specified if input is set.");
    options.addOption("m", "merged", false,
            "the input only contains merged reads.\n If this option is specified read names are not examined for prefixes.\n Both the start and end of the aligment are considered for all reads.");
    options.addOption("v", "version", false, "the version of DeDup.");
    HelpFormatter helpformatter = new HelpFormatter();
    CommandLineParser parser = new BasicParser();
    try {/*from w w  w  .  j a  v a 2 s.  co  m*/
        CommandLine cmd = parser.parse(helpOptions, args);
        if (cmd.hasOption('h')) {
            helpformatter.printHelp(CLASS_NAME, options);
            System.exit(0);
        }
    } catch (ParseException e1) {
    }

    String input = "";
    String outputpath = "";
    Boolean merged = Boolean.FALSE;
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption('i')) {
            input = cmd.getOptionValue('i');
            piped = false;
        }
        if (cmd.hasOption('o')) {
            outputpath = cmd.getOptionValue('o');
        }
        if (cmd.hasOption('m')) {
            merged = Boolean.TRUE;
        }
        if (cmd.hasOption('v')) {
            System.out.println("DeDup v" + VERSION);
            System.exit(0);
        }
    } catch (ParseException e) {
        helpformatter.printHelp(CLASS_NAME, options);
        System.err.println(e.getMessage());
        System.exit(0);
    }
    DecimalFormat df = new DecimalFormat("##.##");

    if (piped) {
        RMDupper rmdup = new RMDupper(System.in, System.out, merged);
        rmdup.readSAMFile();

        System.err.println("We are in piping mode!");
        System.err.println("Total reads: " + rmdup.dupStats.total + "\n");
        System.err.println("Reverse removed: " + rmdup.dupStats.removed_reverse + "\n");
        System.err.println("Forward removed: " + rmdup.dupStats.removed_forward + "\n");
        System.err.println("Merged removed: " + rmdup.dupStats.removed_merged + "\n");
        System.err.println("Total removed: " + (rmdup.dupStats.removed_forward + rmdup.dupStats.removed_merged
                + rmdup.dupStats.removed_reverse) + "\n");
        if (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_forward
                + rmdup.dupStats.removed_reverse == 0) {
            System.err.println("Duplication Rate: " + df.format(0.00));
        } else {
            System.err.println("Duplication Rate: "
                    + df.format((double) (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse
                            + rmdup.dupStats.removed_forward) / (double) rmdup.dupStats.total));
        }

    } else {
        if (outputpath.length() == 0) {
            System.err.println("The output folder has to be specified");
            helpformatter.printHelp(CLASS_NAME, options);
            System.exit(0);
        }

        //Check whether we have a directory as output path, else produce error message and quit!

        File f = new File(outputpath);
        if (!f.isDirectory()) {
            System.err.println("The output folder should be a folder and not a file!");
            System.exit(0);
        }

        File inputFile = new File(input);
        File outputFile = new File(
                outputpath + "/" + Files.getNameWithoutExtension(inputFile.getAbsolutePath()) + "_rmdup.bam");
        File outputlog = new File(
                outputpath + "/" + Files.getNameWithoutExtension(inputFile.getAbsolutePath()) + ".log");
        File outputhist = new File(
                outputpath + "/" + Files.getNameWithoutExtension(inputFile.getAbsolutePath()) + ".hist");

        try {
            FileWriter fw = new FileWriter(outputlog);
            FileWriter histfw = new FileWriter(outputhist);
            BufferedWriter bfw = new BufferedWriter(fw);
            BufferedWriter histbfw = new BufferedWriter(histfw);

            RMDupper rmdup = new RMDupper(inputFile, outputFile, merged);
            rmdup.readSAMFile();
            rmdup.inputSam.close();
            rmdup.outputSam.close();

            bfw.write("Total reads: " + rmdup.dupStats.total + "\n");
            bfw.write("Reverse removed: " + rmdup.dupStats.removed_reverse + "\n");
            bfw.write("Forward removed: " + rmdup.dupStats.removed_forward + "\n");
            bfw.write("Merged removed: " + rmdup.dupStats.removed_merged + "\n");
            bfw.write("Total removed: " + (rmdup.dupStats.removed_forward + rmdup.dupStats.removed_merged
                    + rmdup.dupStats.removed_reverse) + "\n");
            bfw.write("Duplication Rate: "
                    + df.format((double) (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse
                            + rmdup.dupStats.removed_forward) / (double) rmdup.dupStats.total));
            bfw.flush();
            bfw.close();

            histbfw.write(rmdup.oc.getHistogram());
            histbfw.flush();
            histbfw.close();

            System.out.println("Total reads: " + rmdup.dupStats.total + "\n");
            System.out.println("Unmerged removed: "
                    + (rmdup.dupStats.removed_forward + rmdup.dupStats.removed_reverse) + "\n");
            System.out.println("Merged removed: " + rmdup.dupStats.removed_merged + "\n");
            System.out.println("Total removed: " + (rmdup.dupStats.removed_forward
                    + rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse) + "\n");
            if (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_forward
                    + rmdup.dupStats.removed_reverse == 0) {
                System.out.println("Duplication Rate: " + df.format(0.00));
            } else {
                System.out.println("Duplication Rate: "
                        + df.format((double) (rmdup.dupStats.removed_merged + rmdup.dupStats.removed_reverse
                                + rmdup.dupStats.removed_forward) / (double) rmdup.dupStats.total));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:net.sf.extjwnl.cli.ewn.java

public static void main(String[] args) throws IOException, JWNLException {
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(0);//from  www .  j a  v a 2 s  .com
    }
    //find dictionary
    Dictionary d = null;
    File config = new File(defaultConfig);
    if (!config.exists()) {
        if (System.getenv().containsKey("WNHOME")) {
            String wnHomePath = System.getenv().get("WNHOME");
            File wnHome = new File(wnHomePath);
            if (wnHome.exists()) {
                d = Dictionary.getFileBackedInstance(wnHomePath);
            } else {
                log.error("Cannot find dictionary. Make sure " + defaultConfig
                        + " is available or WNHOME variable is set.");
            }
        }
    } else {
        d = Dictionary.getInstance(new FileInputStream(config));
    }

    if (null != d) {
        //parse and execute command line
        if ((-1 < args[0].indexOf('%') && -1 < args[0].indexOf(':')) || "-script".equals(args[0])
                || (-1 < args[0].indexOf('#'))) {
            d.edit();
            //edit
            if ("-script".equals(args[0])) {
                if (args.length < 2) {
                    log.error("Filename missing for -script command");
                    System.exit(1);
                } else {
                    File script = new File(args[1]);
                    if (script.exists()) {
                        //load into args
                        ArrayList<String> newArgs = new ArrayList<String>();
                        BufferedReader in = new BufferedReader(
                                new InputStreamReader(new FileInputStream(script), "UTF-8"));
                        try {
                            String str;
                            while ((str = in.readLine()) != null) {
                                String[] bits = str.split(" ");
                                StringBuilder tempArg = null;
                                for (String bit : bits) {
                                    int quoteCnt = 0;
                                    for (int j = 0; j < bit.length(); j++) {
                                        if ('"' == bit.charAt(j)) {
                                            quoteCnt++;
                                        }
                                    }
                                    if (null != tempArg) {
                                        if (0 == quoteCnt) {
                                            tempArg.append(" ").append(bit);
                                        } else {
                                            tempArg.append(" ").append(bit.replaceAll("\"\"", "\""));
                                            if (1 == (quoteCnt % 2)) {
                                                newArgs.add(
                                                        tempArg.toString().substring(1, tempArg.length() - 1));
                                                tempArg = null;
                                            }
                                        }
                                    } else {
                                        if (0 == quoteCnt) {
                                            newArgs.add(bit);
                                        } else {
                                            if (1 == (quoteCnt % 2)) {
                                                tempArg = new StringBuilder(bit.replaceAll("\"\"", "\""));
                                            } else {
                                                newArgs.add(bit.replaceAll("\"\"", "\""));
                                            }
                                        }
                                    }
                                }
                                if (null != tempArg) {
                                    newArgs.add(tempArg.toString());
                                }
                            }
                        } finally {
                            try {
                                in.close();
                            } catch (IOException e) {
                                //nop
                            }
                        }
                        args = newArgs.toArray(args);
                    }
                }
            }

            Word workWord = null;
            String key = null;
            String lemma = null;
            int lexFileNum = -1;
            int lexId = -1;
            //                String headLemma = null;
            //                int headLexId = -1;
            POS pos = null;
            String derivation = null;

            for (int i = 0; i < args.length; i++) {
                if (null == key && '-' != args[i].charAt(0)
                        && ((-1 < args[i].indexOf('%') && -1 < args[i].indexOf(':')))) {
                    key = args[i];
                    log.info("Searching " + key + "...");
                    if (null != key) {
                        workWord = d.getWordBySenseKey(key);
                    }
                    if (null == workWord) {
                        //parse sensekey
                        lemma = key.substring(0, key.indexOf('%')).replace('_', ' ');
                        String posId = key.substring(key.indexOf('%') + 1, key.indexOf(':'));
                        if ("1".equals(posId) || "2".equals(posId) || "3".equals(posId) || "4".equals(posId)
                                || "5".equals(posId)) {
                            pos = POS.getPOSForId(Integer.parseInt(posId));
                            String lexFileString = key.substring(key.indexOf(':') + 1);
                            if (-1 < lexFileString.indexOf(':')) {
                                lexFileNum = Integer
                                        .parseInt(lexFileString.substring(0, lexFileString.indexOf(':')));
                                if (lexFileString.indexOf(':') + 1 < lexFileString.length()) {
                                    String lexIdString = lexFileString
                                            .substring(lexFileString.indexOf(':') + 1);
                                    if (-1 < lexIdString.indexOf(':')) {
                                        lexId = Integer
                                                .parseInt(lexIdString.substring(0, lexIdString.indexOf(':')));
                                        //                                            if (lexIdString.indexOf(':') + 1 < lexIdString.length()) {
                                        //                                                headLemma = lexIdString.substring(lexIdString.indexOf(':') + 1);
                                        //                                                if (-1 < headLemma.indexOf(':')) {
                                        //                                                    headLemma = headLemma.substring(0, headLemma.indexOf(':'));
                                        //                                                    if (null != headLemma && !"".equals(headLemma) && lexIdString.lastIndexOf(':') + 1 < lexIdString.length()) {
                                        //                                                        headLexId = Integer.parseInt(lexIdString.substring(lexIdString.lastIndexOf(':') + 1));
                                        //                                                    }
                                        //                                                } else {
                                        //                                                    log.error("Malformed sensekey " + key);
                                        //                                                    System.exit(1);
                                        //                                                }
                                        //                                            }
                                    } else {
                                        log.error("Malformed sensekey " + key);
                                        System.exit(1);
                                    }
                                } else {
                                    log.error("Malformed sensekey " + key);
                                    System.exit(1);
                                }
                            } else {
                                log.error("Malformed sensekey " + key);
                                System.exit(1);
                            }
                        } else {
                            log.error("Malformed sensekey " + key);
                            System.exit(1);
                        }
                    }
                } else if (-1 < args[i].indexOf('#')) {
                    if (2 < args[i].length()) {
                        derivation = args[i].substring(2);
                        if (null == derivation) {
                            log.error("Missing derivation");
                            System.exit(1);
                        } else {
                            pos = POS.getPOSForKey(args[i].substring(0, 1));
                            if (null == pos) {
                                log.error("POS " + args[i] + " is not recognized for derivation " + derivation);
                                System.exit(1);
                            }
                        }
                    }
                }

                if ("-add".equals(args[i])) {
                    if (null == key) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    }
                    if (null != workWord) {
                        log.error("Duplicate sensekey " + workWord.getSenseKey());
                        System.exit(1);
                    }
                    log.info("Creating " + pos.getLabel() + " synset...");
                    Synset tempSynset = d.createSynset(pos);
                    log.info("Creating word " + lemma + "...");
                    workWord = new Word(d, tempSynset, 1, lemma);
                    workWord.setLexId(lexId);
                    tempSynset.getWords().add(workWord);
                    tempSynset.setLexFileNum(lexFileNum);
                    key = null;
                }

                if ("-remove".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        d.removeSynset(workWord.getSynset());
                        workWord = null;
                        key = null;
                    }
                }

                if ("-addword".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length && '-' != args[i].charAt(0)) {
                            Word tempWord = new Word(d, workWord.getSynset(),
                                    workWord.getSynset().getWords().size() + 1, args[i]);
                            workWord.getSynset().getWords().add(tempWord);
                            key = null;
                        } else {
                            log.error(
                                    "Missing word for addword command for sensekey " + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-removeword".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        workWord.getSynset().getWords().remove(workWord);
                        key = null;
                    }
                }

                if ("-setgloss".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length && '-' != args[i].charAt(0)) {
                            workWord.getSynset().setGloss(args[i]);
                            key = null;
                        } else {
                            log.error("Missing gloss for setgloss command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-setadjclus".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length && '-' != args[i].charAt(0)) {
                            workWord.getSynset().setIsAdjectiveCluster(Boolean.parseBoolean(args[i]));
                            key = null;
                        } else {
                            log.error("Missing flag for setadjclus command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-setverbframe".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length) {
                            if (workWord instanceof Verb) {
                                Verb verb = (Verb) workWord;
                                if ('-' == args[i].charAt(0)) {
                                    verb.getVerbFrameFlags().clear(Integer.parseInt(args[i].substring(1)));
                                } else {
                                    verb.getVerbFrameFlags().set(Integer.parseInt(args[i]));
                                }
                            } else {
                                log.error("Word at " + workWord.getSenseKey() + " should be verb");
                                System.exit(1);
                            }
                            key = null;
                        } else {
                            log.error("Missing index for setverbframe command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-setverbframeall".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length) {
                            if (workWord.getSynset() instanceof VerbSynset) {
                                if ('-' == args[i].charAt(0)) {
                                    workWord.getSynset().getVerbFrameFlags()
                                            .clear(Integer.parseInt(args[i].substring(1)));
                                } else {
                                    workWord.getSynset().getVerbFrameFlags().set(Integer.parseInt(args[i]));
                                }
                            } else {
                                log.error("Synset at " + workWord.getSenseKey() + " should be verb");
                                System.exit(1);
                            }
                            key = null;
                        } else {
                            log.error("Missing index for setverbframeall command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-setlexfile".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length && '-' != args[i].charAt(0)) {
                            if (-1 < args[i].indexOf('.')) {
                                workWord.getSynset()
                                        .setLexFileNum(LexFileNameLexFileIdMap.getMap().get(args[i]));
                            } else {
                                workWord.getSynset().setLexFileNum(Integer.parseInt(args[i]));
                            }
                        } else {
                            log.error("Missing file number or name for setlexfile command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-addptr".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length) {
                            Word targetWord = d.getWordBySenseKey(args[i]);
                            if (null != targetWord) {
                                i++;
                                if (i < args.length) {
                                    PointerType pt = PointerType.getPointerTypeForKey(args[i]);
                                    if (null != pt) {
                                        Pointer p;
                                        if (pt.isLexical()) {
                                            p = new Pointer(pt, workWord, targetWord);
                                        } else {
                                            p = new Pointer(pt, workWord.getSynset(), targetWord.getSynset());
                                        }
                                        if (!workWord.getSynset().getPointers().contains(p)) {
                                            workWord.getSynset().getPointers().add(p);
                                        } else {
                                            log.error("Duplicate pointer of type " + pt + " to "
                                                    + targetWord.getSenseKey()
                                                    + " in addptr command for sensekey "
                                                    + workWord.getSenseKey());
                                            System.exit(1);
                                        }
                                    } else {
                                        log.error("Invalid pointer type at " + args[i]
                                                + " in addptr command for sensekey " + workWord.getSenseKey());
                                        System.exit(1);
                                    }
                                } else {
                                    log.error("Missing pointer type at " + args[i]
                                            + " in addptr command for sensekey " + workWord.getSenseKey());
                                    System.exit(1);
                                }
                            } else {
                                log.error("Missing target at " + args[i] + " in addptr command for sensekey "
                                        + workWord.getSenseKey());
                                System.exit(1);
                            }
                            key = null;
                        } else {
                            log.error("Missing sensekey for addptr command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-removeptr".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length) {
                            Word targetWord = d.getWordBySenseKey(args[i]);
                            if (null != targetWord) {
                                i++;
                                if (i < args.length) {
                                    PointerType pt = PointerType.getPointerTypeForKey(args[i]);
                                    if (null != pt) {
                                        Pointer p;
                                        if (pt.isLexical()) {
                                            p = new Pointer(pt, workWord, targetWord);
                                        } else {
                                            p = new Pointer(pt, workWord.getSynset(), targetWord.getSynset());
                                        }
                                        if (workWord.getSynset().getPointers().contains(p)) {
                                            workWord.getSynset().getPointers().remove(p);
                                        } else {
                                            log.error("Missing pointer of type " + pt + " to "
                                                    + targetWord.getSenseKey()
                                                    + " in removeptr command for sensekey "
                                                    + workWord.getSenseKey());
                                            System.exit(1);
                                        }
                                    } else {
                                        log.error("Invalid pointer type at " + args[i]
                                                + " in removeptr command for sensekey "
                                                + workWord.getSenseKey());
                                        System.exit(1);
                                    }
                                } else {
                                    log.error("Missing pointer type at " + args[i]
                                            + " in removeptr command for sensekey " + workWord.getSenseKey());
                                    System.exit(1);
                                }
                            } else {
                                log.error("Missing target at " + args[i] + " in removeptr command for sensekey "
                                        + workWord.getSenseKey());
                                System.exit(1);
                            }
                            key = null;
                        } else {
                            log.error("Missing sensekey for removeptr command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-setlexid".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length && '-' != args[i].charAt(0)) {
                            workWord.setLexId(Integer.parseInt(args[i]));
                            key = null;
                        } else {
                            log.error("Missing lexid for setlexid command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-setusecount".equals(args[i])) {
                    if (null == workWord) {
                        log.error("Missing sensekey");
                        System.exit(1);
                    } else {
                        i++;
                        if (i < args.length && '-' != args[i].charAt(0)) {
                            workWord.setUseCount(Integer.parseInt(args[i]));
                            key = null;
                        } else {
                            log.error("Missing count for setusecount command for sensekey "
                                    + workWord.getSenseKey());
                            System.exit(1);
                        }
                    }
                }

                if ("-addexc".equals(args[i])) {
                    i++;
                    if (i < args.length && '-' != args[i].charAt(0)) {
                        String baseform = args[i];
                        Exc e = d.getException(pos, derivation);
                        if (null != e) {
                            if (null != e.getExceptions()) {
                                if (!e.getExceptions().contains(baseform)) {
                                    e.getExceptions().add(baseform);
                                }
                            }
                        } else {
                            ArrayList<String> list = new ArrayList<String>(1);
                            list.add(baseform);
                            d.createException(pos, derivation, list);
                        }
                        derivation = null;
                    } else {
                        log.error("Missing baseform for addexc command for derivation " + derivation);
                        System.exit(1);
                    }
                }

                if ("-removeexc".equals(args[i])) {
                    Exc e = d.getException(pos, derivation);
                    if (null != e) {
                        i++;
                        if (i < args.length && '-' != args[i].charAt(0)) {
                            String baseform = args[i];
                            if (null != e.getExceptions()) {
                                if (e.getExceptions().contains(baseform)) {
                                    e.getExceptions().remove(baseform);
                                }
                                if (0 == e.getExceptions().size()) {
                                    d.removeException(e);
                                }
                            }
                        } else {
                            d.removeException(e);
                        }
                    } else {
                        log.error("Missing derivation " + derivation);
                        System.exit(1);
                    }
                    derivation = null;
                }
            }

            d.save();
        } else {
            //browse
            String key = args[0];
            if (1 == args.length) {
                for (POS pos : POS.getAllPOS()) {
                    IndexWord iw = d.getIndexWord(pos, key);
                    if (null == iw) {
                        System.out.println("\nNo information available for " + pos.getLabel() + " " + key);
                    } else {
                        System.out.println(
                                "\nInformation available for " + iw.getPOS().getLabel() + " " + iw.getLemma());
                        printAvailableInfo(iw);
                    }
                    if (null != d.getMorphologicalProcessor()) {
                        List<String> forms = d.getMorphologicalProcessor().lookupAllBaseForms(pos, key);
                        if (null != forms) {
                            for (String form : forms) {
                                if (!key.equals(form)) {
                                    iw = d.getIndexWord(pos, form);
                                    if (null != iw) {
                                        System.out.println("\nInformation available for "
                                                + iw.getPOS().getLabel() + " " + iw.getLemma());
                                        printAvailableInfo(iw);
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                boolean needHelp = false;
                boolean needGloss = false;
                boolean needLex = false;
                boolean needOffset = false;
                boolean needSenseNum = false;
                boolean needSenseKeys = false;
                int needSense = 0;
                for (String arg : args) {
                    if ("-h".equals(arg)) {
                        needHelp = true;
                    }
                    if ("-g".equals(arg)) {
                        needGloss = true;
                    }
                    if ("-a".equals(arg)) {
                        needLex = true;
                    }
                    if ("-o".equals(arg)) {
                        needOffset = true;
                    }
                    if ("-s".equals(arg)) {
                        needSenseNum = true;
                    }
                    if ("-k".equals(arg)) {
                        needSenseKeys = true;
                    }
                    if (arg.startsWith("-n") && 2 < arg.length()) {
                        needSense = Integer.parseInt(arg.substring(2));
                    }
                }

                for (String arg : args) {
                    if (arg.startsWith("-ants") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Display synsets containing direct antonyms of the search string.\n" + "\n"
                                            + "Direct antonyms are a pair of words between which there is an\n"
                                            + "associative bond built up by co-occurrences.\n" + "\n"
                                            + "Antonym synsets are preceded by \"=>\".");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nAntonyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.ANTONYM, 1, needSense, needGloss, needLex, needOffset,
                                    needSenseNum, needSenseKeys);
                        }
                    } //ants

                    if (arg.startsWith("-hype") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Recursively display hypernym (superordinate) tree for the search\n"
                                            + "string.\n" + "\n"
                                            + "Hypernym is the generic term used to designate a whole class of\n"
                                            + "specific instances.  Y is a hypernym of X if X is a (kind of) Y.\n"
                                            + "\n"
                                            + "Hypernym synsets are preceded by \"=>\", and are indented from\n"
                                            + "the left according to their level in the hierarchy.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nHypernyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.HYPERNYM, PointerUtils.INFINITY, needSense, needGloss,
                                    needLex, needOffset, needSenseNum, needSenseKeys);
                        }
                    } //hype

                    if (arg.startsWith("-hypo") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Display immediate hyponyms (subordinates) for the search string.\n" + "\n"
                                            + "Hyponym is the generic term used to designate a member of a class.\n"
                                            + "X is a hyponym of Y if X is a (kind of) Y.\n" + "\n"
                                            + "Hyponym synsets are preceded by \"=>\".");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nHyponyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.HYPONYM, 1, needSense, needGloss, needLex, needOffset,
                                    needSenseNum, needSenseKeys);
                        }
                    } //hypo

                    if (arg.startsWith("-tree") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Display hyponym (subordinate) tree for the search string.  This is\n"
                                            + "a recursive search that finds the hyponyms of each hyponym. \n"
                                            + "\n"
                                            + "Hyponym is the generic term used to designate a member of a class.\n"
                                            + "X is a hyponym of Y if X is a (kind of) Y. \n" + "\n"
                                            + "Hyponym synsets are preceded by \"=>\", and are indented from the left\n"
                                            + "according to their level in the hierarchy.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nHyponyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.HYPONYM, PointerUtils.INFINITY, needSense, needGloss,
                                    needLex, needOffset, needSenseNum, needSenseKeys);
                        }
                    } //tree

                    if (arg.startsWith("-enta") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Recursively display entailment relations of the search string.\n" + "\n"
                                            + "The action represented by the verb X entails Y if X cannot be done\n"
                                            + "unless Y is, or has been, done.\n" + "\n"
                                            + "Entailment synsets are preceded by \"=>\", and are indented from the left\n"
                                            + "according to their level in the hierarchy.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nEntailment of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.ENTAILMENT, PointerUtils.INFINITY, needSense,
                                    needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                        }
                    } //enta

                    if (arg.startsWith("-syns") && 6 == arg.length()) {
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nSynonyms of " + p.getLabel() + " " + iw.getLemma());
                            if (POS.ADJECTIVE == p) {
                                if (needHelp) {
                                    System.out.println(
                                            "Display synonyms and synsets related to synsets containing\n"
                                                    + "the search string.  If the search string is in a head synset\n"
                                                    + "the 'cluster's' satellite synsets are displayed.  If the search\n"
                                                    + "string is in a satellite synset, its head synset is displayed.\n"
                                                    + "If the search string is a pertainym the word or synset that it\n"
                                                    + "pertains to is displayed.\n" + "\n"
                                                    + "A cluster is a group of adjective synsets that are organized around\n"
                                                    + "antonymous pairs or triplets.  An adjective cluster contains two or more\n"
                                                    + "head synsets that contan antonyms.  Each head synset has one or more\n"
                                                    + "satellite synsets.\n" + "\n"
                                                    + "A head synset contains at least one word that has a direct antonym\n"
                                                    + "in another head synset of the same cluster.\n" + "\n"
                                                    + "A satellite synset represents a concept that is similar in meaning to\n"
                                                    + "the concept represented by its head synset.\n" + "\n"
                                                    + "Direct antonyms are a pair of words between which there is an\n"
                                                    + "associative bond built up by co-occurrences.\n" + "\n"
                                                    + "Direct antonyms are printed in parentheses following the adjective.\n"
                                                    + "The position of an adjective in relation to the noun may be restricted\n"
                                                    + "to the prenominal, postnominal or predicative position.  Where present\n"
                                                    + "these restrictions are noted in parentheses.\n" + "\n"
                                                    + "A pertainym is a relational adjective, usually defined by such phrases\n"
                                                    + "as \"of or pertaining to\" and that does not have an antonym.  It pertains\n"
                                                    + "to a noun or another pertainym.\n" + "\n"
                                                    + "Senses contained in head synsets are displayed above the satellites,\n"
                                                    + "which are indented and preceded by \"=>\".  Senses contained in\n"
                                                    + "satellite synsets are displayed with the head synset below.  The head\n"
                                                    + "synset is preceded by \"=>\".\n" + "\n"
                                                    + "Pertainym senses display the word or synsets that the search string\n"
                                                    + "pertains to.");
                                }
                                tracePointers(iw, PointerType.SIMILAR_TO, 1, needSense, needGloss, needLex,
                                        needOffset, needSenseNum, needSenseKeys);
                                tracePointers(iw, PointerType.PARTICIPLE_OF, 1, needSense, needGloss, needLex,
                                        needOffset, needSenseNum, needSenseKeys);
                            }

                            if (POS.ADVERB == p) {
                                if (needHelp) {
                                    System.out.println(
                                            "Display synonyms and synsets related to synsets containing\n"
                                                    + "the search string.  If the search string is a pertainym the word\n"
                                                    + "or synset that it pertains to is displayed.\n" + "\n"
                                                    + "A pertainym is a relational adverb that is derived from an adjective.\n"
                                                    + "\n"
                                                    + "Pertainym senses display the word that the search string is derived from\n"
                                                    + "and the adjective synset that contains the word.  If the adjective synset\n"
                                                    + "is a satellite synset, its head synset is also displayed.");
                                }
                                tracePointers(iw, PointerType.PERTAINYM, 1, needSense, needGloss, needLex,
                                        needOffset, needSenseNum, needSenseKeys);
                            }

                            if (POS.NOUN == p || POS.VERB == p) {
                                if (needHelp) {
                                    System.out.println(
                                            "Recursively display hypernym (superordinate) tree for the search\n"
                                                    + "string.\n" + "\n"
                                                    + "Hypernym is the generic term used to designate a whole class of\n"
                                                    + "specific instances.  Y is a hypernym of X if X is a (kind of) Y.\n"
                                                    + "\n"
                                                    + "Hypernym synsets are preceded by \"=>\", and are indented from\n"
                                                    + "the left according to their level in the hierarchy.");
                                }
                                tracePointers(iw, PointerType.HYPERNYM, PointerUtils.INFINITY, needSense,
                                        needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                            }
                        }
                    } //syns

                    if (arg.startsWith("-smem") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all holonyms of the search string.\n" + "\n"
                                    + "A holonym is the name of the whole of which the 'meronym' names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.\n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nMember Holonyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.MEMBER_HOLONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //smem

                    if (arg.startsWith("-ssub") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all holonyms of the search string.\n" + "\n"
                                    + "A holonym is the name of the whole of which the 'meronym' names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.\n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nSubstance Holonyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.SUBSTANCE_HOLONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //ssub

                    if (arg.startsWith("-sprt") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all holonyms of the search string.\n" + "\n"
                                    + "A holonym is the name of the whole of which the 'meronym' names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.\n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nPart Holonyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.PART_HOLONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //sprt

                    if (arg.startsWith("-memb") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all meronyms of the search string. \n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.\n" + "\n"
                                    + "A holonym is the name of the whole of which the meronym names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nMember Meronyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.MEMBER_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //memb

                    if (arg.startsWith("-subs") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all meronyms of the search string. \n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.\n" + "\n"
                                    + "A holonym is the name of the whole of which the meronym names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nSubstance Meronyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.SUBSTANCE_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //subs

                    if (arg.startsWith("-part") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all meronyms of the search string. \n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.\n" + "\n"
                                    + "A holonym is the name of the whole of which the meronym names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nPart Meronyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.PART_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //part

                    if (arg.startsWith("-mero") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all meronyms of the search string. \n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.\n" + "\n"
                                    + "A holonym is the name of the whole of which the meronym names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nMeronyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.MEMBER_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.SUBSTANCE_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.PART_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //mero

                    if (arg.startsWith("-holo") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all holonyms of the search string.\n" + "\n"
                                    + "A holonym is the name of the whole of which the 'meronym' names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.\n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nHolonyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.MEMBER_HOLONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.SUBSTANCE_HOLONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.PART_HOLONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //holo

                    if (arg.startsWith("-caus") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Recursively display CAUSE TO relations of the search string.\n"
                                    + "\n"
                                    + "The action represented by the verb X causes the action represented by\n"
                                    + "the verb Y.\n" + "\n"
                                    + "CAUSE TO synsets are preceded by \"=>\", and are indented from the left\n"
                                    + "according to their level in the hierarchy.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\n'Cause to' of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.CAUSE, PointerUtils.INFINITY, needSense, needGloss,
                                    needLex, needOffset, needSenseNum, needSenseKeys);
                        }
                    } //caus

                    if (arg.startsWith("-pert") && 6 == arg.length()) {
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nPertainyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.PERTAINYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //pert

                    if (arg.startsWith("-attr") && 6 == arg.length()) {
                        POS p = POS.getPOSForKey(arg.substring(5));
                        if (needHelp) {
                            if (POS.NOUN == p) {
                                System.out
                                        .println("Display adjectives for which search string is an attribute.");
                            }
                            if (POS.ADJECTIVE == p) {
                                System.out.println("Display nouns that are attributes of search string.");
                            }
                        }
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nAttributes of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.ATTRIBUTE, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //attr

                    if (arg.startsWith("-deri") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Display derived forms - nouns and verbs that are related morphologically.\n"
                                            + "Each related synset is preceeded by its part of speech. Each word in the\n"
                                            + "synset is followed by its sense number.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nDerived forms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.NOMINALIZATION, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //deri

                    if (arg.startsWith("-domn") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display domain to which this synset belongs.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nDomain of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.CATEGORY, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.USAGE, 1, needSense, needGloss, needLex, needOffset,
                                    needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.REGION, 1, needSense, needGloss, needLex, needOffset,
                                    needSenseNum, needSenseKeys);
                        }
                    } //domn

                    if (arg.startsWith("-domt") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all synsets belonging to the domain.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nDomain of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.CATEGORY_MEMBER, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.USAGE_MEMBER, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.REGION_MEMBER, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //domt

                    if (arg.startsWith("-faml") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Display familiarity and polysemy information for the search string.\n"
                                            + "The polysemy count is the number of senses in WordNet.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            String[] freqs = { "extremely rare", "very rare", "rare", "uncommon", "common",
                                    "familiar", "very familiar", "extremely familiar" };
                            String[] pos = { "a noun", "a verb", "an adjective", "an adverb" };
                            int cnt = iw.getSenses().size();
                            int familiar = 0;
                            if (cnt == 0) {
                                familiar = 0;
                            }
                            if (cnt == 1) {
                                familiar = 1;
                            }
                            if (cnt == 2) {
                                familiar = 2;
                            }
                            if (cnt >= 3 && cnt <= 4) {
                                familiar = 3;
                            }
                            if (cnt >= 5 && cnt <= 8) {
                                familiar = 4;
                            }
                            if (cnt >= 9 && cnt <= 16) {
                                familiar = 5;
                            }
                            if (cnt >= 17 && cnt <= 32) {
                                familiar = 6;
                            }
                            if (cnt > 32) {
                                familiar = 7;
                            }
                            System.out.println("\n" + iw.getLemma() + " used as " + pos[p.getId() - 1] + " is "
                                    + freqs[familiar] + " (polysemy count = " + cnt + ")");
                        }
                    } //faml

                    if (arg.startsWith("-fram") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Display applicable verb sentence frames for the search string.\n" + "\n"
                                            + "A frame is a sentence template illustrating the usage of a verb.\n"
                                            + "\n"
                                            + "Verb sentence frames are preceded with the string \"*>\" if a sentence\n"
                                            + "frame is acceptable for all of the words in the synset, and with \"=>\"\n"
                                            + "if a sentence frame is acceptable for the search string only.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nVerb frames of " + p.getLabel() + " " + iw.getLemma());
                            for (int i = 0; i < iw.getSenses().size(); i++) {
                                Synset synset = iw.getSenses().get(i);
                                for (String vf : synset.getVerbFrames()) {
                                    System.out.println("\t*> " + vf);
                                }
                                for (Word word : synset.getWords()) {
                                    if (iw.getLemma().equalsIgnoreCase(word.getLemma())) {
                                        if (word instanceof Verb) {
                                            Verb verb = (Verb) word;
                                            for (String vf : verb.getVerbFrames()) {
                                                System.out.println("\t=> " + vf);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } //fram

                    if (arg.startsWith("-hmer") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "Display meronyms for search string tree.  This is a recursive search\n"
                                            + "the prints all the meronyms of the search string and all of its\n"
                                            + "hypernyms. \n" + "\n"
                                            + "A meronym is the name of a constituent part, the substance of, or a\n"
                                            + "member of something.  X is a meronym of Y if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nMeronyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.MEMBER_MERONYM, PointerUtils.INFINITY, needSense,
                                    needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.SUBSTANCE_MERONYM, PointerUtils.INFINITY, needSense,
                                    needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.PART_MERONYM, PointerUtils.INFINITY, needSense,
                                    needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                        }
                    } //hmer

                    if (arg.startsWith("-hhol") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println(
                                    "\"Display holonyms for search string tree.  This is a recursive search\n"
                                            + "that prints all the holonyms of the search string and all of the\n"
                                            + "holonym's holonyms.\n" + "\n"
                                            + "A holonym is the name of the whole of which the meronym names a part.\n"
                                            + "Y is a holonym of X if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nHolonyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.MEMBER_HOLONYM, PointerUtils.INFINITY, needSense,
                                    needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.SUBSTANCE_HOLONYM, PointerUtils.INFINITY, needSense,
                                    needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.PART_HOLONYM, PointerUtils.INFINITY, needSense,
                                    needGloss, needLex, needOffset, needSenseNum, needSenseKeys);
                        }
                    } //hhol

                    if (arg.startsWith("-mero") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out.println("Display all meronyms of the search string. \n" + "\n"
                                    + "A meronym is the name of a constituent part, the substance of, or a\n"
                                    + "member of something.  X is a meronym of Y if X is a part of Y.\n" + "\n"
                                    + "A holonym is the name of the whole of which the meronym names a part.\n"
                                    + "Y is a holonym of X if X is a part of Y.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        IndexWord iw = d.lookupIndexWord(p, key);
                        if (null != iw) {
                            System.out.println("\nMeronyms of " + p.getLabel() + " " + iw.getLemma());
                            tracePointers(iw, PointerType.MEMBER_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.SUBSTANCE_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                            tracePointers(iw, PointerType.PART_MERONYM, 1, needSense, needGloss, needLex,
                                    needOffset, needSenseNum, needSenseKeys);
                        }
                    } //mero

                    if (arg.startsWith("-grep") && 6 == arg.length()) {
                        if (needHelp) {
                            System.out
                                    .println("Print all strings in the database containing the search string\n"
                                            + "as an individual word, or as the first or last string in a word or\n"
                                            + "collocation.");
                        }
                        POS p = POS.getPOSForKey(arg.substring(5));
                        System.out.println("\nGrep of " + p.getLabel() + " " + key);
                        Iterator<IndexWord> ii = d.getIndexWordIterator(p, key);
                        while (ii.hasNext()) {
                            System.out.println(ii.next().getLemma());
                        }
                    } //grep

                    if ("-over".equals(arg)) {
                        for (POS pos : POS.getAllPOS()) {
                            if (null != d.getMorphologicalProcessor()) {
                                IndexWord iw = d.getIndexWord(pos, key);
                                //for plurals like species, glasses
                                if (null != iw && key.equals(iw.getLemma())) {
                                    printOverview(pos, iw, needGloss, needLex, needOffset, needSenseNum,
                                            needSenseKeys);
                                }

                                List<String> forms = d.getMorphologicalProcessor().lookupAllBaseForms(pos, key);
                                if (null != forms) {
                                    for (String form : forms) {
                                        if (!form.equals(key)) {
                                            iw = d.getIndexWord(pos, form);
                                            if (null != iw) {
                                                printOverview(pos, iw, needGloss, needLex, needOffset,
                                                        needSenseNum, needSenseKeys);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } //over
                }
            }
        }
    }
}

From source file:eu.fbk.dh.tint.tokenizer.ItalianTokenizer.java

public static void main(String argv[]) throws IOException {

        ItalianTokenizer tokenizer = new ItalianTokenizer();

        //        byte[] file = Files.readAllBytes((new File("/Users/alessio/Desktop/milano.txt")).toPath());
        //        String text = new String(file);
        String text = "Clinton in testa nei sondaggi dopo lassoluzione dellFbi sulluso di un server di posta privato quando era Segretario di stato.";
        //        text = "``Determinato, pronto a fare tutto il necessario per mantenere la stabilit dei prezzi.''"
        //                + " Ma anche allarmato per come le conseguenze del referendum britannico minacciano leconomia e i mercati europei."
        //                + " Sono nato nel 200 S.p.A."
        //                + " Il mio indirizzo e-mail  alessio@apnetwork.it."
        //                + " Il blog  http://www.ziorufus.it e mi piace molto.";
        //        text = "Questo  un test per una sigla qualsiasi tipo a.B.C. che non ha senso.";
        //        text = "Milano (/milano/ ascolta[?info], in milanese: Milan[4], /mil?/[5])  una citt italiana di 1 346 153 abitanti[2], capoluogo dell'omonima citt metropolitana e della regione Lombardia, secondo comune italiano per numero di abitanti, tredicesimo comune dell'Unione europea e diciannovesimo del continente e, con l'agglomerato urbano, quarta area metropolitana pi popolata d'Europa dopo Londra, Madrid e Parigi[6].\n"
        //                + "\n"
        //                + "Fondata dagli Insubri all'inizio del VI secolo a.C.[7], fu conquistata dai Romani nel 222 a.C.";

        //        System.out.println(text);

        long time = System.currentTimeMillis();
        List<List<CoreLabel>> sentences = tokenizer.parse(text);
        time = System.currentTimeMillis() - time;

        for (int i = 0; i < Math.min(10, sentences.size()); i++) {
            List<CoreLabel> sentence = sentences.get(i);
            for (CoreLabel token : sentence) {
                System.out.println(token.word() + " -- " + token.originalText() + " -- " + token.beginPosition());

            }//from ww  w .j  ava2 s. c o  m
            System.out.println();
        }

        int sentenceSize = sentences.size();
        int lastTokenIndex = sentences.get(sentenceSize - 1).get(sentences.get(sentenceSize - 1).size() - 1)
                .index();
        System.out.println("Length: " + text.length());
        System.out.println("Time: " + time);
        System.out.println("Sentences: " + sentenceSize);
        System.out.println("Tokens: " + lastTokenIndex);
    }

From source file:GoogleImages.java

public static void main(String[] args) throws InterruptedException {
    String searchTerm = "s woman"; // term to search for (use spaces to separate terms)
    int offset = 40; // we can only 20 results at a time - use this to offset and get more!
    String fileSize = "50mp"; // specify file size in mexapixels (S/M/L not figured out yet)
    String source = null; // string to save raw HTML source code

    // format spaces in URL to avoid problems
    searchTerm = searchTerm.replaceAll(" ", "%20");

    // get Google image search HTML source code; mostly built from PhyloWidget example:
    // http://code.google.com/p/phylowidget/source/browse/trunk/PhyloWidget/src/org/phylowidget/render/images/ImageSearcher.java
    int offset2 = 0;
    Set urlsss = new HashSet<String>();
    while (offset2 < 600) {
        try {/*from   w w  w .ja  v a2 s .c  o  m*/
            URL query = new URL("https://www.google.ru/search?start=" + offset2
                    + "&q=angry+woman&newwindow=1&client=opera&hs=bPE&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiAgcKozIfNAhWoHJoKHSb_AUoQ_AUIBygB&biw=1517&bih=731&dpr=0.9#imgrc=G_1tH3YOPcc8KM%3A");
            HttpURLConnection urlc = (HttpURLConnection) query.openConnection(); // start connection...
            urlc.setInstanceFollowRedirects(true);
            urlc.setRequestProperty("User-Agent", "");
            urlc.connect();
            BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream())); // stream in HTTP source to file
            StringBuffer response = new StringBuffer();
            char[] buffer = new char[1024];
            while (true) {
                int charsRead = in.read(buffer);
                if (charsRead == -1) {
                    break;
                }
                response.append(buffer, 0, charsRead);
            }
            in.close(); // close input stream (also closes network connection)
            source = response.toString();
        } // any problems connecting? let us know
        catch (Exception e) {
            e.printStackTrace();
        }

        // print full source code (for debugging)
        // println(source);
        // extract image URLs only, starting with 'imgurl'
        if (source != null) {
            //                System.out.println(source);
            int c = StringUtils.countMatches(source, "http://www.vmir.su");
            System.out.println(c);
            int index = source.indexOf("src=");
            System.out.println(source.subSequence(index, index + 200));
            while (index >= 0) {
                System.out.println(index);
                index = source.indexOf("src=", index + 1);
                if (index == -1) {
                    break;
                }
                String rr = source.substring(index,
                        index + 200 > source.length() ? source.length() : index + 200);

                if (rr.contains("\"")) {
                    rr = rr.substring(5, rr.indexOf("\"", 5));
                }
                System.out.println(rr);
                urlsss.add(rr);
            }
        }
        offset2 += 20;
        Thread.sleep(1000);
        System.out.println("off set = " + offset2);

    }

    System.out.println(urlsss);
    urlsss.forEach(new Consumer<String>() {

        public void accept(String s) {
            try {
                saveImage(s, "C:\\Users\\Java\\Desktop\\ang\\" + UUID.randomUUID().toString() + ".jpg");
            } catch (IOException ex) {
                Logger.getLogger(GoogleImages.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    //            String[][] m = matchAll(source, "img height=\"\\d+\" src=\"([^\"]+)\"");

    // older regex, no longer working but left for posterity
    // built partially from: http://www.mkyong.com/regular-expressions/how-to-validate-image-file-extension-with-regular-expression
    // String[][] m = matchAll(source, "imgurl=(.*?\\.(?i)(jpg|jpeg|png|gif|bmp|tif|tiff))");    // (?i) means case-insensitive
    //            for (int i = 0; i < m.length; i++) {                                                          // iterate all results of the match
    //                println(i + ":\t" + m[i][1]);                                                         // print (or store them)**
    //            }
}

From source file:com.mycompany.myelasticsearch.MainClass.java

/**
 * @param args the command line arguments
 */// w w w .j a v  a 2  s . c  om
public static void main(String[] args) {

    // TODO code application logic here
    Tika tika = new Tika();
    String fileEntry = "C:\\Contract\\Contract1.pdf";
    String filetype = tika.detect(fileEntry);
    System.out.println("FileType " + filetype);
    BodyContentHandler handler = new BodyContentHandler(-1);
    String text = "";
    Metadata metadata = new Metadata();

    FileInputStream inputstream = null;

    try {
        inputstream = new FileInputStream(fileEntry);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    ParseContext pcontext = new ParseContext();

    //parsing the document using PDF parser
    PDFParser pdfparser = new PDFParser();
    try {
        pdfparser.parse(inputstream, handler, metadata, pcontext);
    } catch (IOException ex) {

        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TikaException ex) {
        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    String docText = "";
    String outputArray[];
    String out[];
    //getting the content of the document
    docText = handler.toString().replaceAll("(/[^\\da-zA-Z.]/)", "");

    // PhraseDetection.getPhrases(docText);
    try {
        Node node = nodeBuilder().node();
        Client client = node.client();
        DocumentReader.parseString(docText, client);
        //"Borrowing should be replaced by the user input key"
        Elastic.getDefinedTerm(client, "definedterms", "term", "1", "Borrowing");
        node.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    Stanford.getSentence(docText);

    int definedTermsEnd = docText.indexOf("SCHEDULES");
    String toc = docText.substring(0, definedTermsEnd);
    String c = docText.substring(definedTermsEnd);

    System.out.println("Table of content" + toc);
    System.out.println("--------------------------------");
    System.out.println("content" + c);

    out = toc.split("Article|article|ARTICLE");
    int count = 0;
    String outputArrayString = "";
    int s = 0;
    StringBuffer tocOutput = new StringBuffer();

    for (String o : out) {
        if (count != 0) {
            s = Integer.parseInt(String.valueOf(o.charAt(1)));
            if (s == count) {
                tocOutput.append(o);
                tocOutput.append("JigarAnkitNeeraj");
                System.out.println(s);
            }
        }
        outputArrayString += "Count" + count + o;
        count++;
        System.out.println();
    }
    System.out.println("---------------------------------------------------Content---------");
    count = 1;
    StringBuffer contentOutput = new StringBuffer();

    String splitContent[] = c.split("ARTICLE|Article");
    Node node = nodeBuilder().node();
    Client client = node.client();
    for (String o : splitContent) {
        o = o.replaceAll("[^a-zA-Z0-9.,\\/#!$%\\^&\\*;:{}=\\-_`~()?\\s]+", "");
        o = o.replaceAll("\n", " ");
        char input = o.charAt(1);
        if (input >= '0' && input <= '9') {
            s = Integer.parseInt(String.valueOf(o.charAt(1)));
            if (s == count) {
                //System.out.println(s);
                JSONObject articleJSONObject = new JSONObject();
                contentOutput.append(" \n MyArticlesSeparated \n ");
                articleJSONObject.put("Article" + count, o.toString());
                try {
                    try {
                        JSONObject articleJSONObject1 = new JSONObject();
                        articleJSONObject1.put("hi", "j");
                        client.prepareIndex("contract", "article", String.valueOf(count))
                                .setSource(articleJSONObject.toString()).execute().actionGet();
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    //"Borrowing should be replaced by the user input key"

                } catch (Exception ex) {
                    Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
                }
                System.out.println(s);
                count++;
            }
            //outputArrayString += "Count" + count + o;

            contentOutput.append(o);
        }
    }
    Elastic.getDocument(client, "contract", "article", "1");
    Elastic.searchDocument(client, "contract", "article", "Lenders");
    Elastic.searchDocument(client, "contract", "article", "Negative Covenants");

    Elastic.searchDocument(client, "contract", "article", "Change in Law");
    String tableOfContent[];
    tableOfContent = tocOutput.toString().split("JigarAnkitNeeraj");

    String splitContectsAccordingToArticles[];
    splitContectsAccordingToArticles = contentOutput.toString().split("MyArticlesSeparated");
    int numberOfArticle = splitContectsAccordingToArticles.length;

    int countArticle = 1;
    Double toBeTruncated = new Double("" + countArticle + ".00");

    String section = "Section";
    toBeTruncated += 0.01;

    System.out.println(toBeTruncated);
    String sectionEnd;
    StringBuffer sectionOutput = new StringBuffer();
    int skipFirstArtcile = 0;
    JSONObject obj = new JSONObject();

    for (String article : splitContectsAccordingToArticles) {
        if (skipFirstArtcile != 0) {
            DecimalFormat f = new DecimalFormat("##.00");
            String sectionStart = section + " " + f.format(toBeTruncated);
            int start = article.indexOf(sectionStart);
            toBeTruncated += 0.01;

            System.out.println();
            sectionEnd = section + " " + f.format(toBeTruncated);

            int end = article.indexOf(sectionEnd);
            while (end != -1) {
                sectionStart = section + " " + f.format(toBeTruncated - 0.01);
                sectionOutput.append(" \n Key:" + sectionStart);
                if (start < end) {
                    sectionOutput.append("\n Value:" + article.substring(start, end));
                    obj.put(sectionStart, article.substring(start, end).replaceAll("\\r\\n|\\r|\\n", " "));
                    try {
                        try {
                            JSONObject articleJSONObject1 = new JSONObject();
                            articleJSONObject1.put("hi", "j");
                            client.prepareIndex("contract", "section", String.valueOf(count))
                                    .setSource(obj.toString()).execute().actionGet();
                        } catch (Exception e) {
                            System.out.println(e.getMessage());
                        }
                        //"Borrowing should be replaced by the user input key"

                    } catch (Exception ex) {
                        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }

                start = end;
                toBeTruncated += 0.01;
                sectionEnd = section + " " + f.format(toBeTruncated);
                System.out.println("SectionEnd " + sectionEnd);
                try {
                    end = article.indexOf(sectionEnd);
                } catch (Exception e) {
                    System.out.print(e.getMessage());
                }

                System.out.println("End section index " + end);
            }
            end = article.length() - 1;
            sectionOutput.append(" \n Key:" + sectionStart);
            try {
                sectionOutput.append(" \n Value:" + article.substring(start, end));
                obj.put(sectionStart, article.substring(start, end).replaceAll("\\r\\n|\\r|\\n", " "));
            } catch (Exception e) {
                //What if Article has No Sections
                String numberOnly = article.replaceAll("[^0-9]", "").substring(0, 1);
                String sectionArticle = "ARTICLE " + numberOnly;
                sectionOutput.append(" \n Value:" + article);
                obj.put(sectionArticle, article);

                System.out.println(e.getMessage());
            }

            DecimalFormat ff = new DecimalFormat("##");
            toBeTruncated = Double.valueOf(ff.format(toBeTruncated)) + 1.01;
        }
        skipFirstArtcile++;
    }

    for (String article : splitContectsAccordingToArticles) {
        if (skipFirstArtcile != 0) {
            DecimalFormat f = new DecimalFormat("##.00");
            String sectionStart = section + " " + f.format(toBeTruncated);
            int start = article.indexOf(sectionStart);
            toBeTruncated += 0.01;
            System.out.println();
            sectionEnd = section + " " + f.format(toBeTruncated);

            int end = article.indexOf(sectionEnd);
            while (end != -1) {
                sectionStart = section + " " + f.format(toBeTruncated - 0.01);
                sectionOutput.append(" \n Key:" + sectionStart);
                if (start < end) {
                    sectionOutput.append("\n Value:" + article.substring(start, end));
                    System.out.println(sectionOutput);
                    String patternStr = "\\n\\n+[(]";
                    String paragraphSubstringArray[] = article.substring(start, end).split(patternStr);

                    JSONObject paragraphObject = new JSONObject();
                    int counter = 0;
                    for (String paragraphSubstring : paragraphSubstringArray) {
                        counter++;
                        paragraphObject.put("Paragraph " + counter, paragraphSubstring);

                    }
                    obj.put(sectionStart, paragraphObject);

                }

                start = end;
                toBeTruncated += 0.01;
                sectionEnd = section + " " + f.format(toBeTruncated);
                System.out.println("SectionEnd " + sectionEnd);
                try {
                    end = article.indexOf(sectionEnd);
                } catch (Exception e) {
                    System.out.print(e.getMessage());
                }

                System.out.println("End section index " + end);
            }
            end = article.length() - 1;
            sectionOutput.append(" \n Key:" + sectionStart);
            try {
                sectionOutput.append(" \n Value:" + article.substring(start, end));
                obj.put(sectionStart, article.substring(start, end));
                PhraseDetection.getPhrases(docText);
            } catch (Exception e) {
                //What if Article has No Sections
                String sectionArticle = "ARTICLE";
                System.out.println(e.getMessage());
            }
            DecimalFormat ff = new DecimalFormat("##");
            toBeTruncated = Double.valueOf(ff.format(toBeTruncated)) + 1.01;
        }
        skipFirstArtcile++;
    }

    Elastic.getDocument(client, "contract", "section", "1");
    Elastic.searchDocument(client, "contract", "section", "Lenders");
    Elastic.searchDocument(client, "contract", "section", "Negative Covenants");
    try {
        FileWriter file = new FileWriter("TableOfIndex.txt");
        file.write(tocOutput.toString());
        file.flush();
        file.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        FileWriter file = new FileWriter("Contract3_JSONFile.txt");
        file.write(obj.toString());
        file.flush();
        file.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        FileWriter file = new FileWriter("Contract1_KeyValueSections.txt");
        file.write(sectionOutput.toString());
        file.flush();
        file.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}