List of usage examples for java.lang StringBuffer insert
@Override public StringBuffer insert(int offset, double d)
From source file:com.mg.framework.utils.StringUtils.java
/** * Make sure the string starts with a forward slash but does not end with one; converts * back-slashes to forward-slashes; if in String is null or empty, returns zero length string. *//* w w w. j a va 2 s . c om*/ public static String cleanUpPathPrefix(String prefix) { if (prefix == null || prefix.length() == 0) return ""; StringBuffer cppBuff = new StringBuffer(prefix.replace('\\', '/')); if (cppBuff.charAt(0) != '/') { cppBuff.insert(0, '/'); } if (cppBuff.charAt(cppBuff.length() - 1) == '/') { cppBuff.deleteCharAt(cppBuff.length() - 1); } return cppBuff.toString(); }
From source file:Util.java
public static String isoDateTimeToDate(String isoDate) { StringBuffer sb = new StringBuffer(isoDate); int maxlen;/* w w w. jav a2 s . 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:org.LexGrid.util.sql.DBUtility.java
public static String escapeLdapDN(String string, boolean escapeCommas) { StringBuffer temp = new StringBuffer(string); for (int i = 0; i < temp.length(); i++) { if (temp.charAt(i) == '<') { temp.insert(i, '\\'); i++;//ww w .j a v a 2 s. c o m } if (temp.charAt(i) == '>') { temp.insert(i, '\\'); i++; } if (temp.charAt(i) == '/') { temp.insert(i, '\\'); i++; } if (escapeCommas && temp.charAt(i) == ',') { temp.insert(i, '\\'); i++; } } return temp.toString(); }
From source file:com.doculibre.constellio.lucene.BaseLuceneIndexHelper.java
public static String adjustIfNumber(Object value) { String result;// ww w .ja v a2s . co m if (value != null) { String strValue = value.toString(); try { Integer.parseInt(strValue); StringBuffer sb = new StringBuffer(strValue); for (int i = 0; i < NUMBER_LENGTH - strValue.length(); i++) { sb.insert(0, "0"); } result = sb.toString(); } catch (Exception e) { result = strValue; } } else { result = null; } return result; }
From source file:arena.utils.FileUtils.java
public static String constructOurCanonicalVersion(File current, File stopPoint) { int backOnes = 0; StringBuffer ourCanonicalVersion = new StringBuffer(); while ((current != null) && !current.equals(stopPoint)) { if (current.getName().equals("..")) { backOnes++;/* ww w. j ava2s . com*/ } else if (current.getName().equals(".")) { // skip - do nothing } else if (backOnes > 0) { backOnes--; } else { ourCanonicalVersion.insert(0, "/" + current.getName()); } current = current.getParentFile(); } return ourCanonicalVersion.toString(); }
From source file:phex.util.StringUtils.java
public static String generateRandomUUIDString() { byte[] uuid = new byte[16]; randomizer.nextBytes(uuid);//from w w w . j a v a 2 s . c om uuid[6] &= (byte) 0x0F; //0000 1111 uuid[6] |= (byte) 0x40; //0100 0000 set version 4 (random) uuid[8] &= (byte) 0x3F; //0011 1111 uuid[8] |= (byte) 0x80; //1000 0000 // generate string rep... StringBuffer buf = new StringBuffer(36); for (int i = 0; i < 16; i++) { int val = uuid[i] & 0xFF; buf.append(HEX_CHARS[val >> 4]); buf.append(HEX_CHARS[val & 0x0F]); } buf.insert(8, '-'); buf.insert(13, '-'); buf.insert(18, '-'); buf.insert(23, '-'); // -> 00000000-0000-0000-0000-000000000000 return buf.toString(); }
From source file:net.sf.xmm.moviemanager.http.HttpUtil.java
public static StringBuffer getHtmlNiceFormat(StringBuffer buffer) { int index = 0; // Format html Pattern p = Pattern.compile("</.+?>"); Matcher m = p.matcher(buffer); while (m.find(index)) { index = m.start();/*w w w . j a v a 2 s.com*/ int index2 = buffer.indexOf(">", index) + 1; buffer.insert(index2, SysUtil.getLineSeparator()); index++; } return buffer; }
From source file:org.squale.squaleweb.util.SqualeWebActionUtils.java
/** * Permet d'aller la ligne dans un menu pour pouvoir afficher le nom en entier au lieu qu'il soit tronqu car la * charte graphique impose une taille fixe * //from ww w. java 2 s .c om * @param pItem l'item a couper * @return l'item avec des '\n' tous les n caractres */ public static String formatStringForMenuItem(String pItem) { final int MAX_CHAR = 26; // Nombre de caractres qu'on suppose affichable StringBuffer result = new StringBuffer(pItem); int nbInsertion = result.length() / MAX_CHAR; for (int i = 1; i <= nbInsertion; i++) { result.insert(i * MAX_CHAR, "... "); // On dcale de 3 caractres } return result.toString(); }
From source file:org.castor.cpaptf.rel1toN.TestLoadBi1toN.java
private static String format(final String str, final int len, final boolean after) { StringBuffer sb = new StringBuffer(); if (str != null) { sb.append(str);//from ww w .j a v a2 s .c om for (int i = str.length(); i < len; i++) { if (after) { sb.append(' '); } else { sb.insert(0, ' '); } } } else { for (int i = 0; i < len; i++) { if (after) { sb.append(' '); } else { sb.insert(0, ' '); } } } return sb.toString(); }
From source file:org.hardisonbrewing.s3j.FileSyncer.java
static String getBucketPath(File file) { StringBuffer stringBuffer = new StringBuffer(); while (file != null && file.getParent() != null) { if (stringBuffer.length() > 0) { stringBuffer.insert(0, File.separator); }// w ww . j av a2 s.c o m stringBuffer.insert(0, file.getName()); file = file.getParentFile(); } String path = stringBuffer.toString(); path = path.replace(' ', '_'); return path; }