List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:net.fender.sql.WeightedLoadBalancingDataSource.java
@Override public void init() throws Exception { super.init(); if (dataSources == null || weights == null) { throw new IllegalStateException("dataSources and weights must not be null"); }//from ww w .ja v a 2 s .c om StringTokenizer parser = new StringTokenizer(weights, ","); if (dataSources.size() != parser.countTokens()) { throw new IllegalStateException("dataSources and weights must be the same size"); } List<DataSource> temp = new ArrayList<DataSource>(); int bucket = 0; Iterator<DataSource> d = dataSources.iterator(); while (parser.hasMoreTokens()) { int weight = Integer.parseInt(parser.nextToken().trim()); DataSource dataSource = d.next(); for (int j = bucket; j < bucket + weight; j++) { temp.add(dataSource); } bucket += weight; } size = temp.size(); buckets = temp.toArray(new DataSource[size]); }
From source file:net.grinder.util.VersionNumber.java
/** * Parses a string like "1.0.2" into the version number. * * @param num parameter string//from w w w . ja va 2 s .com */ public VersionNumber(String num) { StringTokenizer tokens = new StringTokenizer(num, ".-_"); this.digits = new int[tokens.countTokens()]; if (this.digits.length < 2) { throw new IllegalArgumentException("Failed to parse " + num + " as version number"); } int i = 0; while (tokens.hasMoreTokens()) { String token = tokens.nextToken().toLowerCase(); if (token.equals("*")) { this.digits[i++] = 1000; } else if (StringUtils.startsWithIgnoreCase(token, "snapshot")) { this.digits[i - 1]--; //noinspection UnusedAssignment this.digits[i++] = 1000; break; } else { if (NumberUtils.isNumber(token)) { this.digits[i++] = Integer.parseInt(token); } } } }
From source file:it.grid.storm.authz.sa.model.FileAuthzDB.java
private void populateHeader() { this.authzDBType = SAAuthzType.getSAType(authzDB.getString("Type")); String[] version = authzDB.getStringArray("Version"); if (version != null) { String versionNr = version[0]; StringTokenizer versionsNr = new StringTokenizer(versionNr, ".", false); if (versionsNr.countTokens() > 0) { this.majorVersion = Integer.parseInt(versionsNr.nextToken()); this.minorVersion = Integer.parseInt(versionsNr.nextToken()); }/*from w w w.ja va 2 s . c om*/ if (version.length > 1) { this.versionDescription = version[1]; } } }
From source file:com.github.maoo.indexer.dao.IndexingDaoJMX.java
private Set<String> tokenizeString(String str) { Set<String> tokens = null; StringTokenizer tokenizer = new StringTokenizer(str, DELIMITER); if (tokenizer.countTokens() > 0) { tokens = new HashSet<String>(); while (tokenizer.hasMoreTokens()) { tokens.add(tokenizer.nextToken().trim()); }//from w ww . j a va2 s. c o m } return tokens; }
From source file:ome.services.formats.OmeroReader.java
public boolean isThisType(String name, boolean open) { StringTokenizer st = new StringTokenizer(name, "\n"); return st.countTokens() == 5; // TODO what is this? }
From source file:edu.umass.cs.msocket.proxy.console.commands.GroupMemberList.java
@Override public void parse(String commandText) throws Exception { UniversalGnsClient gnsClient = module.getGnsClient(); try {// ww w . ja v a 2 s .c o m StringTokenizer st = new StringTokenizer(commandText.trim()); String groupGuid; if (st.countTokens() == 0) { groupGuid = module.getAccountGuid().getGuid(); } else if (st.countTokens() == 1) { groupGuid = st.nextToken(); if (!GnsUtils.isValidGuidString(groupGuid)) { // We probably have an alias, lookup the GUID groupGuid = gnsClient.lookupGuid(groupGuid); } } else { console.printString("Wrong number of arguments for this command.\n"); return; } console.printString("Members in group " + groupGuid); console.printNewline(); JSONArray members = gnsClient.groupGetMembers(groupGuid, module.getAccountGuid()); for (int i = 0; i < members.length(); i++) { console.printString(i + ": " + members.getString(i)); console.printNewline(); } } catch (Exception e) { console.printString("Failed to access GNS ( " + e + ")\n"); } }
From source file:edu.ku.brc.helpers.EMailHelper.java
/** * Send an email. Also sends it as a gmail if applicable, and does password checking. * @param host host of SMTP server/*from w w w . ja v a2 s . c o m*/ * @param uName username of email account * @param pWord password of email account * @param fromEMailAddr the email address of who the email is coming from typically this is the same as the user's email * @param toEMailAddr the email addr of who this is going to * @param subject the Textual subject line of the email * @param bodyText the body text of the email (plain text???) * @param fileAttachment and optional file to be attached to the email * @return true if the msg was sent, false if not */ public static boolean sendMsgAsGMail(final String host, final String uName, final String pWord, final String fromEMailAddr, final String toEMailAddr, final String subject, final String bodyText, final String mimeType, @SuppressWarnings("unused") final String port, @SuppressWarnings("unused") final String security, final File fileAttachment) { String userName = uName; String password = pWord; Boolean fail = false; ArrayList<String> userAndPass = new ArrayList<String>(); Properties props = System.getProperties(); props.put("mail.smtp.host", host); //$NON-NLS-1$ props.put("mail.smtp.auth", "true"); //$NON-NLS-1$ //$NON-NLS-2$ props.put("mail.smtp.port", "587"); //$NON-NLS-1$ //$NON-NLS-2$ props.put("mail.smtp.starttls.enable", "true"); //$NON-NLS-1$ //$NON-NLS-2$ boolean usingSSL = false; if (usingSSL) { props.put("mail.smtps.port", "587"); //$NON-NLS-1$ //$NON-NLS-2$ props.put("mail.smtp.starttls.enable", "true"); //$NON-NLS-1$ //$NON-NLS-2$ } Session session = Session.getInstance(props, null); session.setDebug(instance.isDebugging); if (instance.isDebugging) { log.debug("Host: " + host); //$NON-NLS-1$ log.debug("UserName: " + userName); //$NON-NLS-1$ log.debug("Password: " + password); //$NON-NLS-1$ log.debug("From: " + fromEMailAddr); //$NON-NLS-1$ log.debug("To: " + toEMailAddr); //$NON-NLS-1$ log.debug("Subject: " + subject); //$NON-NLS-1$ } try { // create a message MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(fromEMailAddr)); if (toEMailAddr.indexOf(",") > -1) //$NON-NLS-1$ { StringTokenizer st = new StringTokenizer(toEMailAddr, ","); //$NON-NLS-1$ InternetAddress[] address = new InternetAddress[st.countTokens()]; int i = 0; while (st.hasMoreTokens()) { String toStr = st.nextToken().trim(); address[i++] = new InternetAddress(toStr); } msg.setRecipients(Message.RecipientType.TO, address); } else { InternetAddress[] address = { new InternetAddress(toEMailAddr) }; msg.setRecipients(Message.RecipientType.TO, address); } msg.setSubject(subject); //msg.setContent( aBodyText , "text/html;charset=\"iso-8859-1\""); // create the second message part if (fileAttachment != null) { // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setContent(bodyText, mimeType);//"text/html;charset=\"iso-8859-1\""); //mbp1.setContent(bodyText, "text/html;charset=\"iso-8859-1\""); MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(fileAttachment); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); } else { // add the Multipart to the message msg.setContent(bodyText, mimeType); } // set the Date: header msg.setSentDate(new Date()); // send the message int cnt = 0; do { cnt++; SMTPTransport t = (SMTPTransport) session.getTransport("smtp"); //$NON-NLS-1$ try { t.connect(host, userName, password); t.sendMessage(msg, msg.getAllRecipients()); fail = false; } catch (MessagingException mex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(EMailHelper.class, mex); instance.lastErrorMsg = mex.toString(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); instance.lastErrorMsg = instance.lastErrorMsg + ", " + ex.toString(); //$NON-NLS-1$ } //wrong username or password, get new one if (mex.toString().equals("javax.mail.AuthenticationFailedException")) //$NON-NLS-1$ { fail = true; userAndPass = askForUserAndPassword((Frame) UIRegistry.getTopWindow()); if (userAndPass == null) {//the user is done return false; } // else //try again userName = userAndPass.get(0); password = userAndPass.get(1); } } finally { log.debug("Response: " + t.getLastServerResponse()); //$NON-NLS-1$ t.close(); } } while (fail && cnt < 6); } catch (MessagingException mex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(EMailHelper.class, mex); instance.lastErrorMsg = mex.toString(); //mex.printStackTrace(); Exception ex = null; if ((ex = mex.getNextException()) != null) { ex.printStackTrace(); instance.lastErrorMsg = instance.lastErrorMsg + ", " + ex.toString(); //$NON-NLS-1$ } return false; } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(EMailHelper.class, ex); ex.printStackTrace(); } if (fail) { return false; } //else return true; }
From source file:org.urlshortener.core.dao.rest.UrlShortenerWsDAOImpl.java
/** * //ww w . j a va 2s . c om * @param url * @return */ private String prepareUrl(String url) { String result = url; final StringTokenizer st = new StringTokenizer(url, "\n\r"); if (st.countTokens() == 1) { result = st.nextToken(); } return result; }
From source file:com.alkacon.opencms.documentcenter.CategoryTree.java
/** * Turns comma-separated string into a List of strings.<p> * /*www . j ava 2 s . c o m*/ * @param str the string to be split * @param sep a separator character * @return a List of tokens */ public static List commaStringToList(String str, String sep) { List result = null; StringTokenizer tokenizer = null; if (str != null) { tokenizer = new StringTokenizer(str, sep); result = new ArrayList(tokenizer.countTokens()); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken()); } Collections.sort(result); } else { result = new ArrayList(); } return result; }
From source file:org.sonar.server.charts.deprecated.CustomBarChart.java
private void configureColors(String colorsParam) { Paint[] colors = CustomBarRenderer.COLORS; if (colorsParam != null && colorsParam.length() > 0) { StringTokenizer stColors = new StringTokenizer(colorsParam, ","); colors = new Paint[stColors.countTokens()]; int i = 0; while (stColors.hasMoreTokens()) { colors[i] = Color.decode("0x" + stColors.nextToken()); i++;//from w ww .j ava 2 s.co m } } renderer.setColors(colors); }