List of usage examples for java.lang StringBuilder delete
@Override public StringBuilder delete(int start, int end)
From source file:nl.tue.gale.ae.GaleContext.java
public static void addCookie(Resource resource, String name, String value, int age) { checkNotNull(name);/*w w w . j a va 2 s . c o m*/ if (value == null) value = "Null"; String host = ""; String path = sc(resource).getContextPath(); /* * if * (req(resource).getHeader("User-Agent").contains("compatible; MSIE") * && age == 0) { host = * URIs.of(req(resource).getRequestURL().toString()) .getHost(); path = * "/"; } */ String expires = null; if (age >= 0) { if (age == 0) age = -86400; DateFormat df = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US); Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US); c.add(Calendar.SECOND, age); df.setCalendar(c); expires = df.format(c.getTime()); } else expires = ""; StringBuilder sb = new StringBuilder(); for (Map.Entry<String, String> entry : ImmutableMap .of(name, encodeURL(value), "Expires", expires, "Path", path, "Domain", host).entrySet()) if (!"".equals(entry.getValue())) { sb.append(entry.getKey()); sb.append("="); sb.append(entry.getValue()); sb.append("; "); } sb.delete(sb.length() - 2, sb.length()); resp(resource).setContentType("text/html"); resp(resource).addHeader("Set-Cookie", sb.toString()); }
From source file:org.fastj.fit.tool.JSONHelper.java
public static String[] splitSelector(String selector) throws DataInvalidException { List<String> sl = new ArrayList<String>(); StringBuilder buff = new StringBuilder(); int in = 0;/*from w w w .jav a 2 s.c o m*/ for (int i = 0; i < selector.length(); i++) { char c = selector.charAt(i); if (in > 0) { if (c == '[') { in++; buff.append(c); } else if (c == ']') { in--; if (in == 0) { sl.add(buff.toString().trim()); buff.delete(0, buff.length()); } else { buff.append(c); } } else { buff.append(c); } } else { if (c == '[') { in++; } else { //invalid throw new DataInvalidException("Selector invalid."); } } } if (in != 0) throw new DataInvalidException("Selector invalid."); return sl.toArray(new String[sl.size()]); }
From source file:eu.dasish.annotation.backend.Helpers.java
public static StringBuilder replaceString(StringBuilder source, String oldFragment, Object newObject) { if (oldFragment != null) { int lengthOld = oldFragment.length(); String newFragment;//from w ww. ja v a 2s . c o m if (newObject != null) { if (newObject instanceof Integer) { newFragment = ((Integer) newObject).toString(); } else { if (newObject instanceof String) { newFragment = (String) newObject; } else { newFragment = newObject.toString(); } } } else { newFragment = " "; } int lengthNew = newFragment.length(); int indexOf = source.indexOf(oldFragment); while (indexOf > 0) { source.delete(indexOf, indexOf + lengthOld); source.insert(indexOf, newFragment); indexOf = source.indexOf(oldFragment, indexOf + lengthNew); } } return source; }
From source file:models.MBox.java
private static int appendIdsAndExecuteSql(StringBuilder sqlSb, List<Long> boxIds) { if (boxIds.isEmpty()) return -1; for (Long id : boxIds) { sqlSb.append(" ID=").append(id).append(" OR"); }// ww w. ja va 2 s . c o m sqlSb.delete(sqlSb.length() - 2, sqlSb.length()); sqlSb.append(");"); SqlUpdate down = Ebean.createSqlUpdate(sqlSb.toString()); return down.execute(); }
From source file:com.github.gekoh.yagen.api.DefaultNamingStrategy.java
public static String generateShortName(String name, Integer maxLength, Integer charsPerGroup) { StringBuilder b = new StringBuilder(); int charsPg = charsPerGroup != null ? charsPerGroup : 1; int idx = 0, prevIdx = 0; while ((idx = name.indexOf('_', idx + 1)) > 0 && name.length() > idx) { b.append(name.substring(prevIdx, Math.min(Math.min(prevIdx + charsPg, name.length()), idx))); prevIdx = idx + 1;/*from ww w. ja v a 2 s . c o m*/ if (charsPg > 1) { b.append("_"); } } if (prevIdx > 0 && name.length() >= prevIdx) { b.append(name.substring(prevIdx, Math.min(prevIdx + charsPg, name.length()))); } if (b.length() < 1) { b.append(name); } if (maxLength != null && b.length() > maxLength) { b.delete(maxLength.intValue(), b.length()); } return b.toString(); }
From source file:com.vmware.bdd.utils.CommonUtil.java
public static String toHexString(byte[] bytes) { StringBuilder sb = new StringBuilder(bytes.length * 3); for (int b : bytes) { b &= 0xff;//from w ww.ja v a 2s.c om sb.append(HEXDIGITS[b >> 4]); sb.append(HEXDIGITS[b & 15]); sb.append(':'); } if (sb.length() > 0) { sb.delete(sb.length() - 1, sb.length()); } return sb.toString().toUpperCase(); }
From source file:org.fastj.fit.tool.JSONHelper.java
/** * json.rlt.list[0].value/* w w w . jav a2 s . com*/ * * @param path * @return String[] */ public static String[] split(String path) throws DataInvalidException { List<String> paths = new ArrayList<String>(); boolean needEnd = false; StringBuilder buff = new StringBuilder(); for (int i = 0; i < path.length(); i++) { char c = path.charAt(i); if (c == '.') { if (needEnd) { buff.append(c); continue; } String p = trimJP(buff.toString().trim()); if (p == null || p.isEmpty()) throw new DataInvalidException("Path invalid: " + path); paths.add(p); buff.delete(0, buff.length()); continue; } else if (c == '[') { needEnd = true; } else if (c == ']') { needEnd = false; } buff.append(c); } if (needEnd) throw new DataInvalidException("Path invalid: " + path); String p = buff.toString().trim(); if (p.isEmpty()) throw new DataInvalidException("Path invalid: " + path); paths.add(p); return paths.toArray(new String[paths.size()]); }
From source file:pl.edu.agh.iosr.lsf.dao.DatabaseHelper.java
private static Map<String, String> loadStatementStore(InputStream in) throws IOException { Map<String, String> statementStore = new HashMap<>(); try {//from w ww . ja v a 2 s .co m BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder sb = new StringBuilder(100); String line; int hi = -1, sci = -1; while (true) { line = br.readLine(); if (line == null) break; hi = line.indexOf('#'); if (hi >= 0) line = line.substring(0, hi).trim(); if (line.length() < 1) continue; sci = line.lastIndexOf(';'); if (sci >= 0) { line = line.substring(0, sci); sb.append(line); line = sb.toString(); sb.delete(0, sb.length()); sci = line.indexOf(':'); statementStore.put(line.substring(0, sci), line.substring(sci + 1, line.length())); } else { sb.append(line); } } } finally { in.close(); } return statementStore; }
From source file:Main.java
public static String fillTextBox(TextPaint paint, int fragmentWidth, String source, int start) { StringBuilder sb = new StringBuilder(); final int length = source.length(); int indexLeft = start; int indexRight = start + 1; int lastWhiteSpaceL = 0; int lastWhiteSpaceR = 0; while (paint.measureText(sb.toString()) < fragmentWidth && (indexLeft >= 0 || indexRight < length)) { if (indexLeft >= 0) { char c = source.charAt(indexLeft); if (Character.isWhitespace(c)) lastWhiteSpaceL = indexLeft; sb.insert(0, c);//from w ww .j av a 2s . co m indexLeft--; } if (indexRight < length) { char c = source.charAt(indexRight); if (Character.isWhitespace(c)) lastWhiteSpaceR = indexRight; sb.append(c); indexRight++; } } if (indexLeft >= 0) { // Delete first word part sb.delete(0, lastWhiteSpaceL - indexLeft); sb.insert(0, "..."); indexLeft = lastWhiteSpaceL - 3; // Set new index left } if (indexRight < length) { // Delete last word part sb.delete(lastWhiteSpaceR - (indexLeft + 1), sb.length()); sb.append("..."); } return sb.toString(); }
From source file:com.forerunnergames.tools.common.Strings.java
/** * Deletes the contents of the specified StringBuilder * * @param s/* ww w .j a v a 2s . c o m*/ * The StringBuilder to delete the content of, must not be null. * * @return The empty StringBuilder. */ public static StringBuilder clear(final StringBuilder s) { Arguments.checkIsNotNull(s, "s"); return s.delete(0, s.length()); }