List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:org.atricore.idbus.capabilities.clientcertauthn.X509CertificateAuthScheme.java
/** * Parses a Compound name/*w ww .ja v a 2 s . c o m*/ * (ie. CN=Java Duke, OU=Java Software Division, O=Sun Microsystems Inc, C=US) and * builds a HashMap object with key-value pairs. * * @param s a string containing the compound name to be parsed * @return a HashMap object built from the parsed key-value pairs * @throws IllegalArgumentException if the compound name * is invalid */ private HashMap parseCompoundName(String s) { String valArray[] = null; if (s == null) { throw new IllegalArgumentException(); } HashMap hm = new HashMap(); // Escape characters noticed, so use "extended/escaped parser" if ((s.indexOf("\"") > 0) || (s.indexOf("\\") > 0)) { StringBuffer sb = new StringBuffer(s); boolean escaped = false; StringBuffer buff = new StringBuffer(); String key = ""; String value = ""; for (int i = 0; i < sb.length(); i++) { // Quotes are begin/end, so keep a flag of escape-state if ('"' == sb.charAt(i)) { if (escaped) { escaped = false; continue; } else { escaped = true; continue; } // Single-character escape/advance // but check the length, too. } else if ('\\' == sb.charAt(i)) { i++; if (i >= sb.length()) { break; } // Split on '=' between key/value } else if ('=' == sb.charAt(i)) { key = buff.toString(); buff = new StringBuffer(); continue; // We've reached a valid delimiter, as long as we're not // still reading 'escaped' data } else if ((',' == sb.charAt(i)) && (!escaped)) { value = buff.toString(); buff = new StringBuffer(); key = key.trim().toLowerCase(); value = value.trim(); hm.put(key, value); continue; } buff.append(sb.charAt(i)); } // for... // And the last one... value = buff.toString(); key = key.trim().toLowerCase(); value = value.trim(); hm.put(key, value); } else { // Otherwise, no (known) escape characters, so continue on with // the faster parse. StringTokenizer st = new StringTokenizer(s, ","); while (st.hasMoreTokens()) { String pair = (String) st.nextToken(); int pos = pair.indexOf('='); if (pos == -1) { // XXX // should give more detail about the illegal argument throw new IllegalArgumentException(); } String key = pair.substring(0, pos).trim().toLowerCase(); String val = pair.substring(pos + 1, pair.length()).trim(); hm.put(key, val); } } return hm; }
From source file:com.stimulus.archiva.language.NGramProfile.java
/** * Analyze a piece of text/*from ww w . j a v a 2s. c o m*/ * * @param text the text to be analyzed */ public void analyze(StringBuffer text) { if (ngrams != null) { ngrams.clear(); sorted = null; ngramcounts = null; } word.clear().append(SEPARATOR); for (int i = 0; i < text.length(); i++) { char c = Character.toLowerCase(text.charAt(i)); if (Character.isLetter(c)) { add(word.append(c)); } else { //found word boundary if (word.length() > 1) { //we have a word! add(word.append(SEPARATOR)); word.clear().append(SEPARATOR); } } } if (word.length() > 1) { //we have a word! add(word.append(SEPARATOR)); } normalize(); }
From source file:GIST.IzbirkomExtractor.AbbrList.java
/** * Creates a list of all possible expansions of a given streetName. * stretName itself will be the first element of the expansion list. * //w ww. j ava2 s . co m * @param streetName * @return */ public ArrayList<String> createAllExpansions(String streetName) { ArrayList<String> expansions = new ArrayList<String>(); expansions.add(streetName); Matcher mat = getAbbreviationsPattern().matcher(streetName); if (mat.find()) { for (String exp : abbrevs.get(mat.group(1)).getExpansions()) { StringBuffer str = new StringBuffer(mat.replaceFirst(exp)); /* get rid of abbreviations with dash */ if (streetName.length() > mat.start(1) + 1 && streetName.charAt(mat.start(1) + 1) == '-') { str.setCharAt(mat.start(1) + exp.length(), ' '); } if (exp.endsWith("-")) { // support for ?-, ?-, -; remove space, downcase following letter /* skip replacement and the end of string */ if (str.toString().endsWith(exp)) continue; str.delete(mat.start(1) + exp.length() - 1, mat.start(1) + exp.length() + 1); char upcase = str.charAt(mat.start(1) + exp.length() - 1); str.setCharAt(mat.start(1) + exp.length() - 1, Character.toLowerCase(upcase)); } expansions.add(str.toString()); } } return expansions; }
From source file:it.cnr.icar.eric.server.common.Utility.java
/** * Removes the <?xml version="1.0"?> decalaration from XML string * @return the XML declaration// ww w. j a v a 2 s. c om */ public String removeXMLDeclaration(StringBuffer str) { String decl = ""; int len = str.length(); int startIndex = -1; //start of what we are removing int endIndex = -1; //end of what we are removing for (int i = 0; i < len; i++) { if (str.charAt(i) == '<') { decl += "<"; startIndex = i; //Skip spaces after '<' i++; while (str.charAt(i) == ' ') { decl += " "; i++; } if (str.charAt(i) == '?') { //We have an XML declaration to remove //Skip forward and find matching '>' while (str.charAt(i) != '>') { decl += str.charAt(i); i++; } decl += ">"; endIndex = i; break; } else { //Not an XML declaration startIndex = -1; break; } } } if (startIndex != -1) { str.delete(startIndex, endIndex + 1); } return decl; }
From source file:com.wabacus.system.component.application.report.configbean.crosslist.CrossListReportDynDatasetBean.java
private String getDynamicCrossStatiSelectColsWithVerticalStati(Map<String, String> mAllSelectCols) { if (this.lstIncludeCrossStatiColAndGroupBeans == null || lstIncludeCrossStatiColAndGroupBeans.size() == 0) return ""; if (mAllSelectCols == null || mAllSelectCols.size() == 0) return ""; StringBuffer resultBuf = new StringBuffer(); String selectColsTmp;//from w w w . ja va2 s.c o m for (AbsCrossListReportColAndGroupBean colgroupBeanTmp : lstIncludeCrossStatiColAndGroupBeans) { if (!colgroupBeanTmp.getInnerDynamicColBean().isHasVerticalstatistic()) continue; selectColsTmp = mAllSelectCols.get(colgroupBeanTmp.getRootCrossColGroupId()); if (selectColsTmp == null || selectColsTmp.trim().equals("")) continue; resultBuf.append(selectColsTmp).append(","); } if (resultBuf.length() > 0 && resultBuf.charAt(resultBuf.length() - 1) == ',') resultBuf.deleteCharAt(resultBuf.length() - 1); return resultBuf.toString(); }
From source file:org.opennms.netmgt.mib2events.Mib2Events.java
public Logmsg getTrapEventLogmsg(MibValueSymbol trapValueSymbol) { Logmsg msg = new Logmsg(); msg.setDest("logndisplay"); final StringBuffer dbuf = new StringBuffer(); dbuf.append("<p>"); dbuf.append("\n"); dbuf.append("\t").append(trapValueSymbol.getName()).append(" trap received\n"); int vbNum = 1; for (MibValue vb : getTrapVars(trapValueSymbol)) { dbuf.append("\t").append(vb.getName()).append("=%parm[#").append(vbNum).append("]%\n"); vbNum++;/*from w w w . ja v a2 s. c om*/ } if (dbuf.charAt(dbuf.length() - 1) == '\n') { dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end } dbuf.append("</p>\n\t"); msg.setContent(dbuf.toString()); return msg; }
From source file:net.fenyo.gnetwatch.activities.Capture.java
/** * Reads tethereal standard output and extracts frames one by one. * @param none./*ww w.ja v a 2 s . co m*/ * @return void. */ // Capture thread public void run() { final StringBuffer packet = new StringBuffer(); try { cmd.fork(); forked = true; while (!config.isEnd() && !must_end) { // on doit pouvoir optimiser en utilisant un StringBuffer pour str final String str = cmd.readLineStdout(); if (str == null) break; packet.append(str); // log.debug("[" + str + "]"); // replaces invalid XML characters with ' ' for (int idx = 0; idx < packet.length(); idx++) // http://www.w3.org/TR/REC-xml/#charsets if (packet.charAt(idx) != 9 && packet.charAt(idx) != 10 && packet.charAt(idx) != 13 && packet.charAt(idx) < 32) packet.setCharAt(idx, ' '); if (str.contains("</packet>")) { try { handlePacket(packet); } catch (final DocumentException ex) { log.warn("Exception", ex); } packet.setLength(0); } } } catch (final IOException ex) { log.warn("Exception", ex); } catch (final InterruptedException ex) { // terminate the thread } finally { forked = true; } }
From source file:TarInputStream.java
/** * Determine the number of bytes in an entry name. * //from w w w. java 2 s. c o m * @param header * The header buffer from which to parse. * @param offset * The offset into the buffer from which to parse. * @param length * The number of header bytes to parse. * @return The number of bytes in a header's entry name. */ public static int getNameBytes(StringBuffer name, byte[] buf, int offset, int length) { int i; for (i = 0; i < length && i < name.length(); ++i) { buf[offset + i] = (byte) name.charAt(i); } for (; i < length; ++i) { buf[offset + i] = 0; } return offset + length; }
From source file:com.wabacus.system.dataset.select.report.value.RelationalDBReportDataSetValueProvider.java
private String parseStatiSqlWithoutCondition(List<StatisticItemBean> lstStatitemBeansWithoutCondition, String sql) {/* w w w. ja va2s.c o m*/ if (lstStatitemBeansWithoutCondition == null || lstStatitemBeansWithoutCondition.size() == 0) return ""; StringBuffer statisticColumnsBuf = new StringBuffer(); for (StatisticItemBean statItemBeanTmp : lstStatitemBeansWithoutCondition) { statisticColumnsBuf.append(statItemBeanTmp.getValue()).append(" as ") .append(statItemBeanTmp.getProperty()).append(","); } if (statisticColumnsBuf.length() > 0 && statisticColumnsBuf.charAt(statisticColumnsBuf.length() - 1) == ',') { statisticColumnsBuf.deleteCharAt(statisticColumnsBuf.length() - 1); } String sqlStati = ""; if (statisticColumnsBuf.length() > 0) { sqlStati = "select " + statisticColumnsBuf.toString() + " from (" + sql + ") wx_tableStati"; } return sqlStati; }
From source file:net.sf.jabref.logic.groups.KeywordGroup.java
/** * Removes matches of searchString in the entry's field. This is only * possible if the search expression is not a regExp. *//*from w ww .j a v a 2s . com*/ private void removeMatches(BibEntry entry) { if (!entry.hasField(searchField)) { return; // nothing to modify } String content = entry.getField(searchField); StringBuffer sbOrig = new StringBuffer(content); StringBuffer sbLower = new StringBuffer(content.toLowerCase()); StringBuffer haystack = caseSensitive ? sbOrig : sbLower; String needle = caseSensitive ? searchExpression : searchExpression.toLowerCase(); int i; int j; int k; final String separator = jabRefPreferences.get(JabRefPreferences.KEYWORD_SEPARATOR); while ((i = haystack.indexOf(needle)) >= 0) { sbOrig.replace(i, i + needle.length(), ""); sbLower.replace(i, i + needle.length(), ""); // reduce spaces at i to 1 j = i; k = i; while (((j - 1) >= 0) && (separator.indexOf(haystack.charAt(j - 1)) >= 0)) { --j; } while ((k < haystack.length()) && (separator.indexOf(haystack.charAt(k)) >= 0)) { ++k; } sbOrig.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : ""); sbLower.replace(j, k, (j >= 0) && (k < sbOrig.length()) ? separator : ""); } String result = sbOrig.toString().trim(); if (result.isEmpty()) { entry.clearField(searchField); } else { entry.setField(searchField, result); } }