List of usage examples for java.lang StringBuffer StringBuffer
@HotSpotIntrinsicCandidate
public StringBuffer()
From source file:Main.java
public static String toUtf8String(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 0 && c <= 255) { sb.append(c);/* w ww . j a va 2s . c o m*/ } else { byte[] b; try { b = String.valueOf(c).getBytes("utf-8"); } catch (Exception ex) { System.out.println(ex); b = new byte[0]; } for (int j = 0; j < b.length; j++) { int k = b[j]; if (k < 0) k += 256; sb.append("%" + Integer.toHexString(k).toUpperCase()); } } } return sb.toString(); }
From source file:Main.java
public static void logBytes(byte[] ucPtr) { String s;/*from w w w . ja va2s . co m*/ final StringBuffer sb = new StringBuffer(); for (int i = 0; i < ucPtr.length; ++i) { if (0 == i) { s = ""; } else { s = ", "; } s += String.valueOf(ucPtr[i]); sb.append(s); } // LogUtil.amengLog().d("++++ " + "data=" + sb); }
From source file:Main.java
public static String generateString(int length) { StringBuffer sb = new StringBuffer(); Random random = new Random(); for (int i = 0; i < length; i++) { sb.append(random.nextInt());/* w ww .j av a 2 s. c om*/ } return sb.toString(); }
From source file:Main.java
public static String appendAdditionalZeroOrOne(String binaryNum) { StringBuffer sb = new StringBuffer(); int current = 0; while (current < binaryNum.length()) { if ((binaryNum.length() - current) > 7) { sb.append(0);//from ww w . ja v a 2 s.c om } else { sb.append(1); } for (int i = current; i < (current + 7); i++) { sb.append(binaryNum.charAt(i)); } current += 7; } return sb.toString(); }
From source file:Main.java
public static String escapeCharacters(char ch[], int start, int length) { StringBuffer out = new StringBuffer(); for (int i = start; i < start + length; i++) { if (ch[i] >= 0x20 && ch[i] < 0x7f) { out.append(ch[i]);/*www . j a v a2 s . c o m*/ } else { out.append("&#" + (int) ch[i] + ';'); } } return out.toString(); }
From source file:Main.java
public static String logBytes(byte[] ucPtr) { String s;//from w w w. j a va 2 s.c om final StringBuffer sb = new StringBuffer(); for (int i = 0; i < ucPtr.length; ++i) { if (0 == i) { s = ""; } else { s = ", "; } s += String.valueOf(ucPtr[i]); sb.append(s); } return sb.toString(); }
From source file:Main.java
public static String hex(byte[] array) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); }/*from w ww . j a v a 2 s . com*/ return sb.toString(); }
From source file:Main.java
public static String getNodesText(NodeList nodes) { StringBuffer ret = new StringBuffer(); for (int i = 0, l = nodes.getLength(); i < l; i++) { ret.append(nodes.item(i).getTextContent()); }/*from www . j a va 2 s.c o m*/ return ret.toString(); }
From source file:Main.java
public static String getItemXml(String name, String price, String special) { StringBuffer buffer = new StringBuffer(); buffer.append("<item>"); buffer.append("<name>" + name + "</name>"); buffer.append("<price>" + price + "</price>"); buffer.append("<special>" + special + "</special>"); buffer.append("</item>"); return buffer.toString(); }
From source file:Main.java
public static String getCookie(ArrayList<String> lt) { StringBuffer sb = new StringBuffer(); for (String s : lt) { sb.append(s).append(";"); }/*from w ww . j ava 2 s .c o m*/ return sb.toString(); }