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

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);
        idx++;// w  ww.j  a v a  2 s .co  m
    }
    buf.append(str);
    return buf.toString();
}

From source file:Main.java

private static String intSetToString(List<?> list) {
    final StringBuffer dataSB = new StringBuffer();

    for (int i = 0; i < list.size(); i++) {
        dataSB.append(list.get(i));
        if (i < list.size() - 1) {
            dataSB.append(SEPERATOR);/*from   ww  w .  j  a  v a2s  . c  om*/
        }
    }
    return dataSB.toString();
}

From source file:com.billing.ng.crypto.util.HashUtils.java

/**
 * Generates an alphanumeric salted hash token using the configured digest algorithm. The generated hash
 * is stripped of all non-alphanumeric characters to make it safe for use as an HTTP GET parameter value.
 *
 * @see com.billing.ng.crypto.context.HashAlgorithmHolder
 *
 * @param base string to use as the primary basis of the hash
 * @param appends additional strings to append to the plain-text password before hashing
 * @return hash string/*ww w . ja v  a  2  s .co  m*/
 */
public static String generateHash(String base, String... appends) {
    StringBuffer plainText = new StringBuffer();
    plainText.append(base);
    for (String string : appends)
        plainText.append(string);

    HashAlgorithm algorithm = HashAlgorithmHolder.getAlgorithm();

    byte[] bytes = algorithm.digestBytes(plainText.toString());
    return Base64.encodeBase64URLSafeString(bytes);
}

From source file:Main.java

public static String difference(String xpath1, String xpath2) {
    String[] paths1 = split(xpath1);
    String[] paths2 = split(xpath2);
    int length = Math.min(paths1.length, paths2.length);
    int index = 0;
    while (index < length && paths1[index].equals(paths2[index])) {
        index++;/*from w  w w .j  a  va 2 s.co  m*/
    }
    StringBuffer b = new StringBuffer();
    for (int i = 0; i < index; i++) {
        b.append(paths1[i]);
    }
    while (index < paths1.length) {
        b.append(paths1[index++]);
        b.append('/');
    }
    return b.toString();
}

From source file:Main.java

public static String arrayToString(String[] a) {
    StringBuffer result = new StringBuffer();
    if (a.length > 0) {
        result.append(a[0]);
        for (int i = 1; i < a.length; i++) {
            result.append("; ");
            result.append(a[i]);//from  w w  w . j a  v  a2 s .  c o  m
        }
    }
    return result.toString();
}

From source file:Main.java

/**
 * Returns <code>count</code> copies of the given character.
 * // ww w  .j a v  a  2s . c o  m
 * @param count
 * @param ch
 * @return
 */
public static String getNChars(int count, char ch) {
    StringBuffer buf = new StringBuffer(count);
    for (int i = 0; i < count; i++)
        buf.append(ch);
    return buf.toString();

}

From source file:Main.java

public static String bcd2Str(byte[] bytes) {
    StringBuffer temp = new StringBuffer(bytes.length * 2);
    for (int i = 0; i < bytes.length; i++) {
        temp.append((byte) ((bytes[i] & 0xf0) >>> 4));
        temp.append((byte) (bytes[i] & 0x0f));
    }//  ww w.j a v  a2  s. c  o m
    return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1)
            : temp.toString();
}

From source file:Main.java

public static String Bcd2Str(byte[] bytes) {
    StringBuffer temp = new StringBuffer(bytes.length * 2);

    for (int i = 0; i < bytes.length; i++) {
        temp.append((byte) ((bytes[i] & 0xf0) >>> 4));
        temp.append((byte) (bytes[i] & 0x0f));
    }//from ww  w.j  a va  2 s.  c  om
    return temp.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]);
        if (i < list.length - 1) {
            ret.append(',');
        }//  w  w  w  .  ja va 2s . c  om
    }
    return ret.toString();
}

From source file:Main.java

public static String calculateMD5(String string, String encoding) {
    try {//from  w w w . java2  s .c o m
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] array = md.digest(string.getBytes(Charset.forName(encoding)));
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < array.length; ++i) {
            sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString();
    } catch (NoSuchAlgorithmException e) {
    }
    return null;
}