List of usage examples for java.lang StringBuffer StringBuffer
@HotSpotIntrinsicCandidate
public StringBuffer()
From source file:Main.java
static String convertToHex(byte[] data) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < data.length; i++) { int halfbyte = (data[i] >>> 4) & 0x0F; int two_halfs = 0; do {//from w w w . ja v a2s .com if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte)); else buf.append((char) ('a' + (halfbyte - 10))); halfbyte = data[i] & 0x0F; } while (two_halfs++ < 1); } return buf.toString(); }
From source file:Main.java
public static String getParams(Map<String, String> form) { StringBuffer params = new StringBuffer(); int i = 0;/* w w w . j a va 2s.com*/ for (Map.Entry<String, String> entry : form.entrySet()) { if (i > 0) { params.append("&"); } params.append(entry.getKey()); params.append("="); params.append(entry.getValue()); i++; } return params.toString(); }
From source file:Main.java
public static String msgToXML(String phoneNumber, String smsContent, String from) { StringBuffer sbRoot = new StringBuffer(); addReportRootHead(sbRoot);//from ww w . ja va 2 s . c o m addReportRootNode(sbRoot, "msgtype", "sms"); addReportRootNode(sbRoot, "from", from); addReportRootNode(sbRoot, "phoneNumber", phoneNumber); addReportRootNode(sbRoot, "content", smsContent); addReportRootTail(sbRoot); return sbRoot.toString(); }
From source file:Main.java
public static String readerToString(BufferedReader reader) { StringBuffer rawBody = new StringBuffer(); String line = null;//ww w . j a va2 s. c om try { while ((line = reader.readLine()) != null) rawBody.append(line); } catch (Exception e) { /*report an error*/ } return rawBody.toString(); }
From source file:Main.java
public static String makeDeviceID(byte[] bytes) { if (bytes.length < 12) return ""; StringBuffer sb = new StringBuffer(); for (byte b : bytes) { sb.append(Integer.toHexString((b & 0xFF) | 0xFFFFFF00).substring(6).toUpperCase()); }//from w w w . j a v a 2s .com return sb.toString(); }
From source file:Main.java
private static String parseByte2HexStr(byte[] buf) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < buf.length; i++) { String hex = Integer.toHexString(buf[i] & 0XFF); if (hex.length() == 1) { // hex = '0' + hex; sb.append("0"); }// w w w. j a v a 2 s .c om sb.append(hex); } return sb.toString().toUpperCase(); }
From source file:Main.java
public static String fillString(String strValue, char ch, int iSign) { try {/* www . j a va2s.com*/ StringBuffer strTemp = new StringBuffer(); int iDifference = iSign - strValue.length(); if (iDifference <= 0) return strValue; for (int i = 0; i < iDifference; i++) strTemp.append(ch); strTemp.append(strValue); return strTemp.toString(); } catch (Exception ex) { return ""; } }
From source file:Main.java
public static String getNowDate() { StringBuffer sbBuffer = new StringBuffer(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sbBuffer.append(format.format(Calendar.getInstance().getTime())); return sbBuffer.toString(); }
From source file:Main.java
public static String stringArrayToString(String[] array) { StringBuffer result = new StringBuffer(); for (int i = 0; i < array.length - 1; i++) { result.append(array[i]).append(TAB); }/*w w w . j a va 2 s. co m*/ result.append(array.length - 1); return result.toString(); }
From source file:Main.java
public static String encodeUnicode(String str) { char[] utfBytes = str.toCharArray(); StringBuffer buffer = new StringBuffer(); for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) { String hexB = Integer.toHexString(utfBytes[byteIndex]); if (hexB.length() <= 2) { hexB = "00" + hexB; }//from w w w . ja v a 2 s .c o m buffer.append("\\u" + hexB); } return buffer.substring(0); }