List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:Main.java
private static String toStringByArray(Object[] value) { StringBuffer sb = new StringBuffer(100); String type = value[0].getClass().getName(); sb.append("{").append(type).append("@"); for (int i = 0; i < value.length; i++) { sb.append(esc(value[i].toString())).append(","); }/* w w w.j ava 2 s .com*/ return sb.substring(0, sb.length() - 1) + "}"; }
From source file:com.kolich.curacao.mappers.request.types.body.EncodedRequestBodyMapper.java
private static final Multimap<String, String> parse(final String body, final String encodingCharset) throws Exception { final ImmutableMultimap.Builder<String, String> result = ImmutableListMultimap.builder(); // <https://github.com/markkolich/curacao/issues/12> // Only bother parsing the POST body if there's actually something there to parse. if (!StringUtils.isEmpty(body)) { final StringBuffer buffer = new StringBuffer(body); final Cursor cursor = new Cursor(0, buffer.length()); while (!cursor.atEnd()) { final Map.Entry<String, String> entry = getNextNameValuePair(buffer, cursor); if (!entry.getKey().isEmpty()) { result.put(decode(entry.getKey(), encodingCharset), decode(entry.getValue(), encodingCharset)); }//from www.ja v a 2 s . c om } } return result.build(); }
From source file:Main.java
/** * Get the path to a given element. The path is a simplified version of XPath. It begins with the first element UNDER * the document element./*from w w w . j av a 2s . c om*/ * * @param elem Element of interest * @return XPath-like path to the element */ public static String getElementPath(Element elem) { if (elem == null) return null; StringBuffer sb = new StringBuffer(); Node parent = null; for (Node node = elem; node != null; node = parent) { parent = node.getParentNode(); if ((node instanceof Element) && (parent instanceof Element)) { if (sb.length() > 0) sb.insert(0, '/'); sb.insert(0, node.getNodeName()); } } return sb.toString(); }
From source file:com.vaadin.sass.internal.visitor.IfElseNodeHandler.java
private static String replaceStrings(String expression) { expression = expression.replaceAll("\"", ""); Matcher m = pattern.matcher(expression); StringBuffer b = new StringBuffer(); while (m.find()) { String group = m.group(); m.appendReplacement(b, "'" + group + "'"); }//from w ww.ja va 2 s . com m.appendTail(b); if (b.length() != 0) { return b.toString(); } return expression; }
From source file:Main.java
/** * Transforms a collection of strings into a comma delimited string, where * each component get single-quoted./*from ww w . j a v a 2s . c o m*/ * * @param elements the collection of Integers * @return a comma delimited String. */ public static String getQuotedCommaDelimitedString(Collection<String> elements) { if (elements != null && elements.size() > 0) { final StringBuffer buffer = new StringBuffer(); for (String element : elements) { buffer.append("'").append(element.toString()).append("', "); } return buffer.substring(0, buffer.length() - ", ".length()); } return null; }
From source file:Main.java
public static final void appendCookies(final StringBuffer cookie, final HttpURLConnection conn) { List<String> values = conn.getHeaderFields().get("Set-Cookie"); if (values != null) { for (String v : values) { if (v.indexOf("deleted") == -1) { if (cookie.length() > 0) { cookie.append("; "); }/*from w w w. j a va 2 s .c o m*/ cookie.append(v.split(";")[0]); } } } }
From source file:StringUtil.java
/** * Left justify a string, and fill to a given length with the character <code>fill</code>. * If the length of the string is greater than "maxLength" characters, return only * the first, left "maxLength" characters. *//* ww w . j av a 2 s . c o m*/ public static String leftJustify(String s, int maxLength, char fill) { if (s == null || maxLength == 0) { return s; } // If the string has more than "maxLength" characters, // return only the first "maxLength" characters of the string. if (s.trim().length() > maxLength) { return s.substring(0, maxLength).trim(); } StringBuffer sb = new StringBuffer(s.trim()); // Append as many blanks as needed to reach "maxLength". while (sb.length() < maxLength) { sb.append(fill); } return sb.toString(); }
From source file:BitLottoVerify.java
public static String printBytesInHex(byte[] d) { StringBuffer s = new StringBuffer(d.length * 2); BigInteger bi = new BigInteger(1, d); s.append(bi.toString(16));//w w w .java 2s .c o m while (s.length() < d.length * 2) { s.insert(0, '0'); } return s.toString(); }
From source file:gov.gtas.parsers.util.FlightUtils.java
/** * Separate flight carrier and flight number from single input string. * @param s/* w w w. ja va 2 s. co m*/ * @return */ public static FlightNumber separateCarrierAndFlightNumber(String s) { StringBuffer fn = new StringBuffer(); int j; for (j = s.length() - 1; j >= 0; j--) { char c = s.charAt(j); if (Character.isDigit(c)) { fn.append(c); if (s.length() - fn.length() == MIN_CARRIER_LENG) { break; } else if (fn.length() == MAX_FLIGHT_NUM_LENG) { break; } } else { break; } } String carrier = s.substring(0, s.length() - fn.length()); return new FlightNumber(carrier, fn.reverse().toString()); }
From source file:com.jnj.b2b.storefront.util.MetaSanitizerUtil.java
/** * Takes a string of words, removes duplicates and returns a comma separated list of keywords as a String * /*from www.j a v a 2s. c om*/ * @param keywords * Keywords to be sanitized * @return String of comma separated keywords */ public static String sanitizeKeywords(final String keywords) { final String clean = (StringUtils.isNotEmpty(keywords) ? Jsoup.parse(keywords).text() : ""); // Clean html final String[] words = StringUtils.split(clean.replace("\"", "")); // Clean quotes // Remove duplicates final StringBuffer noDupes = new StringBuffer(); for (final String word : words) { if (noDupes.indexOf(word) == -1) { noDupes.append(word).append(','); } } if (noDupes.length() > 0) { noDupes.deleteCharAt(noDupes.length() - 1); } return noDupes.toString(); }