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

public static String getJsonTempleteId(String templateIdShort) {
    StringBuffer sb = new StringBuffer();
    sb.append("{");
    sb.append("\"template_id_short\":\"").append(templateIdShort).append("\"");
    sb.append("}");
    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. j  a va2s.  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 lpad(String str, int length, String ch) {
    str = (str == null) ? "" : str;
    StringBuffer buf = new StringBuffer();
    int idx = str.length();
    while (idx < length) {
        buf.append(ch);/*from  w w w.jav a  2 s.c  o m*/
        idx++;
    }
    buf.append(str);
    return buf.toString();
}

From source file:Main.java

public static String getCustomerXml(String name) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("<customer>");
    buffer.append("<name>" + name + "</name>");
    buffer.append("</customer>");

    return buffer.toString();
}

From source file:Main.java

public static String toConstantFormat(String str) {
    int n = str.length();
    List<Character> list = new ArrayList<Character>();
    char c;//from  www.  j a v a 2  s.  co m
    for (int i = 0; i < n; i++) {
        c = str.charAt(i);
        if (i != 0 && Character.isUpperCase(c)) {
            list.add('_');
        }
        list.add(Character.toUpperCase(c));
    }

    StringBuffer buffer = new StringBuffer();
    for (Character character : list) {
        buffer.append(character);
    }
    return buffer.toString();

}

From source file:Main.java

/**
 * Unescapes specified string. Inverse operation of escapeXML(...).
 * // w w w. j av a2  s  . c o m
 * @param text string to be unescaped
 * @return unescaped string
 */
public static final String unescapeXML(String text) {
    StringBuffer unescaped = new StringBuffer();
    unescapeXML(text, 0, text.length(), unescaped);
    return unescaped.toString();
}

From source file:Main.java

public static String getHexString(byte[] messageid) {
    StringBuffer sb = new StringBuffer();
    if (messageid.length > 0) {
        for (byte b : messageid) {
            sb.append(String.format("%02X", b));
        }//  w w w . j a  va 2  s. c  o m
    }
    return sb.toString();
}

From source file:Main.java

public static String inputStream2String(InputStream in) throws IOException {
    StringBuffer out = new StringBuffer();
    byte[] b = new byte[4096];
    for (int n; (n = in.read(b)) != -1;) {
        out.append(new String(b, 0, n));
    }//from  w w  w  . ja  v  a2s .c  o  m
    return out.toString();
}

From source file:Main.java

/**
 * Pad a string S on left out to width W using padding character PAD.
 *
 * @param s// w ww.ja  v  a  2s.  c om
 *     string to pad
 * @param width
 *     width of field to add padding
 * @param pad
 *     character to use for padding
 * @return padded string
 */
public static String padLeft(String s, int width, char pad) {
    StringBuffer sb = new StringBuffer();
    for (int i = s.length(); i < width; i++) {
        sb.append(pad);
    }
    sb.append(s);
    return sb.toString();
}

From source file:Main.java

private static String getMd5(String md5) throws Exception {
    MessageDigest md = java.security.MessageDigest.getInstance(MD5);
    byte[] array = md.digest(md5.getBytes(CHARSET_NAME));
    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 w w  . j a  v  a  2 s.com
    return sb.toString();
}