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

/**
 * CDATA sections can not have a "]]>" in them. This method takes the input and wraps it up in one or more CDATA sections, converting any "]]>" strings into
 * "]]>".//from   ww  w  .  j  a va 2  s  .  c o  m
 */
public static String wrapStringInCDATA(final String input) {
    final StringBuffer retValue = new StringBuffer("<![CDATA[");
    retValue.append(input.replaceAll(END_CDATA_RE, END_CDATA_RE + END_CDATA_REPLACE + START_CDATA));
    retValue.append("]]>");
    return retValue.toString();
}

From source file:com.zb.app.common.util.SerialNumGenerator.java

private static String getSuffix(Long id) {
    Long num = 1l;/*  w  w  w.  ja  v a2s  .c o m*/
    Random random = new Random();
    if (id != null) {
        num = id * (random.nextInt(1000));
        if (num < 100) {
            num = num * (random.nextInt());
        }
        num = (id * (random.nextInt(1000))) % 100000;// id??
    }

    StringBuffer suffixBuffer = new StringBuffer();
    suffixBuffer.append(String.valueOf(num)).append(random.nextInt(1000));
    return StringUtils.leftPad(suffixBuffer.toString(), 8, '0');
}

From source file:Main.java

/**
 * Convert the given map to a string./*from  w ww  .j av a 2s.  c  o  m*/
 * @param m Any map to display
 * @return A string (multi-line) containing a view of the desired map
 */
public static <A, B> String toString(Map<A, B> m) {
    StringBuffer sb = new StringBuffer();
    sb.append("[\n");
    for (A key : m.keySet()) {
        sb.append("  " + key + " => " + m.get(key) + "\n");
    }
    sb.append("]");
    return sb.toString();
}

From source file:Main.java

/**
 * Apply the toString() method recursively to this throwable and all its causes.
 * The idea is to get cause information as in printStackTrace() without the stack trace.
 *
 * @param t the throwable to print./*from w  w w  .  ja v  a 2  s  . c  o m*/
 * @return
 */
public static String getThrowableAndCausesAsString(Throwable t) {
    StringBuffer buf = new StringBuffer();
    buf.append(t.toString());
    if (t.getCause() != null) {
        buf.append("\nCaused by: ");
        buf.append(getThrowableAndCausesAsString(t.getCause()));
    }
    return buf.toString();
}

From source file:Main.java

private static SecretKeySpec createKey(String key) {
    byte[] data = null;
    if (key == null) {
        key = "";
    }//from   w  ww . j  a va 2  s  .c  o  m
    StringBuffer sb = new StringBuffer(16);
    sb.append(key);
    while (sb.length() < 16) {
        sb.append("0");
    }
    if (sb.length() > 16) {
        sb.setLength(16);
    }
    try {
        data = sb.toString().getBytes("UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return new SecretKeySpec(data, "AES");
}

From source file:Main.java

public static String byteToHex(byte data) {
    StringBuffer buf = new StringBuffer();
    buf.append(toHexChar((data >>> 4) & 0x0F));
    buf.append(toHexChar(data & 0x0F));
    return buf.toString();
}

From source file:Main.java

public static String wrappText(String p_text, String locale) {
    if (p_text == null || p_text.trim().length() == 0) {
        return null;
    }/*from w w w. j  av  a 2  s .com*/

    StringBuffer sb = new StringBuffer();
    sb.append("<?xml version=\"1.0\"?>");
    sb.append("<diplomat locale=\"").append(locale).append("\" version=\"2.0\" datatype=\"xlf\">");
    sb.append("<translatable>");
    sb.append(p_text);
    sb.append("</translatable>");
    sb.append("</diplomat>");

    return sb.toString();
}

From source file:Main.java

public static String numToK(int number) {
    if (number < 10000) {
        return String.valueOf(number);
    } else {/*  w  ww .  jav  a2s.c o m*/
        float value = number * 1.0f / 10000;
        StringBuffer sb = new StringBuffer(String.valueOf(value));
        sb.append("K");
        return sb.toString();
    }
}

From source file:Main.java

public static String SendAllJsonMessageMass(String mediaId, Boolean bool, String gourpId) {
    StringBuffer sb = new StringBuffer();
    sb.append("{");
    sb.append("\"msgtype\":\"mpnews\",");
    sb.append("\"mpnews\":{");
    sb.append("\"media_id\":\"").append(mediaId).append("\"");
    sb.append("},");
    sb.append("\"filter\":{");
    sb.append("\"is_to_all\":").append(bool);
    sb.append("\"group_id\":\"").append(gourpId).append("\"");
    sb.append("}}");
    return sb.toString();
}

From source file:Main.java

public static String getGooglePlayUrl(String utmSource, String utmContent) {
    Uri.Builder builder = new Uri.Builder();
    builder.scheme("https");
    builder.authority("play.google.com");
    builder.path("/store/apps/details");
    builder.appendQueryParameter("id", "com.konifar.kotoha");

    if (utmSource != null && utmContent != null) {
        StringBuffer sb = new StringBuffer();
        sb.append("utm_source=");
        sb.append(utmSource);/* w w  w .j a  v  a  2  s  .  c o m*/
        sb.append("&utm_medium=direct");
        sb.append("&");
        sb.append("utm_content=");
        sb.append(utmContent);
        builder.appendQueryParameter("referrer", sb.toString());
    }

    return builder.build().toString();
}