Example usage for java.lang StringBuffer append

List of usage examples for java.lang StringBuffer append

Introduction

In this page you can find the example usage for java.lang StringBuffer append.

Prototype

@Override
    public synchronized StringBuffer append(double d) 

Source Link

Usage

From source file:Main.java

private static String arrayToString(JSONArray ar) throws JSONException {
    StringBuffer bfr = new StringBuffer();
    for (int i = 0; i < ar.length(); i++) {
        bfr.append(ar.getString(i));
        if (i != ar.length() - 1)
            bfr.append(",");
    }//from  w  ww . jav a2s.c o m
    return bfr.toString();
}

From source file:Main.java

public static String numberCheck(String num) {
    if (num == null || num.length() == 0) {
        return "";
    }/*from w ww .ja v  a  2s  .c o m*/
    Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[34578]\\d{9})|(?:861[34578]\\d{9}))(?!\\d)");
    Matcher matcher = pattern.matcher(num);
    StringBuffer bf = new StringBuffer(64);
    while (matcher.find()) {
        bf.append(matcher.group()).append(",");
    }
    int len = bf.length();
    if (len > 0) {
        bf.deleteCharAt(len - 1);
    }
    return bf.toString();
}

From source file:Main.java

public static String getMapAppendUrl(Map<String, String> params) {
    StringBuffer sb1 = new StringBuffer();
    for (String key : params.keySet()) {
        sb1.append(key);
        sb1.append("=");
        sb1.append((String) params.get(key));
        sb1.append("&");
    }//ww  w. ja  v a  2s. c  om
    sb1.deleteCharAt(sb1.length() - 1);
    return sb1.toString();
}

From source file:org.hardisonbrewing.s3j.HttpUtil.java

public static void printHeaders(HttpMessage httpMessage) {

    for (Header header : httpMessage.getAllHeaders()) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("    ");
        stringBuffer.append(header.getName());
        stringBuffer.append(": ");
        stringBuffer.append(header.getValue());
        System.out.println(stringBuffer.toString());
    }/*from w w  w .  j av a2s. c o m*/
}

From source file:Main.java

public static String bytesToString(byte[] bytes) {
    if (bytes == null)
        return "";
    StringBuffer sb = new StringBuffer();
    for (byte b : bytes) {
        sb.append(String.format("%02x ", b & 0xFF));
    }//from   w w  w.j  a  v  a2s  .c o m
    String str = sb.toString();
    if (str.length() > 0) {
        str = str.substring(0, str.length() - 1);
    }
    return str;
}

From source file:Main.java

public static String toXML(Object obj) {
    StringBuffer xml = new StringBuffer();
    StringBuffer space = new StringBuffer();
    toXMLCycle(obj, xml, space);//from www . ja v  a  2  s. co m

    StringBuffer result = new StringBuffer();
    result.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
    result.append(
            "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\r\n");
    result.append("<plist version=\"1.0\">\r\n");
    result.append(xml);
    return result.toString();
}

From source file:StringUtils.java

/**
 * Given an array of strings, return a comma-separated list of its elements.
 * @param strs Array of strings//w  w w . ja v a2s .c o  m
 * @return Empty string if strs.length is 0, comma separated list of strings
 * otherwise
 */

public static String arrayToString(String[] strs) {
    if (strs.length == 0) {
        return "";
    }
    StringBuffer sbuf = new StringBuffer();
    sbuf.append(strs[0]);
    for (int idx = 1; idx < strs.length; idx++) {
        sbuf.append(",");
        sbuf.append(strs[idx]);
    }
    return sbuf.toString();
}

From source file:PassPhrase.java

public static String getNext() {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < MIN_LENGTH; i++) {
        sb.append(goodChar[r.nextInt(goodChar.length)]);
    }/*from  www.j  av a 2 s .  c o  m*/
    return sb.toString();
}

From source file:Main.java

public static String getLevel(String xpath, int level) {
    String[] paths = split(xpath);
    StringBuffer b = new StringBuffer();
    for (int i = 0; i < level; i++) {
        b.append(paths[i]);
        b.append(' '); // compensates the slash
    }/*from   www  .  jav  a2 s .  c  om*/
    b.append(paths[level]);
    b.append('/');
    return b.toString();
}

From source file:Main.java

private static String generateNonce(int length) {
    Random random = new Random(System.currentTimeMillis());
    if (length < 10)
        length = 10;/*from   w w w .j a  v  a2 s.com*/

    int MAX_LEN = NONCE_SAMPLE.length();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < length; i++) {
        buf.append(NONCE_SAMPLE.charAt(random.nextInt(MAX_LEN)));
    }
    return buf.toString();
}