Example usage for java.util List size

List of usage examples for java.util List size

Introduction

In this page you can find the example usage for java.util List size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

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  a va  2s.co  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:edu.pitt.dbmi.facebase.hd.HumanDataController.java

/** Entry point to application.  Firstly it gathers properties from hd.properties file on CLASSPATH 
 * Most properties are localisms to do with file path information, database connection strings, 
 * and TrueCrypt program operation.  Hopefully the application can run by only editing entries in 
 * hd.properties file.  hd.properties has normal java properties fragility but also app-specific 
 * fragility--for example, the sshServerUrl must end with a colon, as in root@server:
 * Notice that program properties can also be set below--by filling in the empty strings following 
 * declaration AND commenting-out the try-catch clause that follows which gathers these properties 
 * from hd.properties.  //from  w  w w.  j  av  a  2 s  . c o m
 */
public static void main(String[] args) {
    /** holds human-readable error data to be passed to addError() */
    String errorString = "";

    log.info("HumanDataController Started");
    /** length of time to sleep in between each polling loop, 5secs is responsive, 5mins is alot */
    String sleepFor = "";
    /** Prefix path where TrueCrypt write operations will be performed (i.e. /tmp or /var/tmp), no trailing-slash */
    String trueCryptBasePath = "";
    /** TrueCrypt volume file extension (probably .tc or .zip) */
    String trueCryptExtension = "";
    /** Middle-of-path directory name to be created where TrueCrypt volume will be mounted */
    String trueCryptMountpoint = "";
    /** Human Data Server database credentials */
    String hdDbUser = "";
    String hdPasswd = "";
    String hdJdbcUrl = "";
    /** Hub database credentials */
    String fbDbUser = "";
    String fbPasswd = "";
    String fbJdbcUrl = "";
    /** Full path to truecrypt binary, (ie /usr/bin/truecrypt) */
    String trueCryptBin = "";
    /** Full path to scp binary, (ie /usr/bin/scp) */
    String scpBin = "";
    /** user@host portion of scp destination argument (ie. root@www.server.com:) */
    String sshServerUrl = "";
    /** file full path portion of scp destination argument (ie. /usr/local/downloads/) */
    String finalLocation = "";
    /** Full path to touch binary, (ie /bin/touch) */
    String touchBin = "";
    /** hardcoded truecrypt parameters; run "truecrypt -h" to learn about these */
    String algorithm = "";
    String hash = "";
    String filesystem = "";
    String volumeType = "";
    String randomSource = "";
    String protectHidden = "";
    String extraArgs = "";

    /** truecrypt parameters are packed into a map so we only pass one arg (this map) to method invoking truecrypt */
    HashMap<String, String> trueCryptParams = new HashMap<String, String>();
    trueCryptParams.put("trueCryptBin", "");
    trueCryptParams.put("scpBin", "");
    trueCryptParams.put("sshServerUrl", "");
    trueCryptParams.put("finalLocation", "");
    trueCryptParams.put("touchBin", "");
    trueCryptParams.put("algorithm", "");
    trueCryptParams.put("hash", "");
    trueCryptParams.put("filesystem", "");
    trueCryptParams.put("volumeType", "");
    trueCryptParams.put("randomSource", "");
    trueCryptParams.put("protectHidden", "");
    trueCryptParams.put("extraArgs", "");

    try {
        /** The properties file name is hardcoded to hd.properties--cannot be changed--this file must be on or at root of classpath */
        final Configuration config = new PropertiesConfiguration("hd.properties");
        sleepFor = config.getString("sleepFor");
        hubURL = config.getString("hubURL");
        responseTrigger = config.getString("responseTrigger");
        trueCryptBasePath = config.getString("trueCryptBasePath");
        trueCryptExtension = config.getString("trueCryptExtension");
        trueCryptMountpoint = config.getString("trueCryptMountpoint");
        hdDbUser = config.getString("hdDbUser");
        hdPasswd = config.getString("hdPasswd");
        hdJdbcUrl = config.getString("hdJdbcUrl");
        fbDbUser = config.getString("fbDbUser");
        fbPasswd = config.getString("fbPasswd");
        fbJdbcUrl = config.getString("fbJdbcUrl");
        trueCryptBin = config.getString("trueCryptBin");
        scpBin = config.getString("scpBin");
        sshServerUrl = config.getString("sshServerUrl");
        finalLocation = config.getString("finalLocation");
        touchBin = config.getString("touchBin");
        algorithm = config.getString("algorithm");
        hash = config.getString("hash");
        filesystem = config.getString("filesystem");
        volumeType = config.getString("volumeType");
        randomSource = config.getString("randomSource");
        protectHidden = config.getString("protectHidden");
        extraArgs = config.getString("extraArgs");

        trueCryptParams.put("trueCryptBin", trueCryptBin);
        trueCryptParams.put("scpBin", scpBin);
        trueCryptParams.put("sshServerUrl", sshServerUrl);
        trueCryptParams.put("finalLocation", finalLocation);
        trueCryptParams.put("touchBin", touchBin);
        trueCryptParams.put("algorithm", algorithm);
        trueCryptParams.put("hash", hash);
        trueCryptParams.put("filesystem", filesystem);
        trueCryptParams.put("volumeType", volumeType);
        trueCryptParams.put("randomSource", randomSource);
        trueCryptParams.put("protectHidden", protectHidden);
        trueCryptParams.put("extraArgs", extraArgs);
        log.debug("properties file loaded successfully");
    } catch (final ConfigurationException e) {
        errorString = "Properties file problem";
        String logString = e.getMessage();
        addError(errorString, logString);
        log.error(errorString);
    }
    log.debug("initialize static class variable HumanDataManager declared earlier");
    hdm = new HumanDataManager(hdDbUser, hdPasswd, hdJdbcUrl);
    log.debug("declare and initialize InstructionQueueManager");
    InstructionQueueManager iqm = new InstructionQueueManager(fbDbUser, fbPasswd, fbJdbcUrl);
    log.debug("pass to the logfile/console all startup parameters for troubleshooting");
    log.info("HumanDataController started with these settings from hd.properties: " + "hubURL=" + hubURL + " "
            + "responseTrigger=" + responseTrigger + " " + "trueCryptBasePath=" + trueCryptBasePath + " "
            + "trueCryptExtension=" + trueCryptExtension + " " + "trueCryptMountpoint=" + trueCryptMountpoint
            + " " + "hdDbUser=" + hdDbUser + " " + "hdPasswd=" + hdPasswd + " " + "hdJdbcUrl=" + hdJdbcUrl + " "
            + "fbDbUser=" + fbDbUser + " " + "fbPasswd=" + fbPasswd + " " + "fbJdbcUrl=" + fbJdbcUrl + " "
            + "trueCryptBin=" + trueCryptBin + " " + "scpBin=" + scpBin + " " + "sshServerUrl=" + sshServerUrl
            + " " + "finalLocation=" + finalLocation + " " + "touchBin=" + touchBin + " " + "algorithm="
            + algorithm + " " + "hash=" + hash + " " + "filesystem=" + filesystem + " " + "volumeType="
            + volumeType + " " + "randomSource=" + randomSource + " " + "protectHidden=" + protectHidden + " "
            + "extraArgs=" + extraArgs);
    log.debug("Enter infinite loop where program will continuously poll Hub server database for new requests");
    while (true) {
        log.debug("LOOP START");
        try {
            Thread.sleep(Integer.parseInt(sleepFor) * 1000);
        } catch (InterruptedException ie) {
            errorString = "Failed to sleep, got interrupted.";
            log.error(errorString, ie);
            addError(errorString, ie.getMessage());
        }
        log.debug(
                "About to invoke InstructionQueueManager.queryInstructions()--Hibernate to fb_queue starts NOW");
        List<InstructionQueueItem> aiqi = iqm.queryInstructions();
        log.debug("Currently there are " + aiqi.size() + " items in the queue");
        InstructionQueueItem iqi;
        String instructionName = "";
        log.debug("About to send http request -status- telling Hub we are alive:");
        httpGetter("status", "0");
        if (aiqi.size() > 0) {
            log.debug(
                    "There is at least one request, status=pending, queue item; commence processing of most recent item");
            iqi = aiqi.get(0);
            log.debug("About to get existing user key, or create a new one, via fb_keychain Hibernate");
            FbKey key = hdm.queryKey(iqi.getUid());
            log.debug(
                    "About to pull the JSON Instructions string, and other items, from the InstructionQueueItem");
            String instructionsString = iqi.getInstructions();
            instructionName = iqi.getName();
            log.debug("About to create a new FileManager object with:");
            log.debug(instructionName + trueCryptBasePath + trueCryptExtension + trueCryptMountpoint);
            FileManager fm = new FileManager(instructionName, trueCryptBasePath, trueCryptExtension,
                    trueCryptMountpoint);
            ArrayList<Instructions> ali = new ArrayList<Instructions>();
            log.debug(
                    "FileManager.makeInstructionsObjects() creates multiple Instruction objects from the InstructionQueueItem.getInstructions() value");
            if (fm.makeInstructionsObjects(instructionsString, ali)) {
                log.debug("FileManager.makeInstructionsObjects() returned true");
            } else {
                errorString = "FileManager.makeInstructionsObjects() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            log.debug(
                    "FileManager.makeFiles() uses its list of Instruction objects and calls its makeFiles() method to make/get requested data files");
            if (fm.makeFiles(ali)) {
                log.debug("FileManager.makeFiles() returned true");
            } else {
                errorString = "FileManager.makeFiles() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            //sends the size/100000 as seconds(100k/sec)...needs to be real seconds.");
            long bytesPerSecond = 100000;
            Long timeToMake = new Long(fm.getSize() / bytesPerSecond);
            String timeToMakeString = timeToMake.toString();
            log.debug("Send http request -status- to Hub with total creation time estimate:");
            log.debug(timeToMakeString);
            httpGetter("status", timeToMakeString);
            log.debug(
                    "Update the queue_item row with the total size of the data being packaged with InstructionQueueManager.updateInstructionSize()");
            if (iqm.updateInstructionSize(fm.getSize(), iqi.getQid())) {
                log.debug("InstructionQueueManager.updateInstructionSize() returned true");
            } else {
                errorString = "InstructionQueueManager.updateInstructionSize() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            log.debug("About to make new TrueCryptManager with these args:");
            log.debug(key.getEncryption_key() + fm.getSize() + fm.getTrueCryptPath()
                    + fm.getTrueCryptVolumePath() + trueCryptParams);
            TrueCryptManager tcm = new TrueCryptManager(key.getEncryption_key(), fm.getSize(),
                    fm.getTrueCryptPath(), fm.getTrueCryptVolumePath(), trueCryptParams);
            if (tcm.touchVolume()) {
                log.debug("TrueCryptManager.touchVolume() returned true, touched file");
            } else {
                errorString = "TrueCryptManager.touchVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.makeVolume()) {
                log.debug("TrueCryptManager.makeVolume() returned true, created TrueCrypt volume");
            } else {
                errorString = "TrueCryptManager.makeVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.mountVolume()) {
                log.debug("TrueCryptManager.mountVolume() returned true, mounted TrueCrypt volume");
            } else {
                errorString = "TrueCryptManager.mountVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (fm.copyFilesToVolume(ali)) {
                log.debug(
                        "TrueCryptManager.copyFilesToVolume() returned true, copied requested files to mounted volume");
            } else {
                errorString = "TrueCryptManager.copyFilesToVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.disMountVolume()) {
                log.debug("TrueCryptManager.disMountVolume() returned true, umounted TrueCrypt volume");
            } else {
                errorString = "TrueCryptManager.disMountVolume() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (tcm.sendVolumeToFinalLocation()) {
                log.debug(
                        "TrueCryptManager.sendVolumeToFinalLocation() returned true, copied TrueCrypt volume to retreivable, final location");
            } else {
                errorString = "TrueCryptManager.sendVolumeToFinalLocation() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            if (iqm.updateInstructionToCompleted(tcm.getFinalLocation() + fm.getTrueCryptFilename(),
                    fm.getSize(), iqi.getQid(), getErrors(), getLogs())) {
                log.debug("InstructionQueueManager.updateInstructionToCompleted() returned true");
                log.debug(
                        "Processing of queue item is almost finished, updated fb_queue item row with location, size, status, errors, logs:");
                log.debug(tcm.getFinalLocation() + fm.getTrueCryptFilename() + fm.getSize() + iqi.getQid()
                        + getErrors() + getLogs());
            } else {
                errorString = "InstructionQueueManager.updateInstructionToCompleted() returned false";
                log.error(errorString);
                addError(errorString, "");
            }
            log.debug("About to send http request -update- telling Hub which item is finished.");
            httpGetter("update", iqi.getHash());
            log.debug("Finished processing pending queue item, status should now be complete or error");
        } else {
            log.debug("Zero queue items");
        }
        log.debug("LOOP END");
    }
}

From source file:io.s4.client.Driver.java

/**
 * Reads and prints all events over an interval of 5 seconds from a set of
 * streams specified on the command line.
 * //w  w w.j ava 2  s.  c  o  m
 * @param argv
 *            list of streams
 * @throws IOException
 *             if an error occurs while reading from adapter.
 */
public static void main(String[] argv) throws IOException {
    Driver d = new Driver("localhost", 2334);

    System.out.println("State: " + d.getState());

    d.init();

    System.out.println("State: " + d.getState());

    d.setReadMode(ReadMode.Select).readInclude(argv).setWriteMode(WriteMode.Enabled);

    d.connect();

    System.out.println("State: " + d.getState());

    List<Message> mm = d.recvAll(5001);
    System.out.println("got messages (" + mm.size() + "): " + mm);

    System.out.println("Disconnecting...");
    d.disconnect();

    System.out.println("State: " + d.getState());
}

From source file:com.act.lcms.v2.MZCollisionCounter.java

public static void main(String[] args) throws Exception {
    CLIUtil cliUtil = new CLIUtil(MassChargeCalculator.class, HELP_MESSAGE, OPTION_BUILDERS);
    CommandLine cl = cliUtil.parseCommandLine(args);

    File inputFile = new File(cl.getOptionValue(OPTION_INPUT_INCHI_LIST));
    if (!inputFile.exists()) {
        cliUtil.failWithMessage("Input file at does not exist at %s", inputFile.getAbsolutePath());
    }/*from   www  .ja v  a  2 s  .  c om*/

    List<MassChargeCalculator.MZSource> sources = new ArrayList<>();
    try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) {
        String line;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            sources.add(new MassChargeCalculator.MZSource(line));
            if (sources.size() % 1000 == 0) {
                LOGGER.info("Loaded %d sources from input file", sources.size());
            }
        }
    }

    Set<String> considerIons = Collections.emptySet();
    if (cl.hasOption(OPTION_ONLY_CONSIDER_IONS)) {
        List<String> ions = Arrays.asList(cl.getOptionValues(OPTION_ONLY_CONSIDER_IONS));
        LOGGER.info("Only considering ions for m/z calculation: %s", StringUtils.join(ions, ", "));
        considerIons = new HashSet<>(ions);
    }

    TSVWriter<String, Long> tsvWriter = new TSVWriter<>(Arrays.asList("collisions", "count"));
    tsvWriter.open(new File(cl.getOptionValue(OPTION_OUTPUT_FILE)));

    try {
        LOGGER.info("Loaded %d sources in total from input file", sources.size());

        MassChargeCalculator.MassChargeMap mzMap = MassChargeCalculator.makeMassChargeMap(sources,
                considerIons);

        if (!cl.hasOption(OPTION_COUNT_WINDOW_INTERSECTIONS)) {
            // Do an exact analysis of the m/z collisions if windowing is not specified.

            LOGGER.info("Computing precise collision histogram.");
            Iterable<Double> mzs = mzMap.ionMZIter();
            Map<Integer, Long> collisionHistogram = histogram(
                    StreamSupport.stream(mzs.spliterator(), false).map(mz -> { // See comment about Iterable below.
                        try {
                            return mzMap.ionMZToMZSources(mz).size();
                        } catch (NoSuchElementException e) {
                            LOGGER.error("Caught no such element exception for mz %f: %s", mz, e.getMessage());
                            throw e;
                        }
                    }));
            List<Integer> sortedCollisions = new ArrayList<>(collisionHistogram.keySet());
            Collections.sort(sortedCollisions);
            for (Integer collision : sortedCollisions) {
                tsvWriter.append(new HashMap<String, Long>() {
                    {
                        put("collisions", collision.longValue());
                        put("count", collisionHistogram.get(collision));
                    }
                });
            }
        } else {
            /* After some deliberation (thanks Gil!), the windowed variant of this calculation counts the number of
             * structures whose 0.01 Da m/z windows (for some set of ions) overlap with each other.
             *
             * For example, let's assume we have five total input structures, and are only searching for one ion.  Let's
             * also assume that three of those structures have m/z A and the remaining two have m/z B.  The windows might
             * look like this in the m/z domain:
             * |----A----|
             *        |----B----|
             * Because A represents three structures and overlaps with B, which represents two, we assign A a count of 5--
             * this is the number of structures we believe could fall into the range of A given our current peak calling
             * approach.  Similarly, B is assigned a count of 5, as the possibility for collision/confusion is symmetric.
             *
             * Note that this is an over-approximation of collisions, as we could more precisely only consider intersections
             * when the exact m/z of B falls within the window around A and vice versa.  However, because we have observed
             * cases where the MS sensor doesn't report structures at exactly the m/z we predict, we employ this weaker
             * definition of intersection to give a slightly pessimistic view of what confusions might be possible. */
            // Compute windows for every m/z.  We don't care about the original mz values since we just want the count.
            List<Double> mzs = mzMap.ionMZsSorted();

            final Double windowHalfWidth;
            if (cl.hasOption(OPTION_WINDOW_HALFWIDTH)) {
                // Don't use get with default for this option, as we want the exact FP value of the default tolerance.
                windowHalfWidth = Double.valueOf(cl.getOptionValue(OPTION_WINDOW_HALFWIDTH));
            } else {
                windowHalfWidth = DEFAULT_WINDOW_TOLERANCE;
            }

            /* Window = (lower bound, upper bound), counter of represented m/z's that collide with this window, and number
             * of representative structures (which will be used in counting collisions). */
            LinkedList<CollisionWindow> allWindows = new LinkedList<CollisionWindow>() {
                {
                    for (Double mz : mzs) {
                        // CPU for memory trade-off: don't re-compute the window bounds over and over and over and over and over.
                        try {
                            add(new CollisionWindow(mz, windowHalfWidth, mzMap.ionMZToMZSources(mz).size()));
                        } catch (NoSuchElementException e) {
                            LOGGER.error("Caught no such element exception for mz %f: %s", mz, e.getMessage());
                            throw e;
                        }
                    }
                }
            };

            // Sweep line time!  The window ranges are the interesting points.  We just accumulate overlap counts as we go.
            LinkedList<CollisionWindow> workingSet = new LinkedList<>();
            List<CollisionWindow> finished = new LinkedList<>();

            while (allWindows.size() > 0) {
                CollisionWindow thisWindow = allWindows.pop();
                // Remove any windows from the working set that don't overlap with the next window.
                while (workingSet.size() > 0 && workingSet.peekFirst().getMaxMZ() < thisWindow.getMinMZ()) {
                    finished.add(workingSet.pop());
                }

                for (CollisionWindow w : workingSet) {
                    /* Add the size of the new overlapping window's structure count to each of the windows in the working set,
                     * which represents the number of possible confused structures that fall within the overlapping region.
                     * We exclude the window itself as it should already have counted the colliding structures it represents. */
                    w.getAccumulator().add(thisWindow.getStructureCount());

                    /* Reciprocally, add the structure counts of all windows with which the current window overlaps to it. */
                    thisWindow.getAccumulator().add(w.getStructureCount());
                }

                // Now that accumulation is complete, we can safely add the current window.
                workingSet.add(thisWindow);
            }

            // All the interesting events are done, so drop the remaining windows into the finished set.
            finished.addAll(workingSet);

            Map<Long, Long> collisionHistogram = histogram(
                    finished.stream().map(w -> w.getAccumulator().longValue()));
            List<Long> sortedCollisions = new ArrayList<>(collisionHistogram.keySet());
            Collections.sort(sortedCollisions);
            for (Long collision : sortedCollisions) {
                tsvWriter.append(new HashMap<String, Long>() {
                    {
                        put("collisions", collision);
                        put("count", collisionHistogram.get(collision));
                    }
                });
            }
        }
    } finally {
        if (tsvWriter != null) {
            tsvWriter.close();
        }
    }
}

From source file:simauthenticator.SimAuthenticator.java

/**
 * @param args the command line arguments
 *///from  w  ww  .  j a va 2  s. c o  m
public static void main(String[] args) throws Exception {

    cliOpts = new Options();
    cliOpts.addOption("U", "url", true, "Connection URL");
    cliOpts.addOption("u", "user", true, "User name");
    cliOpts.addOption("p", "password", true, "User password");
    cliOpts.addOption("d", "domain", true, "Domain name");
    cliOpts.addOption("v", "verbose", false, "Verbose output");
    cliOpts.addOption("k", "keystore", true, "KeyStore path");
    cliOpts.addOption("K", "keystorepass", true, "KeyStore password");
    cliOpts.addOption("h", "help", false, "Print help info");

    CommandLineParser clip = new GnuParser();
    cmd = clip.parse(cliOpts, args);

    if (cmd.hasOption("help")) {
        help();
        return;
    } else {
        boolean valid = init(args);
        if (!valid) {
            return;
        }
    }

    HttpClientContext clientContext = HttpClientContext.create();

    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    char[] keystorePassword = passwk.toCharArray();
    FileInputStream kfis = null;
    try {
        kfis = new FileInputStream(keyStorePath);
        ks.load(kfis, keystorePassword);
    } finally {
        if (kfis != null) {
            kfis.close();
        }
    }

    SSLContext sslContext = SSLContexts.custom().useSSL().loadTrustMaterial(ks).build();
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setSslcontext(sslContext)
            .setSSLSocketFactory(sslsf).setUserAgent(userAgent);
    ;

    cookieStore = new BasicCookieStore();
    /* BasicClientCookie cookie = new BasicClientCookie("SIM authenticator", "Utility for getting event details");
     cookie.setVersion(0);
     cookie.setDomain(".astelit.ukr");
     cookie.setPath("/");
     cookieStore.addCookie(cookie);*/

    CloseableHttpClient client = httpClientBuilder.build();

    try {

        NTCredentials creds = new NTCredentials(usern, passwu, InetAddress.getLocalHost().getHostName(),
                domain);
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY, creds);
        HttpClientContext context = HttpClientContext.create();
        context.setCredentialsProvider(credsProvider);
        context.setCookieStore(cookieStore);
        HttpGet httpget = new HttpGet(eventUrl);
        if (verbose) {
            System.out.println("executing request " + httpget.getRequestLine());
        }
        HttpResponse response = client.execute(httpget, context);
        HttpEntity entity = response.getEntity();

        HttpPost httppost = new HttpPost(eventUrl);
        List<Cookie> cookies = cookieStore.getCookies();

        if (verbose) {
            System.out.println("----------------------------------------------");
            System.out.println(response.getStatusLine());
            System.out.print("Initial set of cookies: ");
            if (cookies.isEmpty()) {
                System.out.println("none");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }
        }

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("usernameInput", usern));
        nvps.add(new BasicNameValuePair("passwordInput", passwu));
        nvps.add(new BasicNameValuePair("domainInput", domain));
        //nvps.add(new BasicNameValuePair("j_username", domain + "\\" + usern));
        //nvps.add(new BasicNameValuePair("j_password", ipAddr + ";" + passwu));
        if (entity != null && verbose) {
            System.out.println("Responce content length: " + entity.getContentLength());

        }

        //System.out.println(EntityUtils.toString(entity));

        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

        HttpResponse afterPostResponse = client.execute(httppost, context);
        HttpEntity afterPostEntity = afterPostResponse.getEntity();
        cookies = cookieStore.getCookies();
        if (entity != null && verbose) {
            System.out.println("----------------------------------------------");
            System.out.println(afterPostResponse.getStatusLine());
            System.out.println("Responce content length: " + afterPostEntity.getContentLength());
            System.out.print("After POST set of cookies: ");
            if (cookies.isEmpty()) {
                System.out.println("none");
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    System.out.println("- " + cookies.get(i).toString());
                }
            }
        }

        System.out.println(EntityUtils.toString(afterPostEntity));
        EntityUtils.consume(entity);
        EntityUtils.consume(afterPostEntity);

    } finally {

        client.getConnectionManager().shutdown();
    }

}

From source file:PodbaseMetadataMigration2.java

public static void main(String[] args) throws Exception {
    System.out.println("Running data migration");

    String projectString = FileUtils.readFileToString(new File("projects.txt"));
    Map<String, Integer> projectIdMapping = new HashMap<String, Integer>();
    for (String line : projectString.split("\n")) {
        String[] split = line.split(":");
        int id = Integer.parseInt(split[0].trim());
        String name = split[1].trim();
        projectIdMapping.put(name, id);// w ww  .  ja  v a2 s .com
    }

    System.out.println("Reading projects..");
    List<ProjectEntry> projects = dataFromFile("./migrate/projects.data", ProjectEntry.class);
    projectIdMap = parseProjectMap(projects, projectIdMapping);

    System.out.println("Found " + projects.size() + " projects.");

    System.out.println("Reading tags..");
    List<TagEntry> tags = dataFromFile("./migrate/tags.data", TagEntry.class);
    System.out.println("Found " + tags.size() + " tags.");

    System.out.println("Reading templates..");
    List<TemplateEntry> templates = dataFromFile("./migrate/templates.data", TemplateEntry.class);
    System.out.println("Found " + templates.size() + " templates.");

    System.out.println("Reading template fields..");
    List<TemplateFieldEntry> templateFields = dataFromFile("./migrate/template_fields.data",
            TemplateFieldEntry.class);
    System.out.println("Found " + templateFields.size() + " templateFields.");

    int entryCount = tags.size() + templates.size() + templateFields.size();

    //System.out.println("Generating Project SQL");
    //String projectSql = generateSql((List<AbstractEntry>)(List<?>)projects);
    System.out.println("Generating Attribute SQL");
    String imageAttributes = generateSql((List<AbstractEntry>) (List<?>) tags);
    System.out.println("Generating Image SQL");
    String databaseImages = generateDatabaseImageSql();
    //System.out.println("Generating Directory SQL");
    //String directorySql = generateDirectorySql(projects);

    //System.out.println("Generating Template SQL");
    //String templateSql = generateSql((List<AbstractEntry>)(List<?>)templates);
    //System.out.println("Generating Field SQL");
    //String fieldsSql = generateSql((List<AbstractEntry>)(List<?>)templateFields);

    System.out.println("Writing database.sql");
    BufferedWriter bw = new BufferedWriter(new FileWriter(new File("./database.sql")));
    //bw.append(projectSql);
    //bw.append("\n\n");
    bw.append(databaseImages);
    bw.append("\n\n");
    //bw.append(directorySql);
    //bw.append("\n\n");
    bw.append(imageAttributes);
    bw.append("\n\n");
    //      bw.append(templateSql);
    //      bw.append("\n\n");
    //      bw.append(fieldsSql);
    //      bw.append("\n\n");
    bw.close();

    System.out.println("Writing missingImages.txt");
    bw = new BufferedWriter(new FileWriter(new File("./missingImages.txt")));
    for (String img : missingImages) {
        bw.append(img + "\n");
    }
    bw.close();

    System.out.println("Migration completed successfully!");
}

From source file:io.s4.util.LoadGenerator.java

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

    options.addOption(//from w  w  w . jav  a  2s .  c  om
            OptionBuilder.withArgName("rate").hasArg().withDescription("Rate (events per second)").create("r"));

    options.addOption(OptionBuilder.withArgName("display_rate").hasArg()
            .withDescription("Display Rate at specified second boundary").create("d"));

    options.addOption(OptionBuilder.withArgName("start_boundary").hasArg()
            .withDescription("Start boundary in seconds").create("b"));

    options.addOption(OptionBuilder.withArgName("run_for").hasArg()
            .withDescription("Run for a specified number of seconds").create("x"));

    options.addOption(OptionBuilder.withArgName("cluster_manager").hasArg().withDescription("Cluster manager")
            .create("z"));

    options.addOption(OptionBuilder.withArgName("sender_application_name").hasArg()
            .withDescription("Sender application name").create("a"));

    options.addOption(OptionBuilder.withArgName("listener_application_name").hasArg()
            .withDescription("Listener application name").create("g"));

    options.addOption(
            OptionBuilder.withArgName("sleep_overhead").hasArg().withDescription("Sleep overhead").create("o"));

    options.addOption(new Option("w", "Warm-up"));

    CommandLineParser parser = new GnuParser();

    CommandLine line = null;
    try {
        // parse the command line arguments
        line = parser.parse(options, args);
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Parsing failed.  Reason: " + exp.getMessage());
        System.exit(1);
    }

    int expectedRate = 250;
    if (line.hasOption("r")) {
        try {
            expectedRate = Integer.parseInt(line.getOptionValue("r"));
        } catch (Exception e) {
            System.err.println("Bad expected rate specified " + line.getOptionValue("r"));
            System.exit(1);
        }
    }

    int displayRateIntervalSeconds = 20;
    if (line.hasOption("d")) {
        try {
            displayRateIntervalSeconds = Integer.parseInt(line.getOptionValue("d"));
        } catch (Exception e) {
            System.err.println("Bad display rate value specified " + line.getOptionValue("d"));
            System.exit(1);
        }
    }

    int startBoundary = 2;
    if (line.hasOption("b")) {
        try {
            startBoundary = Integer.parseInt(line.getOptionValue("b"));
        } catch (Exception e) {
            System.err.println("Bad start boundary value specified " + line.getOptionValue("b"));
            System.exit(1);
        }
    }

    int updateFrequency = 0;
    if (line.hasOption("f")) {
        try {
            updateFrequency = Integer.parseInt(line.getOptionValue("f"));
        } catch (Exception e) {
            System.err.println("Bad query udpdate frequency specified " + line.getOptionValue("f"));
            System.exit(1);
        }
        System.out.printf("Update frequency is %d\n", updateFrequency);
    }

    int runForTime = 0;
    if (line.hasOption("x")) {
        try {
            runForTime = Integer.parseInt(line.getOptionValue("x"));
        } catch (Exception e) {
            System.err.println("Bad run for time specified " + line.getOptionValue("x"));
            System.exit(1);
        }
        System.out.printf("Run for time is %d\n", runForTime);
    }

    String clusterManagerAddress = null;
    if (line.hasOption("z")) {
        clusterManagerAddress = line.getOptionValue("z");
    }

    String senderApplicationName = null;
    if (line.hasOption("a")) {
        senderApplicationName = line.getOptionValue("a");
    }

    String listenerApplicationName = null;
    if (line.hasOption("a")) {
        listenerApplicationName = line.getOptionValue("g");
    }

    if (listenerApplicationName == null) {
        listenerApplicationName = senderApplicationName;
    }

    long sleepOverheadMicros = -1;
    if (line.hasOption("o")) {
        try {
            sleepOverheadMicros = Long.parseLong(line.getOptionValue("o"));
        } catch (NumberFormatException e) {
            System.err.println("Bad sleep overhead specified " + line.getOptionValue("o"));
            System.exit(1);
        }
        System.out.printf("Specified sleep overhead is %d\n", sleepOverheadMicros);
    }

    if (line.hasOption("w")) {
        warmUp = true;
    }

    List loArgs = line.getArgList();
    if (loArgs.size() < 1) {
        System.err.println("No input file specified");
        System.exit(1);
    }

    String inputFilename = (String) loArgs.get(0);

    EventEmitter emitter = null;

    SerializerDeserializer serDeser = new KryoSerDeser();

    CommLayerEmitter clEmitter = new CommLayerEmitter();
    clEmitter.setAppName(senderApplicationName);
    clEmitter.setListenerAppName(listenerApplicationName);
    clEmitter.setClusterManagerAddress(clusterManagerAddress);
    clEmitter.setSenderId(String.valueOf(System.currentTimeMillis() / 1000));
    clEmitter.setSerDeser(serDeser);
    clEmitter.init();
    emitter = clEmitter;

    long endTime = 0;
    if (runForTime > 0) {
        endTime = System.currentTimeMillis() + (runForTime * 1000);
    }

    LoadGenerator loadGenerator = new LoadGenerator();
    loadGenerator.setInputFilename(inputFilename);
    loadGenerator.setEventEmitter(clEmitter);
    loadGenerator.setDisplayRateInterval(displayRateIntervalSeconds);
    loadGenerator.setExpectedRate(expectedRate);
    loadGenerator.run();

    System.exit(0);
}

From source file:org.wso2.api.client.APIDownloader.java

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

    String adminCookie;/*  w  ww. j a v a 2  s.  co m*/
    String authenticationAdminURL = APIDownloaderConstant.SERVICE_URL
            + APIDownloaderConstant.AUTHENTICATION_ADMIN;
    String tenantAdminURL = APIDownloaderConstant.SERVICE_URL + APIDownloaderConstant.TENANT_ADMIN;

    // setting the system properties for javax.net.ssl
    AuthenticationAdminServiceClient.setSystemProperties(APIDownloaderConstant.CLIENT_TRUST_STORE_PATH,
            APIDownloaderConstant.KEY_STORE_TYPE, APIDownloaderConstant.KEY_STORE_PASSWORD);
    AuthenticationAdminServiceClient.init(authenticationAdminURL);
    log.info("retrieving the admin cookie from the logged in session....");
    adminCookie = AuthenticationAdminServiceClient.login(APIDownloaderConstant.HOST_NAME,
            APIDownloaderConstant.USER_NAME, APIDownloaderConstant.PASSWORD);

    List<String> tenantDomainList = null;
    if (adminCookie != null) {
        log.info("logged in to the back-end server successfully....");

        TenantMgtAdminServiceClient.init(tenantAdminURL, adminCookie);
        tenantDomainList = TenantMgtAdminServiceClient.getAllTenants();
    } else {
        throw new APIStoreInvocationException("Login Failed to Admin service");
    }

    httpClient = HttpClientBuilder.create().build();
    String storeCookie = StoreAPIInvoker.loginToStore(httpClient);

    if (storeCookie == null) {
        throw new APIStoreInvocationException("Login Failed to API Store");
    }

    for (int i = 0; i < tenantDomainList.size(); i++) {
        APIMetaData apiMetaData = StoreAPIInvoker.fetchAPIMetaData(httpClient, tenantDomainList.get(i),
                storeCookie);
        StoreAPIInvoker.fetchAPIDefinition(httpClient, apiMetaData, storeCookie);
    }
}

From source file:alfio.config.SpringBootLauncher.java

/**
 * Entry point for spring boot/*from  w  w w .j  ava2  s. com*/
 * @param args original arguments
 */
public static void main(String[] args) {
    Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
    String profiles = System.getProperty("spring.profiles.active", "");

    SpringApplication application = new SpringApplication(SpringBootInitializer.class,
            RepositoryConfiguration.class, DataSourceConfiguration.class, WebSecurityConfig.class,
            MvcConfiguration.class);
    List<String> additionalProfiles = new ArrayList<>();
    additionalProfiles.add(Initializer.PROFILE_SPRING_BOOT);
    if ("true".equals(System.getenv("ALFIO_LOG_STDOUT_ONLY"))) {
        // -> will load application-stdout.properties on top to override the logger configuration
        additionalProfiles.add("stdout");
    }
    if ("true".equals(System.getenv("ALFIO_DEMO_ENABLED"))) {
        additionalProfiles.add(Initializer.PROFILE_DEMO);
    }
    if ("true".equals(System.getenv("ALFIO_JDBC_SESSION_ENABLED"))) {
        additionalProfiles.add(Initializer.PROFILE_JDBC_SESSION);
    }
    application.setAdditionalProfiles(additionalProfiles.toArray(new String[additionalProfiles.size()]));
    ConfigurableApplicationContext applicationContext = application.run(args);
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    log.info("profiles: requested {}, active {}", profiles,
            String.join(", ", (CharSequence[]) environment.getActiveProfiles()));
    if ("true".equals(System.getProperty("startDBManager"))) {
        launchHsqlGUI();
    }
}

From source file:org.n52.oss.testdata.sml.GeneratorClient.java

/**
 * @param args// w w w.  j  a  v  a2  s .com
 */
public static void main(String[] args) {
    if (sending)
        log.info("Starting insertion of test sensors into " + sirURL);
    else
        log.warn("Starting generation of test sensors, NOT sending!");

    TestSensorFactory factory = new TestSensorFactory();

    // create sensors
    List<TestSensor> sensors = new ArrayList<TestSensor>();

    for (int i = 0; i < nSensorsToGenerate; i++) {
        TestSensor s = factory.createRandomTestSensor();
        sensors.add(s);
        log.info("Added new random sensor: " + s);
    }

    ArrayList<String> insertedSirIds = new ArrayList<String>();

    // insert sensors to service
    int startOfSubList = 0;
    int endOfSubList = nSensorsInOneInsertRequest;
    while (endOfSubList <= sensors.size() + nSensorsInOneInsertRequest) {
        List<TestSensor> currentSensors = sensors.subList(startOfSubList,
                Math.min(endOfSubList, sensors.size()));

        if (currentSensors.isEmpty())
            break;

        try {
            String[] insertedSirIDs = insertSensorsInSIR(currentSensors);
            if (insertedSirIDs == null) {
                log.error("Did not insert dummy sensors.");
            } else {
                insertedSirIds.addAll(Arrays.asList(insertedSirIDs));
            }
        } catch (HttpException e) {
            log.error("Error inserting sensors.", e);
        } catch (IOException e) {
            log.error("Error inserting sensors.", e);
        }

        startOfSubList = Math.min(endOfSubList, sensors.size());
        endOfSubList = endOfSubList + nSensorsInOneInsertRequest;

        if (sending) {
            try {
                if (log.isDebugEnabled())
                    log.debug("Sleeping for " + SLEEP_BETWEEN_REQUESTS + " msecs.");
                Thread.sleep(SLEEP_BETWEEN_REQUESTS);
            } catch (InterruptedException e) {
                log.error("Interrupted!", e);
            }
        }
    }

    log.info("Added sensors (ids in sir): " + Arrays.toString(insertedSirIds.toArray()));
}