List of usage examples for java.lang StringBuffer StringBuffer
public StringBuffer(CharSequence seq)
From source file:Main.java
public static String byteArrayToHexString(byte[] b) { StringBuffer sb = new StringBuffer(b.length * 2); for (int i = 0; i < b.length; i++) { int v = b[i] & 0xff; if (v < 16) { sb.append('0'); }/*w ww.ja v a 2 s . co m*/ sb.append(Integer.toHexString(v)); } return sb.toString().toUpperCase(Locale.US); }
From source file:Main.java
public static String getUserAgent() { StringBuffer sb = new StringBuffer("Mapbox Android SDK"); if (getVersionNumber() != null) { sb.append("/"); sb.append(getVersionNumber());//w w w .j av a 2 s. co m } return sb.toString(); }
From source file:Util.java
public static String dateToIsoDateTime(String date) { StringBuffer sb = new StringBuffer(date); if (date.length() >= 8) { //20070101 -> 2007-01-01 //insert hyphens between year, month, and day sb.insert(4, '-'); sb.insert(7, '-'); //2007-01-01T173012 -> 2007-01-01T17:30:12 if (date.length() >= 15) { //insert colons between hours, minutes, and seconds sb.insert(13, ':'); sb.insert(16, ':'); //2007-01-01T17:30:12 -> 2007-01-01T17:30:12.000 //append milliseconds if (sb.toString().length() > 19) sb.insert(20, ".000"); else/* w w w . j a v a 2s .co m*/ sb.append(".000"); //2007-01-01T17:30:12.000 -> 2007-01-01T17:30:12.000Z //append UTC indicator if exists if (date.length() > 15 && date.charAt(15) == 'Z') sb.append('Z'); } if (sb.length() > 19) sb.setLength(19); } return sb.toString(); }
From source file:Main.java
public static final String toHexString(byte[] paramArrayOfByte) { int i = paramArrayOfByte.length * 2; StringBuffer localStringBuffer1 = new StringBuffer(i); int j = 0;/*from w w w. jav a2 s .com*/ while (true) { int k = paramArrayOfByte.length; if (j >= k) return localStringBuffer1.toString().toLowerCase(); int m = paramArrayOfByte[j] & 0xFF; if (m < 16) localStringBuffer1.append(48); String str = Integer.toHexString(m); StringBuffer localStringBuffer3 = localStringBuffer1.append(str); j += 1; } }
From source file:Main.java
public static String stringAppend(String[] strings) { if (strings != null) { int len = strings.length; StringBuffer stb = new StringBuffer(strings[0]); for (int i = 1; i < len; i++) { stb.append(strings[i]);/*from www .j a v a2s . com*/ } return stb.toString(); } else { return null; } }
From source file:Main.java
public static String enumerationToString(Enumeration enm) { StringBuffer sb = new StringBuffer(100); boolean firstItem = true; sb.append("["); while (enm.hasMoreElements()) { if (!firstItem) { sb.append(", "); }//from w ww.j a v a 2 s.c o m sb.append(enm.nextElement()); firstItem = false; } sb.append("]"); return sb.toString(); }
From source file:Main.java
public static String formatTo2Bit(int num) { if (num < 10) { StringBuffer sb;//from w w w. j ava2s . com sb = new StringBuffer("0"); sb.append(num); return sb.toString(); } else { return String.valueOf(num); } }
From source file:Main.java
public static String replace(String xml, Map value) { int len = xml.length(); StringBuffer buf = new StringBuffer(len); for (int i = 0; i < len; i++) { char c = xml.charAt(i); if (c == '$') { i++;/*from www . j a v a 2s . co m*/ StringBuffer key = new StringBuffer(); char temp = xml.charAt(i); while (temp != '}') { if (temp != '{') { key.append(temp); } i++; temp = xml.charAt(i); } String variable = (String) value.get(key.toString()); if (null == variable) { buf.append(""); } else { buf.append(variable); } } else { buf.append(c); } } return buf.toString(); }
From source file:Main.java
public static String replaceCharAt(String s, int pos, char c) { StringBuffer buf = new StringBuffer(s); buf.setCharAt(pos, c);/*from w ww . ja va 2s. c o m*/ return buf.toString(); }
From source file:Main.java
public static String getRandomPermutation(String s) { StringBuffer buffer = new StringBuffer(s); int n = s.length(); for (int i = 0; i < n; i++) { int random = generator.nextInt(n); buffer = swap(buffer, i, random); }// w ww.j a v a2s . co m return new String(buffer); }