List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.aliyun.android.oss.http.OSSHttpTool.java
public static String encodeUri(String uri) { StringBuffer encodeBuffer = new StringBuffer(); String[] splitArray = uri.split("/"); for (String part : splitArray) { try {// ww w . ja va 2 s. com encodeBuffer.append(URLEncoder.encode(part, "UTF-8")).append("/"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } if (!uri.endsWith("/")) { encodeBuffer.deleteCharAt(encodeBuffer.length() - 1); } return encodeBuffer.toString(); }
From source file:Util.java
public static String isoDateTimeToDate(String isoDate) { StringBuffer sb = new StringBuffer(isoDate); int maxlen;//w w w. jav a 2s.c om if (isoDate.length() >= 10) { //2007-01-01 -> 20070101 //remove hyphens between year, month, and day sb.deleteCharAt(4); sb.deleteCharAt(6); maxlen = 8; //20070101T17:30:12 -> 20070101T173012 if (isoDate.length() >= 19) { maxlen = 15; //remove colons between hours, minutes, and seconds sb.deleteCharAt(11); sb.deleteCharAt(13); if (isoDate.indexOf("Z") >= 0) { sb.insert(15, 'Z'); ++maxlen; } } if (sb.length() > maxlen) sb.setLength(maxlen); } return sb.toString(); }
From source file:com.anyi.gp.license.RegisterTools.java
public static String getKeyString(String encodeType) { StringBuffer sb = new StringBuffer(); sb.append("Host[" + getHostName() + "];"); sb.append("Ip["); Set entrySet = getInetAddresses().entrySet(); java.util.Map.Entry entry;//from ww w. j a v a 2 s .c om for (Iterator iterator = entrySet.iterator(); iterator.hasNext(); sb.append(entry.getValue() + ",")) { entry = (java.util.Map.Entry) iterator.next(); } if (!entrySet.isEmpty()) { sb = new StringBuffer(sb.substring(0, sb.length() - 1)); } sb.append("];"); sb.append("ENCODETYPE[" + encodeType + "];"); sb.append("Mac["); List macList = getMacAddresses(); for (int i = 0; i < macList.size(); i++) { if (i != 0) { sb.append(","); } sb.append(macList.get(i)); } sb.append("]"); return sb.toString(); }
From source file:com.useekm.indexing.postgis.IndexedStatement.java
private static String createQuery(String base, Resource subject, URI predicate, Value object) { StringBuffer sql = new StringBuffer(MAX_SELECT_LEN).append(base); if (subject != null || predicate != null || object != null) sql.append(WHERE);// w w w . j a va2 s .c o m int startLen = sql.length(); if (subject != null) append(sql, startLen, SUBJECT, EQQ); if (predicate != null) append(sql, startLen, PREDICATE, EQQ); if (object != null) createObjectEqualClauses(sql, startLen, object); return sql.toString(); }
From source file:ch.entwine.weblounge.maven.S3DeployMojo.java
/** * Concatenates the url elements with respect to leading and trailing slashes. * The path will always end with a trailing slash. * // w ww. j a v a 2 s.com * @param urlElements * the path elements * @return the concatenated url of the two arguments * @throws IllegalArgumentException * if less than two path elements are provided */ private static String concat(String... urlElements) throws IllegalArgumentException { if (urlElements == null || urlElements.length < 1) throw new IllegalArgumentException("Prefix cannot be null or empty"); if (urlElements.length < 2) throw new IllegalArgumentException("Suffix cannot be null or empty"); StringBuffer b = new StringBuffer(); for (String s : urlElements) { if (StringUtils.isBlank(s)) throw new IllegalArgumentException("Path element cannot be null"); String element = checkSeparator(s); element = removeDoubleSeparator(element); if (b.length() == 0) { b.append(element); } else if (b.lastIndexOf("/") < b.length() - 1 && !element.startsWith("/")) { b.append("/").append(element); } else if (b.lastIndexOf("/") == b.length() - 1 && element.startsWith("/")) { b.append(element.substring(1)); } else { b.append(element); } } return b.toString(); }
From source file:Main.java
/** * <p>This helper method loads the XML properties from a specific * XML element, or set of elements.</p> * * @param nodeList <code>List</code> of elements to load from. * @param baseName the base name of this property. */// w w w .j a va 2 s. c o m private static void loadFromElements(Map<String, String> result, NodeList nodeList, StringBuffer baseName) { // Iterate through each element for (int s = 0; s < nodeList.getLength(); s++) { Node current = nodeList.item(s); if (current.getNodeType() == Node.ELEMENT_NODE) { String name = current.getNodeName(); String text = null; NodeList childNodes = current.getChildNodes(); if (childNodes.getLength() > 0) { text = current.getChildNodes().item(0).getNodeValue(); } // String text = current.getAttributeValue("value"); // Don't add "." if no baseName if (baseName.length() > 0) { baseName.append("."); } baseName.append(name); // See if we have an element value if ((text == null) || (text.equals(""))) { // If no text, recurse on children loadFromElements(result, current.getChildNodes(), baseName); } else { // If text, this is a property result.put(baseName.toString(), text); } // On unwind from recursion, remove last name if (baseName.length() == name.length()) { baseName.setLength(0); } else { baseName.setLength(baseName.length() - (name.length() + 1)); } } } }
From source file:edu.harvard.i2b2.analysis.security.HighEncryption.java
public static String leftPad(String stringToPad, int size, String padder) { if (padder.length() == 0) { return stringToPad; }//www. j a v a 2 s . c o m StringBuffer strb = new StringBuffer(size); StringCharacterIterator sci = new StringCharacterIterator(padder); while (strb.length() < (size - stringToPad.length())) { for (char ch = sci.first(); ch != CharacterIterator.DONE; ch = sci.next()) { if (strb.length() < size - stringToPad.length()) { strb.insert(strb.length(), String.valueOf(ch)); } } } return strb.append(stringToPad).toString(); }
From source file:com.hihframework.core.utils.BeanUtils.java
public static String getConditions(Object obj, String... excludes) { String[] fieldsName = ReflectUtil.getAllFieldsName(obj); ArrayList<Object> args = new ArrayList<Object>(); StringBuffer sb = new StringBuffer(); for (String fieldName : fieldsName) { Object value = ReflectUtil.getFieldValue(obj, fieldName); if (fieldName.equals("id")) continue; for (String exclude : excludes) { if (fieldName.equals(exclude)) continue; }/* www . j a v a 2s .co m*/ if (value != null) { sb.append(" and " + fieldName + "=?,"); args.add(value); } } String sql = sb.toString(); if (sql.endsWith(",")) { sb.deleteCharAt(sb.length() - 1); sql = sb.toString(); } return sql; }
From source file:com.aliyun.odps.rodps.ROdps.java
/** * /*from ww w . j av a 2 s . c o m*/ * @Title: partitionMap2String * @Description: TODO * @param sepc * @param valueDim * @param fieldDim * @return * @return String * @throws */ private static String partitionMap2String(Map<String, String> sepc, String valueDim, String fieldDim) { StringBuffer ret = new StringBuffer(); for (Map.Entry<String, String> entry : sepc.entrySet()) { if (ret.length() > 0) { ret.append(fieldDim); } ret.append(entry.getKey() + "=" + valueDim + entry.getValue() + valueDim); } return ret.toString(); }
From source file:org.opencron.common.utils.StringUtils.java
public static String joinString(Collection<?> collection, String separator) { AssertUtils.notEmpty(collection, "joinString arguments collection and separator can not be null"); StringBuffer collStr = new StringBuffer(); for (Object o : collection) { collStr.append(o).append(separator); }//from w ww . j a v a 2 s . c o m return collStr.substring(0, collStr.length() - separator.length()); }