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 hash(String pass) {
    MessageDigest md = null;/*  ww w .j  a va  2 s .  c om*/
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    md.update(pass.getBytes());
    byte byteData[] = md.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();

}

From source file:Main.java

public static String streamToString(InputStream input) throws IOException {

    InputStreamReader isr = new InputStreamReader(input);
    BufferedReader reader = new BufferedReader(isr);

    String line;/*from  ww  w.j av  a 2 s  . c  om*/
    StringBuffer sb = new StringBuffer();
    while ((line = reader.readLine()) != null) {
        sb.append(line);
    }
    reader.close();
    isr.close();
    return sb.toString();
}

From source file:Main.java

private static String getHexString(byte[] data) {
    StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < data.length; i++) {
        stringBuffer.append(Integer.toString((data[i] & 0xff) + 0x100, 16).substring(1));
    }/*from   w w w.j av  a2  s.c o m*/
    return stringBuffer.toString();
}

From source file:Main.java

public static String stringAppend(String[] strings) {

    if (strings != null) {
        int len = strings.length;
        StringBuffer stb = new StringBuffer(strings[0]);
        for (int i = 1; i < len; i++) {
            stb.append(strings[i]);
        }//from   w w  w.j a va 2s  .  c  om
        return stb.toString();
    } else {
        return null;
    }

}

From source file:Main.java

public static String bcd2StrIn(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));
    }/*w  w w. j  a va2s  .c  o  m*/
    return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1)
            : temp.toString();
}

From source file:Main.java

/**
 * Converts a {@link Collection} to a {@link String} separating entries by
 * <code>, </code>./* www  .j  a v a  2 s .c o  m*/
 */
public static String toString(Collection<?> collection) {
    final StringBuffer string = new StringBuffer();
    for (final Object object : collection) {
        string.append(object.toString());
        string.append(", ");
    }

    string.delete(string.length() - 2, string.length());

    return string.toString();
}

From source file:Main.java

static String tocsv(Iterable<String> set) {
    Iterator<String> iter = set.iterator();
    StringBuffer buf = new StringBuffer();
    if (iter.hasNext()) {
        buf.append(iter.next());
    }//from  w  ww.  j a  va  2 s.  co  m
    while (iter.hasNext()) {
        buf.append(",");
        buf.append(iter.next());
    }

    return buf.toString();
}

From source file:Main.java

/** @deprecated */
public static String join(String delim, Object[] col) {
    if (col == null || col.length == 0)
        return "";
    StringBuffer b = new StringBuffer("");

    for (int x = 0; x < col.length; x++) {
        b.append("" + col[x]);
        if (x < (col.length - 1))
            b.append(delim);/*from  ww  w  . ja va2  s.  c  om*/
    }
    return b.toString();
}

From source file:Main.java

public static String getMD5(String input) {
    String result = null;/*from  ww w  .j  a v  a 2  s .  c o  m*/

    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(input.getBytes());
        byte[] digest = md.digest();

        StringBuffer sb = new StringBuffer();

        for (byte b : digest) {
            sb.append(String.format("%02x", b & 0xff));
        }

        result = sb.toString();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        return result;
    }

}

From source file:Main.java

public static String getAbsoluteUri(String parent, String child) {
    if (parent == null || child == null) {
        return null;
    }//from  ww  w  .  j  a v a 2 s.  c o m
    if (isAbsolute(child)) {
        return child;
    }
    String[] parentPaths = parent.split("/");
    String[] childPaths = child.split("/");
    int start = parent.endsWith("/") ? 0 : 1;
    int upLevel = start;
    for (String childPath : childPaths) {
        String path = childPath.trim();
        if ("..".equals(path)) {
            upLevel++;
        } else {
            break;
        }
    }
    StringBuffer buffer = new StringBuffer();
    buffer.append('/');
    for (int i = 0; i < parentPaths.length - upLevel; i++) {
        String path = parentPaths[i];
        if (!"".equals(path)) {
            buffer.append(path);
            buffer.append('/');
        }
    }
    for (int i = upLevel - start; i < childPaths.length; i++) {
        buffer.append(childPaths[i]);
        if (i != childPaths.length - 1) {
            buffer.append('/');
        }
    }
    return buffer.toString();
}