List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.ing.connector.util.WStringUtil.java
/** * Pad to string to the right to "length" using character "c". * Warning: if string.length() > length then "string" is returned, not truncated *///from w w w . j av a 2 s .c o m public static String padStringRight(String string, int length, char c) { StringBuffer sb = new StringBuffer(length); sb.append(string); while (sb.length() < sb.capacity()) sb.append(c); return sb.toString(); }
From source file:com.josephblough.sbt.transport.SbaTransport.java
public static List<LoanAndGrantData> getLoansAndGrantsDataByIndustryAndSpecialties(final String industry, final List<String> specialties) { final StringBuffer parameters = new StringBuffer(); for (String speciality : specialties) { if (parameters.length() > 0) { parameters.append("-"); }// w w w .j a va 2s . c o m parameters.append(formatForUrl(speciality)); } final String url = LOANS_AND_GRANTS_BASE_URL + "nil/for_profit/" + formatForUrl(industry) + "/" + parameters.toString() + ".json"; return getLoansAndGrantsData(url); }
From source file:com.josephblough.sbt.transport.SbaTransport.java
public static List<LoanAndGrantData> getLoansAndGrantsDataByStateAndSpecialties(final String stateAbbreviation, final List<String> specialties) { final StringBuffer parameters = new StringBuffer(); for (String speciality : specialties) { if (parameters.length() > 0) { parameters.append("-"); }/*from w w w. j a v a2 s . c om*/ parameters.append(formatForUrl(speciality)); } final String url = LOANS_AND_GRANTS_BASE_URL + stateAbbreviation.toLowerCase() + "/for_profit/nil/" + parameters.toString() + ".json"; return getLoansAndGrantsData(url); }
From source file:com.josephblough.sbt.transport.SbaTransport.java
public static List<LoanAndGrantData> getLoansAndGrantsDataByStateAndIndustryAndSpecialties( final String stateAbbreviation, final String industry, final List<String> specialties) { final StringBuffer parameters = new StringBuffer(); for (String speciality : specialties) { if (parameters.length() > 0) { parameters.append("-"); }//from w w w.ja va2 s. co m parameters.append(formatForUrl(speciality)); } final String url = LOANS_AND_GRANTS_BASE_URL + stateAbbreviation.toLowerCase() + "/for_profit/" + formatForUrl(industry) + "/" + parameters + ".json"; return getLoansAndGrantsData(url); }
From source file:com.alibaba.rocketmq.filtersrv.filter.DynaCode.java
private static String extractClasspath(ClassLoader cl) { StringBuffer buf = new StringBuffer(); while (cl != null) { if (cl instanceof URLClassLoader) { URL urls[] = ((URLClassLoader) cl).getURLs(); for (int i = 0; i < urls.length; i++) { if (buf.length() > 0) { buf.append(File.pathSeparatorChar); }/*from w w w.java 2 s. co m*/ String s = urls[i].getFile(); try { s = URLDecoder.decode(s, "UTF-8"); } catch (UnsupportedEncodingException e) { continue; } File f = new File(s); buf.append(f.getAbsolutePath()); } } cl = cl.getParent(); } return buf.toString(); }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
private static void append(StringBuffer sql, int startLen, String... values) { if (sql.length() > startLen) sql.append(AND);/* w w w. ja v a 2 s.com*/ for (int i = 0; i != values.length; ++i) sql.append(values[i]); }
From source file:cn.edu.zju.acm.onlinejudge.util.ProblemManager.java
private static String[] split(String line) { int quote = 0; StringBuffer sb = new StringBuffer(); List<String> values = new ArrayList<String>(); for (int i = 0; i < line.length(); ++i) { char ch = line.charAt(i); if (ch == '"') { if (quote == 0 && sb.length() == 0) { quote = 1;/*from ww w .jav a2 s . com*/ continue; } if (quote == 0) { sb.append(ch); continue; } if (quote == 2) { sb.append(ch); quote--; } else { quote++; } } else if (quote == 1) { sb.append(ch); } else if (ch == ',') { values.add(sb.toString().trim()); sb = new StringBuffer(); quote = 0; } else { sb.append(ch); } } values.add(sb.toString().trim()); return values.toArray(new String[0]); }
From source file:Main.java
/** * Converts a method name to an attribute name, e.g. getFooBar() --> foo_bar, isFlag --> flag. * @param methodName//ww w. ja va2 s.c om * @return */ public static String methodNameToAttributeName(final String methodName) { String name = methodName; if ((methodName.startsWith("get") || methodName.startsWith("set")) && methodName.length() > 3) name = methodName.substring(3); else if (methodName.startsWith("is") && methodName.length() > 2) name = methodName.substring(2); // Pattern p=Pattern.compile("[A-Z]+"); Matcher m = METHOD_NAME_TO_ATTR_NAME_PATTERN.matcher(name); StringBuffer sb = new StringBuffer(); while (m.find()) { int start = m.start(), end = m.end(); String str = name.substring(start, end).toLowerCase(); if (str.length() > 1) { String tmp1 = str.substring(0, str.length() - 1); String tmp2 = str.substring(str.length() - 1); str = tmp1 + "_" + tmp2; } if (start == 0) { m.appendReplacement(sb, str); } else m.appendReplacement(sb, "_" + str); } m.appendTail(sb); return sb.length() > 0 ? sb.toString() : methodName; }
From source file:Unsigned.java
/** * Return the unsigned value of the number. * /*from w w w . ja v a 2 s. c o m*/ * @param number * a byte value * @return the unsigned value */ public static long unsigned(byte number) { long result = 0; BinaryFormat format = new BinaryFormat(); String binary = format.format(number); StringBuffer buffer = new StringBuffer(binary); buffer.reverse(); int length = buffer.length(); for (int i = 0; i < length; i++) { result += (buffer.charAt(i) == '1') ? 1 << i : 0; } return (result); }
From source file:Unsigned.java
/** * Return the unsigned value of the number. * //from ww w. ja va 2 s . c o m * @param number * a short value * @return the unsigned value */ public static long unsigned(short number) { long result = 0; BinaryFormat format = new BinaryFormat(); String binary = format.format(number); StringBuffer buffer = new StringBuffer(binary); buffer.reverse(); int length = buffer.length(); for (int i = 0; i < length; i++) { result += (buffer.charAt(i) == '1') ? 1 << i : 0; } return (result); }