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 computeHash(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    digest.reset();//from w  w w .j  ava  2  s  . c om

    byte[] byteData = digest.digest(input.getBytes("UTF-8"));
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < byteData.length; i++) {
        sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
    }

    return sb.toString();
}

From source file:Main.java

public static String GetDisplayTitle(String alias, String creditCode) {
    StringBuffer sb = new StringBuffer();
    if (alias != null && alias.trim() != "") {
        sb.append("[");
        sb.append(alias.trim());//from   w  ww  . j a v  a  2s.  com
        sb.append("] ");
    }
    if (creditCode != null && creditCode.trim() != "") {
        if (creditCode.length() > 10) {
            sb.append(creditCode.substring(0, 6));
            sb.append("...");
            sb.append(creditCode.substring(creditCode.length() - 4, 4));
        } else
            sb.append(creditCode);
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Forms an hex-encoded String of the specified byte array.
 *
 * @param byteArray The byte array to be hex-encoded.
 *
 * @return An hex-encoded String of the specified byte array.
 *///from   w  w  w . j a  va 2 s. c  om
public static String byteArrayToHexString(byte[] byteArray) {
    if (byteArray == null) {
        return "";
    }

    StringBuffer sb = new StringBuffer();

    for (byte b : byteArray) {
        sb.append(String.format("%02X ", b & 0xFF));
    }

    return sb.substring(0, sb.length() - 1).toString();
}

From source file:Main.java

public static String addAttribute(String p_name, String p_value) {
    StringBuffer l_buf = null;

    if (p_value != null) {
        l_buf = new StringBuffer();
        l_buf.append(" ").append(p_name).append("=\"");
        l_buf.append(p_value).append("\"");
        return l_buf.toString();
    }//from w  w w. j a  va  2 s  .  c o m

    return "";
}

From source file:Main.java

private static String longSetToString(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  w  w  w  . j  a v a2 s. c  o  m
        }
    }
    return dataSB.toString();
}

From source file:Main.java

/**
 * Returns attribute's getter method. If the method not found then
 * NoSuchMethodException will be thrown.
 * /*w ww  .  j av  a 2  s.co  m*/
 * @param cls
 *          the class the attribute belongs too
 * @param attr
 *          the attribute's name
 * @return attribute's getter method
 * @throws NoSuchMethodException
 *           if the getter was not found
 */
public final static Method getAttributeGetter(Class cls, String attr) throws NoSuchMethodException {
    StringBuffer buf = new StringBuffer(attr.length() + 3);
    buf.append("get");
    if (Character.isLowerCase(attr.charAt(0))) {
        buf.append(Character.toUpperCase(attr.charAt(0))).append(attr.substring(1));
    } else {
        buf.append(attr);
    }

    try {
        return cls.getMethod(buf.toString(), (Class[]) null);
    } catch (NoSuchMethodException e) {
        buf.replace(0, 3, "is");
        return cls.getMethod(buf.toString(), (Class[]) null);
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Method getSetMethod(Class objectClass, String fieldName) {

    try {/*from  ww  w  .ja v a  2s . c  o  m*/

        Class[] parameterTypes = new Class[1];

        Field field = objectClass.getDeclaredField(fieldName);

        parameterTypes[0] = field.getType();

        StringBuffer sb = new StringBuffer();

        sb.append("set");

        sb.append(fieldName.substring(0, 1).toUpperCase());

        sb.append(fieldName.substring(1));

        Method method = objectClass.getMethod(sb.toString(), parameterTypes);

        return method;

    } catch (Exception e) {

        e.printStackTrace();

    }

    return null;

}

From source file:Main.java

public static String MD5(String md5) {
    try {/*from   ww w . ja va2s. c  o  m*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] array = md.digest(md5.getBytes());
        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;
}

From source file:Main.java

public static String getMd5String(String md5) {
    try {//from  w  ww  . jav a 2s.c o  m
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
        byte[] array = md.digest(md5.getBytes());
        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 (java.security.NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String sha512(String what_to_encode) {
    final MessageDigest sha512;
    try {//from   w  w w .  j  a  va 2s . co m
        sha512 = MessageDigest.getInstance("SHA-512");
    } catch (NoSuchAlgorithmException e) {
        return "404";
    }
    sha512.update(what_to_encode.getBytes());
    byte byteData[] = sha512.digest();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < byteData.length; i++) {
        sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
    }
    return sb.toString();
}