List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:com.log4ic.compressor.utils.template.JavascriptTemplateEngine.java
public static String parse(String name, String source, Mode mode) { StringBuilder buffer = new StringBuilder(); switch (mode) { case AMD://w w w .j a v a2 s. c o m buffer.append("define("); if (StringUtils.isNotBlank(name)) { buffer.append("'").append(name).append("',"); } buffer.append("function(){return "); break; case CALLBACK: buffer.append(name).append("("); break; case COMMON: buffer.append("window['").append(name).append("']="); break; default: } source = source.replaceAll("'", "\\\\'"); buffer.append(source.replaceAll("(?m)^(\\s*)(.*?)\\s*$", "$1'$2'+")); buffer.delete(buffer.length() - 1, buffer.length()); switch (mode) { case AMD: buffer.append("})"); break; case CALLBACK: buffer.append(")"); break; case COMMON: default: } buffer.append(";"); return buffer.toString(); }
From source file:net.netheos.pcsapi.providers.hubic.Swift.java
static Date parseLastModified(JSONObject json) { try {/* www. j a v a2 s. c om*/ String lm = json.optString("last_modified", null); // "2014-02-12T16:13:49.346540" if (lm == null) { return null; } // Date format if (!lm.contains("+")) { lm += "+0000"; } // Normalize millis and remove microseconds, if any: StringBuilder builder = new StringBuilder(lm); int dotPos = lm.indexOf('.'); int plusPos = lm.indexOf('+'); if (dotPos > 0) { if (plusPos - dotPos > 4) { builder.delete(dotPos + 4, plusPos); // remove microsec } else while (plusPos - dotPos < 4) { // complete millis : ".3" -> ".300" builder.insert(plusPos, '0'); plusPos++; } } else { // no milliseconds ? defensive code builder.insert(plusPos, ".000"); } DateFormat lastModifiedDateFormat = new SimpleDateFormat(DF_LAST_MODIFIED_PATTERN, Locale.ENGLISH); return lastModifiedDateFormat.parse(builder.toString()); } catch (ParseException ex) { LOGGER.warn("Error parsing date", ex); return null; } }
From source file:com.forsrc.utils.MyRsaUtils.java
/** * Encrypt 2 string./*from w ww .j ava 2s . c o m*/ * * @param rsaKey the rsa key * @param plaintext the plaintext * @return the string */ public static String encrypt2(RsaKey rsaKey, String plaintext) { BigInteger[] plaintextBigIntegers = string2BigIntegers(plaintext); StringBuilder sb = new StringBuilder(BLOCK_SIZE + 1); for (BigInteger bigInteger : plaintextBigIntegers) { BigInteger encrypt = encrypt(rsaKey, bigInteger); sb.append(encrypt.toString()).append("$"); } sb.delete(sb.length() - 1, sb.length()); return new String(new Base64().encode(sb.toString().getBytes())); }
From source file:com.cloud.utils.db.SqlGenerator.java
public static StringBuilder buildUpdateSql(String tableName, List<Attribute> attrs) { StringBuilder sql = new StringBuilder("UPDATE "); sql.append(tableName).append(" SET "); for (Attribute attr : attrs) { sql.append(attr.columnName).append(" = ?, "); }/*from w w w . j a v a 2 s .co m*/ sql.delete(sql.length() - 2, sql.length()); sql.append(" WHERE "); return sql; }
From source file:de.codesourcery.jasm16.utils.Misc.java
public static String removeLeadingWhitespace(String input) { StringBuilder output = new StringBuilder(input); while (output.length() > 0 && Character.isWhitespace(output.charAt(0))) { output.delete(0, 1); }/*from ww w. j av a 2 s . c o m*/ return output.toString(); }
From source file:net.radai.beanz.util.ReflectionUtil.java
public static String prettyPrint(Type type) { if (type instanceof GenericArrayType) { GenericArrayType genericArrayType = (GenericArrayType) type; return prettyPrint(genericArrayType.getGenericComponentType()) + "[]"; }/* w w w . j a v a2s.co m*/ if (type instanceof WildcardType) { WildcardType wildcardType = (WildcardType) type; return wildcardType.toString(); } if (type instanceof TypeVariable) { TypeVariable<?> typeVariable = (TypeVariable) type; return typeVariable.getName(); } if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; StringBuilder sb = new StringBuilder(); sb.append(prettyPrint(parameterizedType.getRawType())); Type[] typeArguments = parameterizedType.getActualTypeArguments(); if (typeArguments != null && typeArguments.length > 0) { sb.append("<"); for (Type typeArgument : typeArguments) { sb.append(prettyPrint(typeArgument)).append(", "); } sb.delete(sb.length() - 2, sb.length()); // last ", " sb.append(">"); } return sb.toString(); } Class<?> clazz = (Class<?>) type; if (clazz.isArray()) { return prettyPrint(clazz.getComponentType()) + "[]"; } return clazz.getSimpleName(); }
From source file:org.cleverbus.common.Strings.java
/** * Converts an array to the string.// w w w.j a v a 2 s . com * * @param array the array that has to be converted * @return the array as a string */ public static String arrayToString(Object[] array) { if (array == null) { return "null"; } int i; StringBuilder sb = new StringBuilder(); sb.append('['); for (i = 0; i < array.length; i++) { if (array[i] != null) { sb.append(array[i].toString()); } else { sb.append("null"); } sb.append(','); } if (i > 0) { sb.delete(sb.length() - 1, sb.length()); } sb.append(']'); return sb.toString(); }
From source file:cc.recommenders.names.CoReNames.java
/** * @return the <b><method name>(<parameter simple types...>)</b> * - no return value./*from w ww . j a v a 2 s . com*/ */ public static String vm2srcSimpleMethod(final ICoReMethodName name) { ensureIsNotNull(name, "name"); final StringBuilder sb = new StringBuilder(); if (name.getName().equals("<subtype-init>")) { sb.append("ConstructorCallFromSubtype"); } else { sb.append(name.isInit() ? vm2srcSimpleTypeName(name.getDeclaringType()) : name.getName()); } // sb.append('('); for (final ICoReTypeName param : name.getParameterTypes()) { sb.append(vm2srcSimpleTypeName(param)).append(", "); } if (name.getParameterTypes().length > 0) { sb.delete(sb.length() - 2, sb.length()); } // // sb.append(')'); return sb.toString(); }
From source file:com.inmobi.conduit.purge.DataPurgerService.java
private static String getFilterString(Map<String, String> partitionSpec) { final String AND = " AND "; StringBuilder filter = new StringBuilder(); for (Map.Entry<String, String> entry : partitionSpec.entrySet()) { filter.append(entry.getKey()).append("=").append("\"").append(entry.getValue()).append("\"") .append(AND);/*from ww w.j av a2 s .com*/ } int length = filter.toString().length(); if (length > 0) filter.delete(length - AND.length(), length); return filter.toString(); }
From source file:org.apache.carbondata.processing.csvreaderstep.CsvInput.java
/** * This method is borrowed from TextFileInput * * @param log/* w w w.j a va2s . c o m*/ * @param line * @param delimiter * @param enclosure * @param escapeCharacter * @return * @throws KettleException */ public static final String[] guessStringsFromLine(LogChannelInterface log, String line, String delimiter, String enclosure, String escapeCharacter) throws KettleException { List<String> strings = new ArrayList<String>(CarbonCommonConstants.CONSTANT_SIZE_TEN); String pol; // piece of line try { if (line == null) { return null; } // Split string in pieces, only for CSV! int pos = 0; int length = line.length(); boolean dencl = false; int lenEncl = (enclosure == null ? 0 : enclosure.length()); int lenEsc = (escapeCharacter == null ? 0 : escapeCharacter.length()); while (pos < length) { int from = pos; int next; boolean enclFound; boolean containsEscapedEnclosures = false; boolean containsEscapedSeparators = false; // Is the field beginning with an enclosure? // "aa;aa";123;"aaa-aaa";000;... if (lenEncl > 0 && line.substring(from, from + lenEncl).equalsIgnoreCase(enclosure)) { if (log.isRowLevel()) { log.logRowlevel(BaseMessages.getString(PKG, "CsvInput.Log.ConvertLineToRowTitle"), BaseMessages.getString(PKG, "CsvInput.Log.ConvertLineToRow", line.substring(from, from + lenEncl))); //$NON-NLS-1$ //$NON-NLS-2$ } enclFound = true; int p = from + lenEncl; boolean isEnclosure = lenEncl > 0 && p + lenEncl < length && line.substring(p, p + lenEncl).equalsIgnoreCase(enclosure); boolean isEscape = lenEsc > 0 && p + lenEsc < length && line.substring(p, p + lenEsc).equalsIgnoreCase(escapeCharacter); boolean enclosureAfter = false; // Is it really an enclosure? See if it's not repeated twice or escaped! if ((isEnclosure || isEscape) && p < length - 1) { String strnext = line.substring(p + lenEncl, p + 2 * lenEncl); if (strnext.equalsIgnoreCase(enclosure)) { p++; enclosureAfter = true; dencl = true; // Remember to replace them later on! if (isEscape) { containsEscapedEnclosures = true; } } } // Look for a closing enclosure! while ((!isEnclosure || enclosureAfter) && p < line.length()) { p++; enclosureAfter = false; isEnclosure = lenEncl > 0 && p + lenEncl < length && line.substring(p, p + lenEncl).equals(enclosure); isEscape = lenEsc > 0 && p + lenEsc < length && line.substring(p, p + lenEsc).equals(escapeCharacter); // Is it really an enclosure? See if it's not repeated twice or escaped! if ((isEnclosure || isEscape) && p < length - 1) // Is { String strnext = line.substring(p + lenEncl, p + 2 * lenEncl); if (strnext.equals(enclosure)) { p++; enclosureAfter = true; dencl = true; // Remember to replace them later on! if (isEscape) { containsEscapedEnclosures = true; // remember } } } } if (p >= length) { next = p; } else { next = p + lenEncl; } if (log.isRowLevel()) { log.logRowlevel(BaseMessages.getString(PKG, "CsvInput.Log.ConvertLineToRowTitle"), BaseMessages.getString(PKG, "CsvInput.Log.EndOfEnclosure", "" + p)); //$NON-NLS-2$ //$NON-NLS-2$ //$NON-NLS-3$ } } else { enclFound = false; boolean found = false; int startpoint = from; do { next = line.indexOf(delimiter, startpoint); // See if this position is preceded by an escape character. if (lenEsc > 0 && next - lenEsc > 0) { String before = line.substring(next - lenEsc, next); if (escapeCharacter != null && escapeCharacter.equals(before)) { // take the next separator, this one is escaped... startpoint = next + 1; containsEscapedSeparators = true; } else { found = true; } } else { found = true; } } while (!found && next >= 0); } if (next == -1) { next = length; } if (enclFound) { pol = line.substring(from + lenEncl, next - lenEncl); if (log.isRowLevel()) { log.logRowlevel(BaseMessages.getString(PKG, "CsvInput.Log.ConvertLineToRowTitle"), BaseMessages.getString(PKG, "CsvInput.Log.EnclosureFieldFound", "" + pol)); //$NON-NLS-2$ //$NON-NLS-2$ //$NON-NLS-3$ } } else { pol = line.substring(from, next); if (log.isRowLevel()) { log.logRowlevel(BaseMessages.getString(PKG, "CsvInput.Log.ConvertLineToRowTitle"), BaseMessages.getString(PKG, "CsvInput.Log.NormalFieldFound", "" + pol)); //$NON-NLS-2$ //$NON-NLS-2$ //$NON-NLS-3$ } } if (dencl) { StringBuilder sbpol = new StringBuilder(pol); int idx = sbpol.indexOf(enclosure + enclosure); while (idx >= 0) { sbpol.delete(idx, idx + (enclosure == null ? 0 : enclosure.length())); idx = sbpol.indexOf(enclosure + enclosure); } pol = sbpol.toString(); } // replace the escaped enclosures with enclosures... if (containsEscapedEnclosures) { String replace = escapeCharacter + enclosure; String replaceWith = enclosure; pol = Const.replace(pol, replace, replaceWith); } //replace the escaped separators with separators... if (containsEscapedSeparators) { String replace = escapeCharacter + delimiter; String replaceWith = delimiter; pol = Const.replace(pol, replace, replaceWith); } // Now add pol to the strings found! strings.add(pol); pos = next + delimiter.length(); } if (pos == length) { if (log.isRowLevel()) { log.logRowlevel(BaseMessages.getString(PKG, "CsvInput.Log.ConvertLineToRowTitle"), BaseMessages.getString(PKG, "CsvInput.Log.EndOfEmptyLineFound")); } strings.add(""); //$NON-NLS-1$ } } catch (Exception e) { throw new KettleException( BaseMessages.getString(PKG, "CsvInput.Log.Error.ErrorConvertingLine", e.toString()), e); //$NON-NLS-1$ } return strings.toArray(new String[strings.size()]); }