Example usage for org.apache.commons.io FileUtils readLines

List of usage examples for org.apache.commons.io FileUtils readLines

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils readLines.

Prototype

public static List readLines(File file) throws IOException 

Source Link

Document

Reads the contents of a file line by line to a List of Strings using the default encoding for the VM.

Usage

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step2FillWithRetrievedResults.java

public static void main(String[] args) throws IOException {
    // input dir - list of xml query containers
    File inputDir = new File(args[0]);

    // retrieved results from Technion
    // ltr-50queries-100docs.txt
    File ltr = new File(args[1]);

    // output dir
    File outputDir = new File(args[2]);
    if (!outputDir.exists()) {
        outputDir.mkdirs();//from ww  w  .j  a  v  a  2s.c o  m
    }

    // load the query containers first (into map: id + container)
    Map<String, QueryResultContainer> queryResults = new HashMap<>();
    for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) {
        System.out.println(f);
        QueryResultContainer queryResultContainer = QueryResultContainer
                .fromXML(FileUtils.readFileToString(f, "utf-8"));
        queryResults.put(queryResultContainer.qID, queryResultContainer);
    }

    // iterate over IR results
    for (String line : FileUtils.readLines(ltr)) {
        String[] split = line.split("\\s+");
        Integer origQueryId = Integer.valueOf(split[0]);
        String clueWebID = split[2];
        Integer rank = Integer.valueOf(split[3]);
        double score = Double.valueOf(split[4]);
        String additionalInfo = split[5];

        // get the container for this result
        QueryResultContainer container = queryResults.get(origQueryId.toString());

        if (container != null) {
            // add new result
            QueryResultContainer.SingleRankedResult result = new QueryResultContainer.SingleRankedResult();
            result.clueWebID = clueWebID;
            result.rank = rank;
            result.score = score;
            result.additionalInfo = additionalInfo;

            if (container.rankedResults == null) {
                container.rankedResults = new ArrayList<>();
            }
            container.rankedResults.add(result);
        }
    }

    // save all containers to the output dir
    for (QueryResultContainer queryResultContainer : queryResults.values()) {
        File outputFile = new File(outputDir, queryResultContainer.qID + ".xml");
        FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8");
        System.out.println("Finished " + outputFile);
    }
}

From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.IncomingLogGenerator.java

/**
 * @param args//from   www.ja va2 s.c om
 */
public static void main(String[] args) {
    System.out.println("Have started IncomingSMSGenerator.");
    File outFile = new File("/tmp/logs/incomingSMS.csv");
    RandomDataGenerator randomDataImpl = new RandomDataGenerator();

    String randomStrFile = "/tmp/random.txt";

    List<String> randomStrings = new ArrayList<>();
    int randStrLength = 0;

    long startDate = 1412380800; // Unix time in seconds for Oct 4 2014
    long stopDate = 1420070340; // Unix time for in seconds Dec 31 2014

    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2011-06-01 00:16:45" 

    List<String> shortcodeUuids = new ArrayList<>();
    shortcodeUuids.add("094def52-bc18-4a9e-9b84-c34cc6476c75");
    shortcodeUuids.add("e9570c5d-0cc4-41e5-81df-b0674e9dda1e");
    shortcodeUuids.add("a118c8ea-f831-4288-986d-35e22c91fc4d");
    shortcodeUuids.add("a2688d72-291b-470c-8926-31a903f5ed0c");
    shortcodeUuids.add("9bef62f6-e682-4efd-98e9-ca41fa4ef993");

    int shortcodeCount = shortcodeUuids.size() - 1;

    try {
        randomStrings = FileUtils.readLines(new File(randomStrFile));
        randStrLength = randomStrings.size();

        for (int j = 0; j < 30000; j++) {
            FileUtils.write(outFile,
                    // shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"   // Destination 
                    UUID.randomUUID().toString() + "|" // Unique Code
                            + randomDataImpl.nextLong(new Long("254700000000").longValue(),
                                    new Long("254734999999").longValue())
                            + "|" // Origin
                            + shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"
                            + randomStrings.get(randomDataImpl.nextInt(0, randStrLength - 1)) + "|" // Message
                            + "N|" // deleted
                            + dateFormatter.format(
                                    new Date(randomDataImpl.nextLong(startDate, stopDate) * 1000))
                            + "\n", // smsTime                  
                    true); // Append to file                              
        }

    } catch (IOException e) {
        System.err.println("IOException in main.");
        e.printStackTrace();
    }

    System.out.println("Have finished IncomingSMSGenerator.");
}

From source file:com.impetus.ankush.agent.daemon.AnkushAgent.java

/**
 * The main method.//from  www  .j  av  a 2  s .c o  m
 * 
 * @param args
 *            the arguments
 */
public static void main(String[] args) {

    // taskable file name.
    String file = System.getProperty(Constant.AGENT_INSTALL_DIR) + "/.ankush/agent/conf/taskable.conf";

    // iterate always

    try {
        // reading the class name lines from the file
        List<String> classNames = FileUtils.readLines(new File(file));
        // iterate over the class names to start the newly added task.
        for (String className : classNames) {
            // if an empty string from the file then continue the loop.
            if (className.isEmpty()) {
                continue;
            }
            // if not started.
            if (!objMap.containsKey(className)) {
                // create taskable object
                LOGGER.info("Creating " + className + " object.");

                try {
                    Taskable taskable = ActionFactory.getTaskableObject(className);
                    objMap.put(className, taskable);
                    // call start on object ...
                    taskable.start();
                } catch (Exception e) {
                    LOGGER.error("Could not start the " + className + " taskable.");
                }
            }
        }

        // iterating over the existing tasks to stop if it is removed
        // from the file.
        Set<String> existingClassNames = new HashSet<String>(objMap.keySet());
        for (String className : existingClassNames) {
            // if not started.
            if (!classNames.contains(className)) {
                // create taskable object

                LOGGER.info("Removing " + className + " object.");

                Taskable taskable = objMap.get(className);
                objMap.remove(className);
                // call stop on object ...
                taskable.stop();
            }
        }

    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

    while (true) {
        try {
            Thread.sleep(TASK_SEARCH_SLEEP_TIME);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}

From source file:edu.gslis.ts.RunQuery.java

public static void main(String[] args) {
    try {//from   www  .j av a 2 s  .co m
        // Get the commandline options
        Options options = createOptions();
        CommandLineParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        String inputPath = cmd.getOptionValue("input");
        String eventsPath = cmd.getOptionValue("events");
        String stopPath = cmd.getOptionValue("stop");
        int queryId = Integer.valueOf(cmd.getOptionValue("query"));

        List<String> ids = FileUtils.readLines(new File(inputPath + File.separator + "ids.txt"));

        Stopper stopper = new Stopper(stopPath);
        Map<Integer, FeatureVector> queries = readEvents(eventsPath, stopper);

        FeatureVector query = queries.get(queryId);

        Pairtree ptree = new Pairtree();
        Bag<String> words = new HashBag<String>();

        for (String streamId : ids) {

            String ppath = ptree.mapToPPath(streamId.replace("-", ""));

            String inpath = inputPath + File.separator + ppath + File.separator + streamId + ".xz";
            //                System.out.println(inpath);
            File infile = new File(inpath);
            InputStream in = new XZInputStream(new FileInputStream(infile));

            TTransport inTransport = new TIOStreamTransport(new BufferedInputStream(in));
            TBinaryProtocol inProtocol = new TBinaryProtocol(inTransport);
            inTransport.open();
            final StreamItem item = new StreamItem();

            while (true) {
                try {
                    item.read(inProtocol);
                    //                        System.out.println("Read " + item.stream_id);

                } catch (TTransportException tte) {
                    // END_OF_FILE is used to indicate EOF and is not an exception.
                    if (tte.getType() != TTransportException.END_OF_FILE)
                        tte.printStackTrace();
                    break;
                }
            }

            // Do something with this document...
            String docText = item.getBody().getClean_visible();

            StringTokenizer itr = new StringTokenizer(docText);
            while (itr.hasMoreTokens()) {
                words.add(itr.nextToken());
            }

            inTransport.close();

        }

        for (String term : words.uniqueSet()) {
            System.out.println(term + ":" + words.getCount(term));
        }

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

From source file:edu.cmu.lti.oaqa.annographix.apps.SolrQueryApp.java

public static void main(String[] args) {
    Options options = new Options();

    options.addOption("u", null, true, "Solr URI");
    options.addOption("q", null, true, "Query");
    options.addOption("n", null, true, "Max # of results");
    options.addOption("o", null, true, "An optional TREC-style output file");
    options.addOption("w", null, false, "Do a warm-up query call, before each query");

    CommandLineParser parser = new org.apache.commons.cli.GnuParser();

    BufferedWriter trecOutFile = null;

    try {/*from  ww w.j a v a  2s.c  o  m*/
        CommandLine cmd = parser.parse(options, args);
        String queryFile = null, solrURI = null;

        if (cmd.hasOption("u")) {
            solrURI = cmd.getOptionValue("u");
        } else {
            Usage("Specify Solr URI");
        }

        SolrServerWrapper solr = new SolrServerWrapper(solrURI);

        if (cmd.hasOption("q")) {
            queryFile = cmd.getOptionValue("q");
        } else {
            Usage("Specify Query file");
        }

        int numRet = 100;

        if (cmd.hasOption("n")) {
            numRet = Integer.parseInt(cmd.getOptionValue("n"));
        }

        if (cmd.hasOption("o")) {
            trecOutFile = new BufferedWriter(new FileWriter(new File(cmd.getOptionValue("o"))));
        }

        List<String> fieldList = new ArrayList<String>();
        fieldList.add(UtilConst.ID_FIELD);
        fieldList.add(UtilConst.SCORE_FIELD);

        double totalTime = 0;
        double retQty = 0;

        ArrayList<Double> queryTimes = new ArrayList<Double>();

        boolean bDoWarmUp = cmd.hasOption("w");

        if (bDoWarmUp) {
            System.out.println("Using a warmup step!");
        }

        int queryQty = 0;
        for (String t : FileUtils.readLines(new File(queryFile))) {
            t = t.trim();
            if (t.isEmpty())
                continue;
            int ind = t.indexOf('|');
            if (ind < 0)
                throw new Exception("Wrong format, line: '" + t + "'");
            String qID = t.substring(0, ind);
            String q = t.substring(ind + 1);

            SolrDocumentList res = null;

            if (bDoWarmUp) {
                res = solr.runQuery(q, fieldList, numRet);
            }

            Long tm1 = System.currentTimeMillis();
            res = solr.runQuery(q, fieldList, numRet);
            Long tm2 = System.currentTimeMillis();
            retQty += res.getNumFound();
            System.out.println(qID + " Obtained: " + res.getNumFound() + " entries in " + (tm2 - tm1) + " ms");
            double delta = (tm2 - tm1);
            totalTime += delta;
            queryTimes.add(delta);
            ++queryQty;

            if (trecOutFile != null) {

                ArrayList<SolrRes> resArr = new ArrayList<SolrRes>();
                for (SolrDocument doc : res) {
                    String id = (String) doc.getFieldValue(UtilConst.ID_FIELD);
                    float score = (Float) doc.getFieldValue(UtilConst.SCORE_FIELD);
                    resArr.add(new SolrRes(id, "", score));
                }
                SolrRes[] results = resArr.toArray(new SolrRes[resArr.size()]);
                Arrays.sort(results);

                SolrEvalUtils.saveTrecResults(qID, results, trecOutFile, TREC_RUN, results.length);
            }
        }
        double devTime = 0, meanTime = totalTime / queryQty;
        for (int i = 0; i < queryQty; ++i) {
            double d = queryTimes.get(i) - meanTime;
            devTime += d * d;
        }
        devTime = Math.sqrt(devTime / (queryQty - 1));
        System.out.println(String.format("Query time, mean/standard dev: %.2f/%.2f (ms)", meanTime, devTime));
        System.out.println(String.format("Avg # of docs returned: %.2f", retQty / queryQty));

        solr.close();
        trecOutFile.close();
    } catch (ParseException e) {
        Usage("Cannot parse arguments");
    } catch (Exception e) {
        System.err.println("Terminating due to an exception: " + e);
        System.exit(1);
    }

}

From source file:jk.kamoru.test.IMAPMail.java

public static void main(String[] args) {
    /*        if (args.length < 3)
            {/*  ww w.  ja va2  s . c  o m*/
    System.err.println(
        "Usage: IMAPMail <imap server hostname> <username> <password> [TLS]");
    System.exit(1);
            }
    */
    String server = "imap.handysoft.co.kr";
    String username = "namjk24@handysoft.co.kr";
    String password = "22222";

    String proto = (args.length > 3) ? args[3] : null;

    IMAPClient imap;

    if (proto != null) {
        System.out.println("Using secure protocol: " + proto);
        imap = new IMAPSClient(proto, true); // implicit
        // enable the next line to only check if the server certificate has expired (does not check chain):
        //            ((IMAPSClient) imap).setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager());
        // OR enable the next line if the server uses a self-signed certificate (no checks)
        //            ((IMAPSClient) imap).setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
    } else {
        imap = new IMAPClient();
    }
    System.out.println("Connecting to server " + server + " on " + imap.getDefaultPort());

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

    File imap_log_file = new File("IMAMP-UNSEEN");
    try {
        System.out.println(imap_log_file.getAbsolutePath());
        PrintStream ps = new PrintStream(imap_log_file);
        // suppress login details
        imap.addProtocolCommandListener(new PrintCommandListener(ps, true));
    } catch (FileNotFoundException e1) {
        imap.addProtocolCommandListener(new PrintCommandListener(System.out, true));
    }

    try {
        imap.connect(server);
    } catch (IOException e) {
        throw new RuntimeException("Could not connect to server.", e);
    }

    try {
        if (!imap.login(username, password)) {
            System.err.println("Could not login to server. Check password.");
            imap.disconnect();
            System.exit(3);
        }

        imap.setSoTimeout(6000);

        //            imap.capability();

        //            imap.select("inbox");

        //            imap.examine("inbox");

        imap.status("inbox", new String[] { "UNSEEN" });

        //            imap.logout();
        imap.disconnect();

        List<String> imap_log = FileUtils.readLines(imap_log_file);
        for (int i = 0; i < imap_log.size(); i++) {
            System.out.println(i + ":" + imap_log.get(i));
        }
        String unseenText = imap_log.get(4);
        unseenText = unseenText.substring(unseenText.indexOf('(') + 1, unseenText.indexOf(')'));
        int unseenCount = Integer.parseInt(unseenText.split(" ")[1]);

        System.out.println(unseenCount);
        //imap_log.indexOf("UNSEEN ")
    } catch (IOException e) {
        System.out.println(imap.getReplyString());
        e.printStackTrace();
        System.exit(10);
        return;
    }
}

From source file:com.edduarte.protbox.Protbox.java

public static void main(String... args) {

    // activate debug / verbose mode
    if (args.length != 0) {
        List<String> argsList = Arrays.asList(args);
        if (argsList.contains("-v")) {
            Constants.verbose = true;/*from   w  w  w . j  av  a 2  s . c  o  m*/
        }
    }

    // use System's look and feel
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
        // If the System's look and feel is not obtainable, continue execution with JRE look and feel
    }

    // check this is a single instance
    try {
        new ServerSocket(1882);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null,
                "Another instance of Protbox is already running.\n" + "Please close the other instance first.",
                "Protbox already running", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    // check if System Tray is supported by this operative system
    if (!SystemTray.isSupported()) {
        JOptionPane.showMessageDialog(null,
                "Your operative system does not support system tray functionality.\n"
                        + "Please try running Protbox on another operative system.",
                "System tray not supported", JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    // add PKCS11 providers
    FileFilter fileFilter = new AndFileFilter(new WildcardFileFilter(Lists.newArrayList("*.config")),
            HiddenFileFilter.VISIBLE);

    File[] providersConfigFiles = new File(Constants.PROVIDERS_DIR).listFiles(fileFilter);

    if (providersConfigFiles != null) {
        for (File f : providersConfigFiles) {
            try {
                List<String> lines = FileUtils.readLines(f);
                String aliasLine = lines.stream().filter(line -> line.contains("alias")).findFirst().get();
                lines.remove(aliasLine);
                String alias = aliasLine.split("=")[1].trim();

                StringBuilder sb = new StringBuilder();
                for (String s : lines) {
                    sb.append(s);
                    sb.append("\n");
                }

                Provider p = new SunPKCS11(new ReaderInputStream(new StringReader(sb.toString())));
                Security.addProvider(p);

                pkcs11Providers.put(p.getName(), alias);

            } catch (IOException | ProviderException ex) {
                if (ex.getMessage().equals("Initialization failed")) {
                    ex.printStackTrace();

                    String s = "The following error occurred:\n" + ex.getCause().getMessage()
                            + "\n\nIn addition, make sure you have "
                            + "an available smart card reader connected before opening the application.";
                    JTextArea textArea = new JTextArea(s);
                    textArea.setColumns(60);
                    textArea.setLineWrap(true);
                    textArea.setWrapStyleWord(true);
                    textArea.setSize(textArea.getPreferredSize().width, 1);

                    JOptionPane.showMessageDialog(null, textArea, "Error loading PKCS11 provider",
                            JOptionPane.ERROR_MESSAGE);
                    System.exit(1);
                } else {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null,
                            "Error while setting up PKCS11 provider from configuration file " + f.getName()
                                    + ".\n" + ex.getMessage(),
                            "Error loading PKCS11 provider", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }

    // adds a shutdown hook to save instantiated directories into files when the application is being closed
    Runtime.getRuntime().addShutdownHook(new Thread(Protbox::exit));

    // get system tray and run tray applet
    tray = SystemTray.getSystemTray();
    SwingUtilities.invokeLater(() -> {

        if (Constants.verbose) {
            logger.info("Starting application");
        }

        //Start a new TrayApplet object
        trayApplet = TrayApplet.getInstance();
    });

    // prompts the user to choose which provider to use
    ProviderListWindow.showWindow(Protbox.pkcs11Providers.keySet(), providerName -> {

        // loads eID token
        eIDTokenLoadingWindow.showPrompt(providerName, (returnedUser, returnedCertificateData) -> {
            user = returnedUser;
            certificateData = returnedCertificateData;

            // gets a password to use on the saved registry files (for loading and saving)
            final AtomicReference<Consumer<SecretKey>> consumerHolder = new AtomicReference<>(null);
            consumerHolder.set(password -> {
                registriesPasswordKey = password;
                try {
                    // if there are serialized files, load them if they can be decoded by this user's private key
                    final List<SavedRegistry> serializedDirectories = new ArrayList<>();
                    if (Constants.verbose) {
                        logger.info("Reading serialized registry files...");
                    }

                    File[] registryFileList = new File(Constants.REGISTRIES_DIR).listFiles();
                    if (registryFileList != null) {
                        for (File f : registryFileList) {
                            if (f.isFile()) {
                                byte[] data = FileUtils.readFileToByteArray(f);
                                try {
                                    Cipher cipher = Cipher.getInstance("AES");
                                    cipher.init(Cipher.DECRYPT_MODE, registriesPasswordKey);
                                    byte[] registryDecryptedData = cipher.doFinal(data);
                                    serializedDirectories.add(new SavedRegistry(f, registryDecryptedData));
                                } catch (GeneralSecurityException ex) {
                                    if (Constants.verbose) {
                                        logger.info("Inserted Password does not correspond to " + f.getName());
                                    }
                                }
                            }
                        }
                    }

                    // if there were no serialized directories, show NewDirectory window to configure the first folder
                    if (serializedDirectories.isEmpty() || registryFileList == null) {
                        if (Constants.verbose) {
                            logger.info("No registry files were found: running app as first time!");
                        }
                        NewRegistryWindow.start(true);

                    } else { // there were serialized directories
                        loadRegistry(serializedDirectories);
                        trayApplet.repaint();
                        showTrayApplet();
                    }

                } catch (AWTException | IOException | GeneralSecurityException | ReflectiveOperationException
                        | ProtboxException ex) {

                    JOptionPane.showMessageDialog(null,
                            "The inserted password was invalid! Please try another one!", "Invalid password!",
                            JOptionPane.ERROR_MESSAGE);
                    insertPassword(consumerHolder.get());
                }
            });
            insertPassword(consumerHolder.get());
        });
    });
}

From source file:com.jaeksoft.searchlib.util.StringUtils.java

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

    List<String> lines = FileUtils.readLines(new File(args[0]));
    FileWriter fw = new FileWriter(new File(args[1]));
    PrintWriter pw = new PrintWriter(fw);
    for (String line : lines)
        pw.println(StringEscapeUtils.unescapeHtml(line));
    pw.close();//from   w w w . ja  v  a  2  s. c  o m
    fw.close();
}

From source file:com.utdallas.s3lab.smvhunter.monkey.MonkeyMe.java

/**
 * @param args//from  w  w  w .jav  a  2s  .  c  om
 */
public static void main(String[] args) throws Exception {

    logger.info("start time ==== " + System.currentTimeMillis());

    try {
        //load the adb location from the props file
        Properties props = new Properties();
        props.load(new FileInputStream(new File("adb.props")));

        //set the adb location
        WindowUpdate.adbLocation = props.getProperty("adb_location");
        adbLocation = props.getProperty("adb_location");
        //set root dir
        ROOT_DIRECTORY = props.getProperty("root_dir");
        //completed txt
        completedFile = new File(ROOT_DIRECTORY + "tested.txt");
        //db location for static analysis
        dbLocation = props.getProperty("db_location");
        //location for smart input generation output
        smartInputLocation = props.getProperty("smart_input_location");

        //udp dump location
        udpDumpLocation = props.getProperty("udp_dump_location");
        //logcat dump location
        logCatLocation = props.getProperty("log_cat_location");
        //strace output location
        straceOutputLocation = props.getProperty("strace_output_location");
        //strace dump location
        straceDumpLocation = props.getProperty("strace_output_location");

        //set x and y coords
        UIEnumerator.screenX = props.getProperty("x");
        UIEnumerator.screenY = props.getProperty("y");

        DeviceOfflineMonitor.START_EMULATOR = props.getProperty("restart");

        //read output of static analysis
        readFromStaticAnalysisText();
        logger.info("Read static analysis output");

        readFromSmartInputText();
        logger.info("Read smart input generation output");

        //populate the queue with apps which are only present in the static analysis
        @SuppressWarnings("unchecked")
        final Set<? extends String> sslApps = new HashSet<String>(
                CollectionUtils.collect(FileUtils.readLines(new File(dbLocation)), new Transformer() {
                    @Override
                    public Object transform(Object input) {
                        //get app file name
                        String temp = StringUtils.substringBefore(input.toString(), " ");
                        return StringUtils.substringAfterLast(temp, "/");
                    }
                }));
        Collection<File> fileList = FileUtils.listFiles(new File(ROOT_DIRECTORY), new String[] { "apk" },
                false);
        CollectionUtils.filter(fileList, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                return sslApps.contains(StringUtils.substringAfterLast(object.toString(), "/"));
            }
        });
        apkQueue = new LinkedBlockingDeque<File>(fileList);

        logger.info("finished listing files from the root directory");

        try {
            //populate the tested apk list
            completedApps.addAll(FileUtils.readLines(completedFile));
        } catch (Exception e) {
            //pass except
            logger.info("No tested.txt file found");

            //create new file
            if (completedFile.createNewFile()) {
                logger.info("tested.txt created in root directory");
            } else {
                logger.info("tested.txt file could not be created");
            }

        }

        //get the executors for managing the emulators
        executors = Executors.newCachedThreadPool();

        //set the devicemonitor exec
        DeviceOfflineMonitor.exec = executors;

        final List<Future<?>> futureList = new ArrayList<Future<?>>();

        //start the offline device monitor (emulator management thread)
        logger.info("Starting Device Offline Monitor Thread");
        executors.submit(new DeviceOfflineMonitor());

        //get ADB backend object for device change listener
        AdbBackend adb = new AdbBackend();

        //register for device change and wait for events
        //once event is received, start the MonkeyMe thread
        MonkeyDeviceChangeListener deviceChangeListener = new MonkeyDeviceChangeListener(executors, futureList);
        AndroidDebugBridge.addDeviceChangeListener(deviceChangeListener);
        logger.info("Listening to changes in devices (emulators)");

        //wait for the latch to come down
        //this means that all the apks have been processed
        cdl.await();

        logger.info("Finished testing all apps waiting for threads to join");

        //now wait for every thread to finish
        for (Future<?> future : futureList) {
            future.get();
        }

        logger.info("All threads terminated");

        //stop listening for device update
        AndroidDebugBridge.removeDeviceChangeListener(deviceChangeListener);

        //stop the debug bridge
        AndroidDebugBridge.terminate();

        //stop offline device monitor
        DeviceOfflineMonitor.stop = true;

        logger.info("adb and listeners terminated");

    } finally {
        logger.info("Executing this finally");
        executors.shutdownNow();
    }

    logger.info("THE END!!");
}

From source file:com.qwazr.utils.HtmlUtils.java

public static void main(String args[]) throws IOException {
     if (args != null && args.length == 2) {
         List<String> lines = FileUtils.readLines(new File(args[0]));
         FileWriter fw = new FileWriter(new File(args[1]));
         PrintWriter pw = new PrintWriter(fw);
         for (String line : lines)
             pw.println(StringEscapeUtils.unescapeHtml4(line));
         pw.close();//  w  w w.  java 2s . c om
         fw.close();
     }
     String text = "file://&shy;Users/ekeller/Moteur/infotoday_enterprisesearchsourcebook08/Open_on_Windows.exe";
     System.out.println(htmlWrap(text, 20));
     System.out.println(htmlWrapReduce(text, 20, 80));
     String url = "file://Users/ekeller/Moteur/infotoday_enterprisesearchsourcebook08/Open_on_Windows.exe?test=2";
     System.out.println(urlHostPathWrapReduce(url, 80));
 }