Example usage for java.lang StringBuilder toString

List of usage examples for java.lang StringBuilder toString

Introduction

In this page you can find the example usage for java.lang StringBuilder toString.

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public String toString() 

Source Link

Usage

From source file:Main.java

/**
 * Return an integer representation of a BCD array.
 *///from  w w w  .  java  2s.c  o  m
public static int bcdArrayToInt(byte[] bcdArray) {
    StringBuilder decimalString = new StringBuilder();

    for (Byte b : bcdArray) {
        decimalString.append(String.format("%02X", b));
    }

    return Integer.valueOf(decimalString.toString());
}

From source file:com.honnix.yaacs.util.MD5.java

/**
 * Get MD5 sum of the input data.//  w ww  . j a v  a  2  s. c o  m
 * 
 * @param data
 *            input data used to generate MD5 sum
 * @return MD5 sum of the input data, or null if no MD5 algorithm could be
 *         found
 */
public static String getMD5Sum(String data) {
    String encodedData = null;

    try {
        MessageDigest messageDigest = MessageDigest.getInstance("MD5");

        messageDigest.update(data.getBytes("US-ASCII"), 0, data.length());
        encodedData = new BigInteger(1, messageDigest.digest()).toString(16);
    } catch (NoSuchAlgorithmException e) {
        StringBuilder sb = new StringBuilder("No MD5 algorithm.").append(" Could not apply validation check.");

        LOG.error(sb.toString(), e);
    } catch (UnsupportedEncodingException e) {
        LOG.error("This should not happen anyway.", e);
    }

    return encodedData;
}

From source file:Main.java

public static String randomString(int len) {
    final StringBuilder sb = new StringBuilder(len);
    for (int i = 0; i < len; i++) {
        sb.append(AB.charAt(RAND.nextInt(AB.length())));
    }/*from w ww.ja  v  a  2s  .c o  m*/
    return sb.toString();
}

From source file:Main.java

public static String arrayStringToString(String[] args) {
    StringBuilder argumentStringBuilder = new StringBuilder();
    for (int i = 0; i < args.length; i++) {
        argumentStringBuilder.append(args[i]);
    }//  www.  j  av a  2s.c  o m
    return argumentStringBuilder.toString();
}

From source file:Main.java

public static String dateChange(String date) {
    StringBuilder sb = new StringBuilder();
    String[] dateStr = date.split("-");
    for (int i = 0; i < dateStr.length; i++) {
        sb.append(dateStr[i]);//w w  w  .  ja v a  2 s .  com
    }
    return sb.toString();
}

From source file:Main.java

public static String logContentValue(String prefix, ContentValues cv) {
    StringBuilder sb = new StringBuilder().append(prefix + ": ");
    for (String key : cv.keySet())
        sb.append(key).append("=").append(cv.getAsString(key)).append(" ");
    return sb.toString();
}

From source file:org.nuxeo.connect.tools.report.viewer.Viewer.java

public static PrintStream printThreadDump(ArrayNode infos, PrintStream out) throws IOException {
    StringBuilder sb = new StringBuilder();
    new ThreadDumpPrinter(infos).print(sb);
    out.print(sb.toString());
    return out;/*from  www .j  a v a 2 s  .c  o m*/
}

From source file:Main.java

public static String formatMac(String mac) {
    StringBuilder sb = new StringBuilder(mac);
    sb.insert(2, ":");
    sb.insert(5, ":");
    sb.insert(8, ":");
    sb.insert(11, ":");
    sb.insert(14, ":");
    return sb.toString();
}

From source file:Main.java

private static String appendStrs(Object... msgs) {
    if (null == msgs) {
        return "";
    }//from  w w  w. j  a  v a 2  s .  c o  m
    StringBuilder str = new StringBuilder();
    for (Object msg : msgs) {
        if (null != msg) {
            str.append(msg.toString());
        }
    }
    return str.toString();
}

From source file:Main.java

@NonNull
private static String readStream(InputStream stream) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
    String line = "";
    StringBuilder result = new StringBuilder();

    while ((line = reader.readLine()) != null) {
        result.append(line);/*from w  w  w  . j av a2  s.co  m*/
    }

    stream.close();
    return result.toString();
}