Example usage for org.apache.commons.lang3.text StrTokenizer nextToken

List of usage examples for org.apache.commons.lang3.text StrTokenizer nextToken

Introduction

In this page you can find the example usage for org.apache.commons.lang3.text StrTokenizer nextToken.

Prototype

public String nextToken() 

Source Link

Document

Gets the next token from the String.

Usage

From source file:com.hurence.logisland.repository.csv.DynDnsFileParser.java

@Override
public MalwareHost createEntity(StrTokenizer tokenizer) {
    try {/*from  ww w.  ja v a  2  s. co  m*/
        String host = tokenizer.nextToken();
        String malwareBehavior = "dynamic dns";
        MalwareHost malwareHost = new MalwareHost(null, "", "", host, malwareBehavior);

        return malwareHost;
    } catch (Exception ex) {
        log.error("unable to create entity for tokenizer :" + tokenizer.toString(), ex);
        return null;
    }
}

From source file:com.hurence.logisland.repository.csv.MalwareHostCsvFileParser.java

@Override
public MalwareHost createEntity(StrTokenizer tokenizer) {
    try {//from   w w  w  . j a  v  a  2 s  . com
        String host = tokenizer.nextToken();
        String malwareBehavior = tokenizer.nextToken();
        MalwareHost malwareHost = new MalwareHost(null, "", "", host, malwareBehavior);
        return malwareHost;
    } catch (Exception ex) {
        log.error("unable to create entity for tokenizer :" + tokenizer.toString(), ex);
        return null;
    }
}

From source file:com.hurence.logisland.repository.csv.CommandAndConquerHostCsvFileParser.java

@Override
public MalwareHost createEntity(StrTokenizer tokenizer) {
    try {//from  w  ww .ja  va  2s  .  c  o  m
        // date sample : 2013/07/11_02:06
        String strDate = cleanup(tokenizer.nextToken());
        Date updateDate = null;
        if (strDate != null)
            updateDate = sdf.parse(strDate);
        String url = cleanup(tokenizer.nextToken());
        String ip = cleanup(tokenizer.nextToken());
        String host = cleanup(tokenizer.nextToken());
        String malwareBehavior = cleanup(tokenizer.nextToken());

        return new MalwareHost(updateDate, url, ip, host, malwareBehavior);
    } catch (Exception ex) {
        log.error("unable to create entity for tokenizer :" + tokenizer.toString(), ex);
        return null;
    }
}

From source file:edu.lternet.pasta.portal.PastaStatistics.java

/**
 * Iterates through the list of scopes and identifiers to calculate
 * the number of data packages in PASTA.
 * //from   w w w  .  jav a  2 s  .  c om
 * @return The number of data packages.
 */
public Integer getNumDataPackages() {

    Integer numDataPackages = 0;
    String scopeList = null;

    try {
        scopeList = this.dpmClient.listDataPackageScopes();
    } catch (Exception e) {
        logger.error("PastaStatistics: " + e.getMessage());
        e.printStackTrace();
    }

    StrTokenizer scopes = new StrTokenizer(scopeList);

    while (scopes.hasNext()) {
        String scope = scopes.nextToken();

        String idList = null;

        try {
            idList = this.dpmClient.listDataPackageIdentifiers(scope);
        } catch (Exception e) {
            logger.error("PastaStatistics: " + e.getMessage());
            e.printStackTrace();
        }

        StrTokenizer identifiers = new StrTokenizer(idList);

        numDataPackages += identifiers.size();

    }

    return numDataPackages;

}

From source file:edu.lternet.pasta.portal.RevisionBrowseServlet.java

/**
 * The doPost method of the servlet. <br>
 * /*from  w  ww . j a va  2 s.c o  m*/
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request
 *          the request send by the client to the server
 * @param response
 *          the response send by the server to the client
 * @throws ServletException
 *           if an error occurred
 * @throws IOException
 *           if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession httpSession = request.getSession();
    String uid = (String) httpSession.getAttribute("uid");
    if (uid == null || uid.isEmpty())
        uid = "public";
    String scope = request.getParameter("scope");
    String identifier = request.getParameter("identifier");
    Integer id = Integer.valueOf(identifier);
    String text = null;
    String html = null;
    Integer count = 0;

    try {

        if (scope != null && !(scope.isEmpty()) && identifier != null && !(identifier.isEmpty())) {
            DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid);
            text = dpmClient.listDataPackageRevisions(scope, id, null);
            StrTokenizer tokens = new StrTokenizer(text);
            html = "<ol>\n";

            while (tokens.hasNext()) {
                String revision = tokens.nextToken();
                html += "<li><a class=\"searchsubcat\" href=\"./mapbrowse?scope=" + scope + "&identifier="
                        + identifier + "&revision=" + revision + "\">" + scope + "." + identifier + "."
                        + revision + "</a></li>\n";
                count++;
            }

            html += "</ol>\n";
        } else {
            String msg = "The 'scope', 'identifier', or 'revision' field of the packageId is empty.";
            throw new UserErrorException(msg);
        }
    } catch (Exception e) {
        handleDataPortalError(logger, e);
    }

    request.setAttribute("browsemessage", browseMessage);
    request.setAttribute("html", html);
    request.setAttribute("count", count.toString());
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward);
    requestDispatcher.forward(request, response);
}

From source file:edu.lternet.pasta.portal.UserBrowseServlet.java

/**
 * The doPost method of the servlet. <br>
 * //  ww w. j  a  va 2  s.co  m
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request
 *          the request send by the client to the server
 * @param response
 *          the response send by the server to the client
 * @throws ServletException
 *           if an error occurred
 * @throws IOException
 *           if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession httpSession = request.getSession();
    String uid = (String) httpSession.getAttribute("uid");
    String distinguishedName = (String) httpSession.getAttribute("uid");
    String forward = null;
    String browseMessage = "View a data package you have uploaded.";

    if (uid == null || uid.isEmpty() || uid.equals("public") || distinguishedName == null
            || distinguishedName.isEmpty()) {
        String message = LOGIN_WARNING;
        forward = "./login.jsp";
        request.setAttribute("message", message);
        request.setAttribute("from", "userBrowseServlet");
    } else {
        forward = "./dataPackageBrowser.jsp";

        String text = null;
        String html = null;
        Integer count = 0;

        try {

            DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid);
            text = dpmClient.listUserDataPackages(distinguishedName);
            StrTokenizer tokens = new StrTokenizer(text);
            html = "<ol>\n";
            EmlPackageIdFormat epif = new EmlPackageIdFormat();

            while (tokens.hasNext()) {
                String packageId = tokens.nextToken();
                EmlPackageId epid = epif.parse(packageId);
                String scope = epid.getScope();
                Integer identifier = epid.getIdentifier();
                Integer revision = epid.getRevision();
                html += String.format(
                        "<li><a class=\"searchsubcat\" href=\"./mapbrowse?scope=%s&identifier=%d&revision=%d\">%s</a></li>\n",
                        scope, identifier, revision, packageId);
                count++;
            }

            html += "</ol>\n";
            request.setAttribute("html", html);
            request.setAttribute("count", count.toString());
            if (count < 1) {
                browseMessage = String.format("No data packages have been uploaded by user '%s'.",
                        distinguishedName);
            }
            request.setAttribute("browsemessage", browseMessage);
        } catch (Exception e) {
            handleDataPortalError(logger, e);
        }
    }

    RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward);
    requestDispatcher.forward(request, response);
}

From source file:edu.lternet.pasta.portal.ScopeBrowseServlet.java

/**
 * The doPost method of the servlet. <br>
 * /*w  w w . ja va2 s .c  o m*/
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request
 *          the request send by the client to the server
 * @param response
 *          the response send by the server to the client
 * @throws ServletException
 *           if an error occurred
 * @throws IOException
 *           if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession httpSession = request.getSession();

    String uid = (String) httpSession.getAttribute("uid");

    if (uid == null || uid.isEmpty())
        uid = "public";

    String text = null;
    String html = null;
    Integer count = 0;

    try {

        DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid);
        text = dpmClient.listDataPackageScopes();

        StrTokenizer tokens = new StrTokenizer(text);

        html = "<ol>\n";

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

        // Add scope values to a sorted set
        while (tokens.hasNext()) {
            String token = tokens.nextToken();
            arrayList.add(token);
            count++;
        }

        // Output sorted set of scope values
        for (String scope : arrayList) {
            html += "<li><a class=\"searchsubcat\" href=\"./identifierbrowse?scope=" + scope + "\">" + scope
                    + "</a></li>\n";
        }

        html += "</ol>\n";
    } catch (Exception e) {
        handleDataPortalError(logger, e);
    }

    request.setAttribute("browsemessage", browseMessage);
    request.setAttribute("html", html);
    request.setAttribute("count", count.toString());
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward);
    requestDispatcher.forward(request, response);

}

From source file:edu.lternet.pasta.portal.IdentifierBrowseServlet.java

/**
 * The doPost method of the servlet. <br>
 * // w w w.  j  a v  a  2s  .co  m
 * This method is called when a form has its tag value method equals to post.
 * 
 * @param request
 *          the request send by the client to the server
 * @param response
 *          the response send by the server to the client
 * @throws ServletException
 *           if an error occurred
 * @throws IOException
 *           if an error occurred
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    HttpSession httpSession = request.getSession();

    String uid = (String) httpSession.getAttribute("uid");

    if (uid == null || uid.isEmpty())
        uid = "public";

    String scope = request.getParameter("scope");

    String text = null;
    String html = null;
    Integer count = 0;

    if (scope != null && !(scope.isEmpty())) {

        try {

            DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid);
            text = dpmClient.listDataPackageIdentifiers(scope);

            StrTokenizer tokens = new StrTokenizer(text);

            html = "<ol>\n";

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

            // Add scope/identifier values to a sorted set
            while (tokens.hasNext()) {
                arrayList.add(tokens.nextToken());
                count++;
            }

            // Output sorted set of scope/identifier values
            for (String identifier : arrayList) {

                html += "<li><a class=\"searchsubcat\" href=\"./mapbrowse?scope=" + scope + "&identifier="
                        + identifier + "\">" + scope + "." + identifier + "</a></li>\n";

            }

            html += "</ol>\n";

        } catch (Exception e) {
            handleDataPortalError(logger, e);
        }

    } else {
        html = "<p class=\"warning\"> Error: \"scope\" field empty</p>\n";
    }

    request.setAttribute("browsemessage", browseMessage);
    request.setAttribute("html", html);
    request.setAttribute("count", count.toString());
    RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward);
    requestDispatcher.forward(request, response);

}

From source file:com.mgmtp.perfload.perfalyzer.PerfAlyzer.java

private void extractFilesForMarkers() {
    if (!markers.isEmpty()) {
        StrTokenizer tokenizer = StrTokenizer.getCSVInstance();
        tokenizer.setDelimiterChar(';');

        listPerfAlyzerFiles(normalizedDir).stream().filter(perfAlyzerFile -> {
            // GC logs cannot split up here and need to explicitly handle markers later.
            // Load profiles contains the markers themselves and thus need to be filtered out as well.
            String fileName = perfAlyzerFile.getFile().getName();
            return !fileName.contains("gclog") & !fileName.contains("[loadprofile]");
        }).forEach(perfAlyzerFile -> markers.forEach(marker -> {
            try {
                PerfAlyzerFile markerFile = perfAlyzerFile.copy();
                markerFile.setMarker(marker.getName());

                Path destPath = normalizedDir.toPath().resolve(markerFile.getFile().toPath());
                WritableByteChannel destChannel = newByteChannel(destPath, CREATE, WRITE);

                Path srcPath = normalizedDir.toPath().resolve(perfAlyzerFile.getFile().toPath());
                NioUtils.lines(srcPath, UTF_8).filter(s -> {
                    tokenizer.reset(s);//from   w w  w.j  ava  2  s . c o  m
                    long timestamp = Long.parseLong(tokenizer.nextToken());
                    return marker.getLeftMillis() <= timestamp && marker.getRightMillis() > timestamp;
                }).forEach(s -> writeLineToChannel(destChannel, s, UTF_8));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }));
    }
}

From source file:org.grouplens.lenskit.data.dao.MapItemNameDAO.java

/**
 * Read an item list DAO from a file.//www .  j ava2s  .  c  o m
 * @param file A file of item IDs, one per line.
 * @return The item list DAO.
 * @throws java.io.IOException if there is an error reading the list of items.
 */
public static MapItemNameDAO fromCSVFile(File file) throws IOException {
    LineCursor cursor = LineCursor.openFile(file, CompressionMode.AUTO);
    try {
        ImmutableMap.Builder<Long, String> names = ImmutableMap.builder();
        StrTokenizer tok = StrTokenizer.getCSVInstance();
        for (String line : cursor) {
            tok.reset(line);
            long item = Long.parseLong(tok.next());
            String title = tok.nextToken();
            if (title != null) {
                names.put(item, title);
            }
        }
        return new MapItemNameDAO(names.build());
    } catch (NoSuchElementException ex) {
        throw new IOException(String.format("%s:%s: not enough columns", file, cursor.getLineNumber()), ex);
    } catch (NumberFormatException ex) {
        throw new IOException(String.format("%s:%s: id not an integer", file, cursor.getLineNumber()), ex);
    } finally {
        cursor.close();
    }
}