Example usage for java.lang StringBuffer toString

List of usage examples for java.lang StringBuffer toString

Introduction

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

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public synchronized String toString() 

Source Link

Usage

From source file:Main.java

private static String generateInStr(String[] values, String quote) {

    StringBuffer buffer = new StringBuffer("( ");
    int i;/*w  ww.  ja va2s .c o  m*/
    for (i = 0; i < values.length - 1; i++)
        buffer.append(quote + values[i] + quote + ", ");
    buffer.append(quote + values[i] + quote + " )");
    return buffer.toString();
}

From source file:Main.java

public static String createXml(Map<String, Object> map) {
    StringBuffer sb = new StringBuffer();
    for (String key : map.keySet()) {
        sb.append("<").append(key).append(">");
        sb.append(map.get(key));//from  ww  w  .  ja v  a  2s .  co  m
        sb.append("</").append(key).append(">");
    }
    return sb.toString();
}

From source file:Main.java

public static String serializeCert(X509Certificate cert) throws CertificateEncodingException {
    StringBuffer buffer = new StringBuffer();
    buffer.append("-----BEGIN CERTIFICATE-----\n");
    buffer.append(Base64.encodeToString(cert.getEncoded(), Base64.DEFAULT));
    buffer.append("\n-----END CERTIFICATE-----");
    return buffer.toString();
}

From source file:Main.java

public static String makeHexText(byte[] data) {

    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < data.length; i++) {
        if (i != 0) {
            sb.append("-");
        }//from w  w  w .  ja  v a  2 s.  co  m
        sb.append(String.format("%02X", data[i]));
    }
    return sb.toString();
}

From source file:iddb.core.util.PasswordUtils.java

public static String getRandomString() {
    int length = 10;
    Random rand = new Random(System.currentTimeMillis());
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < length; i++) {
        int pos = rand.nextInt(charset.length());
        sb.append(charset.charAt(pos));//ww  w.java2s .  c  o  m
    }
    return sb.toString();
}

From source file:Main.java

public static String convertToCommaDelimited(String[] list) {
    StringBuffer ret = new StringBuffer("");
    for (int i = 0; list != null && i < list.length; i++) {
        ret.append(list[i]);/*from  w  w w  . ja  va 2  s .com*/
        if (i < list.length - 1) {
            ret.append(',');
        }
    }
    return ret.toString();
}

From source file:Main.java

public static String makeTimeString(long milliSecs) {
    StringBuffer sb = new StringBuffer();
    long m = milliSecs / (60 * 1000);
    sb.append(m < 10 ? "0" + m : m);
    sb.append(":");
    long s = (milliSecs % (60 * 1000)) / 1000;
    sb.append(s < 10 ? "0" + s : s);
    return sb.toString();
}

From source file:Main.java

public static String getSpecialString(String context, String encoding) {
    try {//www.  j  av  a  2 s.c om
        ByteArrayInputStream in = new ByteArrayInputStream(context.getBytes());
        InputStreamReader isr = new InputStreamReader(in, encoding);
        BufferedReader reader = new BufferedReader(isr);
        StringBuffer buffer = new StringBuffer();
        String result;
        while ((result = reader.readLine()) != null) {
            buffer.append(result);
        }
        return buffer.toString();
    } catch (Exception ex) {
        return context;
    }
}

From source file:Main.java

/**
 * Join an array of items./*from   ww w. j a v a 2  s . com*/
 * @param <T>
 * @param array
 * @param separator
 * @return string
 */
public static <T> String join(T[] array, String separator) {
    StringBuffer result = new StringBuffer();
    for (int i = 0; i < array.length; ++i) {
        if (i != 0)
            result.append(separator);
        result.append(array[i]);
    }
    return result.toString();
}

From source file:Main.java

public static String toString(int X[][]) {
    StringBuffer res = new StringBuffer("{");
    for (int row[] : X) {
        if (row != X[0]) {
            res.append(", ");
        }// w  w  w  . j  a  v a2 s  .  c o  m
        res.append(Arrays.toString(row));
    }
    res.append("}");
    return res.toString();
}