List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:com.digitalpebble.behemoth.io.warc.HttpResponse.java
private void processHeaderLine(StringBuilder line) throws IOException { int colonIndex = line.indexOf(":"); // key is up to colon if (colonIndex == -1) { int i;//w ww . j a v a 2 s . c o m for (i = 0; i < line.length(); i++) if (!Character.isWhitespace(line.charAt(i))) break; if (i == line.length()) return; throw new IOException("No colon in header:" + line); } String key = line.substring(0, colonIndex); int valueStart = colonIndex + 1; // skip whitespace while (valueStart < line.length()) { int c = line.charAt(valueStart); if (c != ' ' && c != '\t') break; valueStart++; } String value = line.substring(valueStart); headers.set(key, value); }
From source file:io.vertx.ext.shell.term.TelnetTermServerTest.java
@Test public void testWrite(TestContext context) throws IOException { startTelnet(context, term -> {//w ww.ja v a 2 s . c o m term.write("hello_from_server"); }); client.connect("localhost", server.actualPort()); Reader reader = new InputStreamReader(client.getInputStream()); StringBuilder sb = new StringBuilder("hello_from_server"); while (sb.length() > 0) { int c = reader.read(); context.assertNotEquals(-1, c); context.assertEquals(c, (int) sb.charAt(0)); sb.deleteCharAt(0); } }
From source file:com.github.helenusdriver.driver.impl.SequenceStatementImpl.java
/** * Gets the query strings for this sequence statement. * * @author paouelle// w w w.j a va 2 s. co m * * @return the valid CQL query strings for this sequence statement or * <code>null</code> if nothing to sequence * @throws IllegalArgumentException if the statement is associated with a POJO * and the keyspace has not yet been computed and cannot be * computed with the provided suffixes yet */ protected StringBuilder[] getQueryStrings() { if (isDirty() || (cache == null)) { final StringBuilder[] sbs = buildQueryStrings(); if (sbs == null) { this.cache = null; } else { this.cache = new StringBuilder[sbs.length]; for (int i = 0; i < sbs.length; i++) { final StringBuilder sb = sbs[i]; // Use the same test that String#trim() uses to determine // if a character is a whitespace character. int l = sb.length(); while (l > 0 && sb.charAt(l - 1) <= ' ') { l -= 1; } if (l != sb.length()) { sb.setLength(l); } if (l == 0 || sb.charAt(l - 1) != ';') { sb.append(';'); } this.cache[i] = sb; } } } return cache; }
From source file:fr.ribesg.bukkit.api.chat.Chat.java
private static void appendItemDisplay(final StringBuilder builder, final ItemMeta meta) { builder.append("display{"); if (meta.hasDisplayName()) { builder.append("Name:"); builder.append(Chat.escapeString(meta.getDisplayName())); builder.append(','); }//from w w w .j a va2 s. co m if (meta.hasLore()) { builder.append("Lore:["); final Iterator<String> it = meta.getLore().iterator(); while (it.hasNext()) { builder.append(Chat.escapeString(it.next())); if (it.hasNext()) { builder.append(','); } } builder.append("],"); } if (meta instanceof LeatherArmorMeta) { final LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) meta; builder.append("color:").append(leatherArmorMeta.getColor().asRGB()); } if (builder.charAt(builder.length() - 1) == ',') { builder.deleteCharAt(builder.length() - 1); } builder.append("},"); }
From source file:net.sf.firemox.tools.MToolKit.java
/** * Return the specified string without any local white spaces. Would be * replaced when// w w w . j a va2 s. co m * {@link org.apache.commons.lang.StringUtils#deleteWhitespace(String)} would * work. * * @param string * the string to normalize. * @return the given string without any space char. * @see Character#isWhitespace(char) */ public static String replaceWhiteSpaces(String string) { final StringBuilder workingString = new StringBuilder(StringUtils.deleteWhitespace(string)); for (int count = workingString.length(); count-- > 0;) { if (Character.isSpaceChar(workingString.charAt(count))) { // delete this char workingString.deleteCharAt(count); } } return workingString.toString(); }
From source file:com.android.calendar.alerts.AlertService.java
private static void logEventIdsBumped(List<NotificationInfo> list1, List<NotificationInfo> list2) { StringBuilder ids = new StringBuilder(); if (list1 != null) { for (NotificationInfo info : list1) { ids.append(info.eventId);/*w ww. j ava2 s . c om*/ ids.append(","); } } if (list2 != null) { for (NotificationInfo info : list2) { ids.append(info.eventId); ids.append(","); } } if (ids.length() > 0 && ids.charAt(ids.length() - 1) == ',') { ids.setLength(ids.length() - 1); } if (ids.length() > 0) { Log.d(TAG, "Reached max postings, bumping event IDs {" + ids.toString() + "} to digest."); } }
From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLDOMElement.java
/** * Returns a string that represents the element content. This will also include the text content from all child * elements, concatenated in document order. * @return a string that represents the element content */// w w w .java 2 s. c om @Override public String getText() { final StringBuilder buffer = new StringBuilder(); toText(getDomNodeOrDie(), buffer); if (buffer.length() > 0 && buffer.charAt(buffer.length() - 1) == '\n') { return buffer.substring(0, buffer.length() - 1); } return buffer.toString(); }
From source file:net.sourceforge.fenixedu.util.UniqueAcronymCreator.java
private static void appendLast(StringBuilder acronym) { if (logger.isDebugEnabled()) { logger.info("appendLast, called with " + acronym); }/* w ww .j a v a2 s. c o m*/ for (int i = splitsName.length - 1; i > -1; i--) { if (!isValidAcception(splitsName[i]) && splitsName[i].length() >= 3 && !isValidNumeration(splitsName[i])) { String toAppend = splitsName[i].substring(1, 3); toAppend = (toLowerCase) ? toAppend.toLowerCase() : toAppend.toUpperCase(); if (acronym.toString().contains("-")) { int hiffen = acronym.toString().indexOf("-"); if ((hiffen + 1 < acronym.toString().length()) && (isValidNumeration(String.valueOf(acronym.charAt(hiffen + 1))) || hasNumber(String.valueOf(acronym.charAt(hiffen + 1))))) { acronym.insert(hiffen, toAppend); if (logger.isDebugEnabled()) { logger.info("appendLast, found a '-', appending before hiffen " + toAppend); } } else { acronym.append(toAppend); if (logger.isDebugEnabled()) { logger.info("appendLast, found a '-', appending in end " + toAppend); } } } else { if (logger.isDebugEnabled()) { logger.info("appendLast, appending " + toAppend); } acronym.append(toAppend); } break; } } }
From source file:org.elasticsearch.river.solr.SolrRiver.java
protected StringBuilder createSolrQuery() { StringBuilder queryBuilder = new StringBuilder(solrUrl); if (Strings.hasLength(requestHandler)) { if (queryBuilder.charAt(queryBuilder.length() - 1) != '/') { queryBuilder.append("/"); }// w w w . j a va 2 s . c o m queryBuilder.append(requestHandler); } queryBuilder.append("?q=").append(encode(query)).append("&wt=json"); if (filterQueries != null) { for (String filterQuery : filterQueries) { queryBuilder.append("&fq=").append(encode(filterQuery)); } } if (fields != null) { queryBuilder.append("&fl="); for (int i = 0; i < fields.length; i++) { if (i > 0) { queryBuilder.append(encode(" ")); } queryBuilder.append(encode(fields[i])); } } queryBuilder.append("&rows=").append(rows); return queryBuilder; }
From source file:com.wabacus.system.dataset.update.action.rationaldb.SPUpdateAction.java
public void parseActionScript(String sp, List<AbsUpdateAction> lstUpdateActions, String reportTypeKey) { ReportBean rbean = this.ownerUpdateBean.getOwner().getReportBean(); if (sp.startsWith("{") && sp.endsWith("}")) sp = sp.substring(1, sp.length() - 1).trim(); String procedure = sp.toLowerCase().startsWith("call ") ? sp.substring("call ".length()).trim() : sp.trim(); if (procedure.equals("")) { throw new WabacusConfigLoadingException("" + rbean.getPath() + "?" + sp + "???"); }/*w w w . j ava 2 s . c o m*/ String procname = procedure; List lstProcedureParams = new ArrayList(); int idxLeft = procedure.indexOf("("); if (idxLeft == 0) throw new WabacusConfigLoadingException("" + rbean.getPath() + "?" + sp + "????"); if (idxLeft > 0) { int idxRight = procedure.lastIndexOf(")"); if (idxRight != procedure.length() - 1) throw new WabacusConfigLoadingException("" + rbean.getPath() + "?" + sp + "????"); procname = procedure.substring(0, idxLeft).trim(); String params = procedure.substring(idxLeft + 1, idxRight).trim();//? if (!params.equals("")) { List<String> lstParamsTmp = Tools.parseStringToList(params, ",", new String[] { "'", "'" }, false); Object paramObjTmp; for (String paramTmp : lstParamsTmp) { paramObjTmp = createEditParams(paramTmp, reportTypeKey); if (paramObjTmp instanceof String) { String strParamTmp = ((String) paramObjTmp); if (strParamTmp.startsWith("'") && strParamTmp.endsWith("'")) strParamTmp = strParamTmp.substring(1, strParamTmp.length() - 1); if (strParamTmp.startsWith("\"") && strParamTmp.endsWith("\"")) strParamTmp = strParamTmp.substring(1, strParamTmp.length() - 1); paramObjTmp = strParamTmp; } lstProcedureParams.add(paramObjTmp); } } } StringBuilder tmpBuf = new StringBuilder("{call " + procname + "("); for (int i = 0, len = lstProcedureParams.size(); i < len; i++) { tmpBuf.append("?,"); } if (this.returnValueParamname != null && !this.returnValueParamname.trim().equals("")) tmpBuf.append("?"); if (tmpBuf.charAt(tmpBuf.length() - 1) == ',') tmpBuf.deleteCharAt(tmpBuf.length() - 1); tmpBuf.append(")}"); this.sqlsp = tmpBuf.toString(); this.lstParams = lstProcedureParams; lstUpdateActions.add(this); }