Example usage for java.util StringTokenizer hasMoreElements

List of usage examples for java.util StringTokenizer hasMoreElements

Introduction

In this page you can find the example usage for java.util StringTokenizer hasMoreElements.

Prototype

public boolean hasMoreElements() 

Source Link

Document

Returns the same value as the hasMoreTokens method.

Usage

From source file:Stroke.HeadAction.java

public String saveData() {
    HeadOperation headoperation = new HeadOperation();
    Long a;/*from w ww  . j a  v  a  2  s . c  o  m*/
    StringTokenizer st;
    ContactPerson co = new ContactPerson();
    Set<ContactPerson> cp = new HashSet();
    st = new StringTokenizer(contactno, ",");

    while (st.hasMoreElements()) {
        String str = st.nextToken().trim();
        a = Long.parseLong(str);
        co.setContactno(a);
        co.setPersonid(head.getPersonid());
        cp.add(co);
        head.setContact(cp);
    }
    try {

        String filePath = servletRequest.getSession().getServletContext().getRealPath("/uploadedImages/");
        File fileToCreate = new File(filePath, this.userImageFileName);
        FileUtils.copyFile(this.userImage, fileToCreate);
        byte[] bFile = new byte[(int) fileToCreate.length()];
        try (FileInputStream fileInputStream = new FileInputStream(fileToCreate)) {
            fileInputStream.read(bFile);
        }

        String fname = "uploadedImages/" + userImageFileName;
        head.setImagename(fname);
        head.setHeadimg(bFile);
    } catch (IOException e) {
        return INPUT;
    }

    boolean save = headoperation.insertDetails(head);
    if (save) {
        addActionMessage("SUCCESSFULLY INSERTED");
        return SUCCESS;
    } else {
        addActionError("Not inserted");
        return ERROR;
    }

}

From source file:com.bitsofproof.supernode.core.IRCDiscovery.java

@Override
public List<InetSocketAddress> discover() {
    List<InetSocketAddress> al = new ArrayList<InetSocketAddress>();

    try {//from w w  w  . j a v  a2  s.com
        log.trace("Connect to IRC server " + server);
        Socket socket = new Socket(server, port);
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));

        String[] answers = new String[] { "Found your hostname", "using your IP address instead",
                "Couldn't look up your hostname", "ignoring hostname" };
        String line;
        boolean stop = false;
        while (!stop && (line = reader.readLine()) != null) {
            log.trace("IRC receive " + line);
            for (int i = 0; i < answers.length; ++i) {
                if (line.contains(answers[i])) {
                    stop = true;
                    break;
                }
            }
        }

        String nick = "bop" + new SecureRandom().nextInt(Integer.MAX_VALUE);
        writer.println("NICK " + nick);
        writer.println("USER " + nick + " 8 * : " + nick);
        writer.flush();
        log.trace("IRC send: I am " + nick);

        while ((line = reader.readLine()) != null) {
            log.trace("IRC receive " + line);
            if (hasCode(line, new String[] { " 004 ", " 433 " })) {
                break;
            }
        }
        log.trace("IRC send: joining " + channel);
        writer.println("JOIN " + channel);
        writer.println("NAMES");
        writer.flush();
        while ((line = reader.readLine()) != null) {
            log.trace("IRC receive " + line);
            if (hasCode(line, new String[] { " 353 " })) {
                StringTokenizer tokenizer = new StringTokenizer(line, ":");
                String t = tokenizer.nextToken();
                if (tokenizer.hasMoreElements()) {
                    t = tokenizer.nextToken();
                }
                tokenizer = new StringTokenizer(t);
                tokenizer.nextToken();
                while (tokenizer.hasMoreTokens()) {
                    String w = tokenizer.nextToken().substring(1);
                    if (!tokenizer.hasMoreElements()) {
                        continue;
                    }
                    try {
                        byte[] m = ByteUtils.fromBase58WithChecksum(w);
                        byte[] addr = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xff, (byte) 0xff, 0, 0,
                                0, 0 };
                        System.arraycopy(m, 0, addr, 12, 4);
                        al.add(new InetSocketAddress(InetAddress.getByAddress(addr), chain.getPort()));
                    } catch (ValidationException e) {
                        log.trace(e.toString());
                    }
                }
            }
            if (hasCode(line, new String[] { " 366 " })) {
                break;
            }
        }
        writer.println("PART " + channel);
        writer.println("QUIT");
        writer.flush();
        socket.close();
    } catch (UnknownHostException e) {
        log.error("Can not find IRC server " + server, e);
    } catch (IOException e) {
        log.error("Can not use IRC server " + server, e);
    }

    return al;
}

From source file:org.dcm4chex.archive.web.maverick.Dcm4cheeFormController.java

public boolean isStudyPermissionCheckDisabled() {
    ControllerContext ctx = getCtx();// w  ww. ja va  2  s .  com
    if ("false".equals(ctx.getServletConfig().getInitParameter("enableStudyPermissionCheck"))) {
        log.debug("StudyPermission check is disabled!");
        return true;
    }
    String disableUser = ctx.getServletConfig().getInitParameter("disableStudyPermissionCheckForUser");
    if (disableUser == null || disableUser.trim().length() < 1 || "NONE".equalsIgnoreCase(disableUser))
        return false;
    String user = ctx.getRequest().getUserPrincipal().getName();
    StringTokenizer st = new StringTokenizer(disableUser, ",");
    while (st.hasMoreElements()) {
        if (user.equals(st.nextToken())) {
            log.debug("StudyPermission check is disabled for user " + user + "!");
            return true;
        }
    }
    return false;
}

From source file:org.picketlink.social.facebook.FacebookProcessor.java

public void setRoleString(String roleStr) {
    if (roleStr == null)
        throw new RuntimeException("Role String is null in configuration");
    StringTokenizer st = new StringTokenizer(roleStr, ",");
    while (st.hasMoreElements()) {
        roles.add(st.nextToken());/* w  w  w .  j ava 2 s .  c  o  m*/
    }
}

From source file:org.apache.jcs.auxiliary.remote.RemoteCacheFactory.java

/**
 * For LOCAL clients we get a handle to all the failovers, but we do not register a listener
 * with them. We create the RemoteCacheManager, but we do not get a cache. The failover runner
 * will get a cache from the manager. When the primary is restored it will tell the manager for
 * the failover to deregister the listener.
 * <p>//from  w  w w.  j a va2s .c  o  m
 * (non-Javadoc)
 * @see org.apache.jcs.auxiliary.AuxiliaryCacheFactory#createCache(org.apache.jcs.auxiliary.AuxiliaryCacheAttributes,
 *      org.apache.jcs.engine.behavior.ICompositeCacheManager)
 */
public AuxiliaryCache createCache(AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr) {
    RemoteCacheAttributes rca = (RemoteCacheAttributes) iaca;

    ArrayList noWaits = new ArrayList();

    // if LOCAL
    if (rca.getRemoteType() == RemoteCacheAttributes.LOCAL) {
        // a list toi be turned into an array of failover server information
        ArrayList failovers = new ArrayList();

        // not necessary if a failover list is defined
        // REGISTER PRIMARY LISTENER
        // if it is a primary
        boolean primayDefined = false;
        if (rca.getRemoteHost() != null) {
            primayDefined = true;

            failovers.add(rca.getRemoteHost() + ":" + rca.getRemotePort());

            RemoteCacheManager rcm = RemoteCacheManager.getInstance(rca, cacheMgr);
            ICache ic = rcm.getCache(rca);
            if (ic != null) {
                noWaits.add(ic);
            } else {
                log.info("noWait is null");
            }
        }

        // GET HANDLE BUT DONT REGISTER A LISTENER FOR FAILOVERS
        String failoverList = rca.getFailoverServers();
        if (failoverList != null) {
            StringTokenizer fit = new StringTokenizer(failoverList, ",");
            int fCnt = 0;
            while (fit.hasMoreElements()) {
                fCnt++;

                String server = (String) fit.nextElement();
                failovers.add(server);

                rca.setRemoteHost(server.substring(0, server.indexOf(":")));
                rca.setRemotePort(Integer.parseInt(server.substring(server.indexOf(":") + 1)));
                RemoteCacheManager rcm = RemoteCacheManager.getInstance(rca, cacheMgr);
                // add a listener if there are none, need to tell rca what
                // number it is at
                if ((!primayDefined && fCnt == 1) || noWaits.size() <= 0) {
                    ICache ic = rcm.getCache(rca);
                    if (ic != null) {
                        noWaits.add(ic);
                    } else {
                        log.info("noWait is null");
                    }
                }
            }
            // end while
        }
        // end if failoverList != null

        rca.setFailovers((String[]) failovers.toArray(new String[0]));

        // if CLUSTER
    } else if (rca.getRemoteType() == RemoteCacheAttributes.CLUSTER) {
        // REGISTER LISTENERS FOR EACH SYSTEM CLUSTERED CACHEs
        StringTokenizer it = new StringTokenizer(rca.getClusterServers(), ",");
        while (it.hasMoreElements()) {
            // String server = (String)it.next();
            String server = (String) it.nextElement();
            // p( "tcp server = " + server );
            rca.setRemoteHost(server.substring(0, server.indexOf(":")));
            rca.setRemotePort(Integer.parseInt(server.substring(server.indexOf(":") + 1)));
            RemoteCacheManager rcm = RemoteCacheManager.getInstance(rca, cacheMgr);
            rca.setRemoteType(RemoteCacheAttributes.CLUSTER);
            ICache ic = rcm.getCache(rca);
            if (ic != null) {
                noWaits.add(ic);
            } else {
                log.info("noWait is null");
            }
        }

    }
    // end if CLUSTER

    RemoteCacheNoWaitFacade rcnwf = new RemoteCacheNoWaitFacade(
            (RemoteCacheNoWait[]) noWaits.toArray(new RemoteCacheNoWait[0]), rca, cacheMgr);

    getFacades().put(rca.getCacheName(), rcnwf);

    return rcnwf;
}

From source file:org.exoplatform.wiki.rendering.macro.jira.JiraIssueMacroParameters.java

@PropertyDescription("JIRA Field Columns to Display. Sample: type,key,summary")
public void setColumns(String columns) {
    if (StringUtils.isEmpty(columns)) {
        return;//from  w ww .  j  a  v a  2  s  .c om
    }

    StringTokenizer tokenizer = new StringTokenizer(columns, ",");
    if (this.columns == null) {
        this.columns = new ArrayList<String>();
    } else {
        this.columns.clear();
    }

    while (tokenizer.hasMoreElements()) {
        String field = ((String) tokenizer.nextElement()).trim();
        if (!StringUtils.isEmpty(field)) {
            this.columns.add(field);
        }
    }
}

From source file:Main.java

/**
 * Parses the given name and returns the name elements as List of Strings.
 *
 * @param name the name, that should be parsed.
 * @return the parsed name.//w  w  w .  j ava 2s. c  om
 */
private List parseName(final String name) {
    final ArrayList list = new ArrayList();
    final StringTokenizer strTok = new StringTokenizer(name, "/");
    while (strTok.hasMoreElements()) {
        final String s = (String) strTok.nextElement();
        if (s.length() != 0) {
            list.add(s);
        }
    }
    return list;
}

From source file:gtu._work.ui.RetryByPassUI.java

private void readMessageId() {
    StringBuilder sb = new StringBuilder();
    try {//from w  w w.  j a  v  a  2  s.c om
        String county = (String) countryComboBox.getSelectedItem();
        if (StringUtils.isBlank(county)) {
            showMessage("??");
        }
        String type = (String) passRetryComboBox.getSelectedItem();
        if (StringUtils.isBlank(type)) {
            showMessage("???");
        }
        String messageIdAreaStr = messageIdArea.getText();
        if (StringUtils.isBlank(messageIdAreaStr)) {
            showMessage("messageId");
        }
        String ip = "";
        String region = "";
        String port = "";
        for (CountyEnum e : CountyEnum.values()) {
            if (e.countyLabel.equals(county)) {
                ip = e.ip;
                region = e.region;
                port = e.port;
                break;
            }
        }

        List<String> messageIdList = new ArrayList<String>();
        StringTokenizer tokenizer = new StringTokenizer(messageIdAreaStr);
        for (; tokenizer.hasMoreElements();) {
            String val = (String) tokenizer.nextElement();
            messageIdList.add(val);
        }

        for (String messageId : messageIdList) {
            String urlStr = String.format("http://%1$s:%2$s/%3$s/version?MQ=%4$s:%5$s", ip, port, region, type,
                    messageId);
            setLog("URL ==> " + urlStr, sb);

            URL url_address = new URL(urlStr);
            BufferedReader br = new BufferedReader(new InputStreamReader(url_address.openStream(), "UTF-8"));
            for (String line = null; (line = br.readLine()) != null;) {
                setLog(line, sb);
            }
            setLog("***************************************************************", sb);
            setLog("***************************************************************", sb);
            br.close();
        }

        showMessage("?!!");
    } catch (Exception e) {
        //            JCommonUtil.handleException(e);
        showMessage(e.toString());
    }
}

From source file:org.cloudifysource.cloudformation.converter.api.RestFacade.java

/**
 * Connect the Cloudify REST Gateway.//from   ww  w  .  j av  a  2  s .  com
 * 
 * @param user
 *            The user if security is enabled.
 * @param password
 *            The password if security is enabled.
 * @param urlString
 *            The url to Cloudify REST Gateway.
 * @param gsVersion
 *            Cloudify version.
 * @throws RestException
 *             If a REST error occurs
 * @throws RestClientException
 *             If a REST error occurs
 * @throws MalformedURLException
 *             If the url is malformed.
 */
public void connect(final String user, final String password, final String urlString, final String gsVersion)
        throws RestException, RestClientException, MalformedURLException {
    if (urlString == null) {
        throw new IllegalStateException("Cannot conncet to a cloudify manager (url=null).");
    }
    final URL url = new URL(urlString.startsWith("http") ? urlString : "http://" + urlString);
    final StringTokenizer tokenizer = new StringTokenizer(gsVersion == null ? "" : gsVersion, "-");
    final CloudifyVersion cloudifyVersion = new CloudifyVersion();
    final String version = tokenizer.hasMoreElements() ? tokenizer.nextToken() : cloudifyVersion.getVersion();
    final String edition = tokenizer.hasMoreElements() ? tokenizer.nextToken() : cloudifyVersion.getEdition();
    final String milestone = tokenizer.hasMoreElements() ? tokenizer.nextToken()
            : cloudifyVersion.getMilestone();
    final String versionNumber = version + "-" + edition + "-" + milestone;
    logger.fine(String.format("Connected to REST using url=%s, user=%s, version=%s", urlString, user, version));
    this.client = new GSRestClient(user, password, url, versionNumber);
    this.newRestClient = new RestClient(url, user, password, version);
    client.get(SERVICE_CONTROLLER_URL + "testrest");
    if (StringUtils.isNotEmpty(user) || StringUtils.isNotEmpty(password)) {
        this.reconnect(user, password);
    }
}