Example usage for java.lang StringBuffer toString

List of usage examples for java.lang StringBuffer toString

Introduction

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

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public synchronized String toString() 

Source Link

Usage

From source file:Main.java

public static String getNonce() {
    String base = "abcdefghijklmnopqrstuvwxyz0123456789";
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 18; i++) {
        int number = random.nextInt(base.length());
        sb.append(base.charAt(number));//from  w w  w .j  a  v a2 s .c om
    }
    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;/*  w  w w. j a  v  a  2s.  co m*/
    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 byte[] getIV() {
    String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 16; i++) {
        int number = random.nextInt(base.length());
        sb.append(base.charAt(number));/*from ww w.  ja  v a 2  s  .  com*/
    }
    return sb.toString().getBytes();
}

From source file:Main.java

public static String getUserAgent() {
    StringBuffer sb = new StringBuffer("Mapbox Android SDK");

    if (getVersionNumber() != null) {
        sb.append("/");
        sb.append(getVersionNumber());/*from   w  w w.  j  ava2  s.  c o  m*/
    }

    return sb.toString();
}

From source file:com.fengduo.bee.commons.core.utils.Identities.java

/**
 * ??n?/*from  w w  w .ja v  a  2s. c o  m*/
 */
public static String randomNum(int n) {
    Random r = new Random(System.currentTimeMillis());
    StringBuffer buf = new StringBuffer(n);
    for (int i = 0; i < n; i++) {
        buf.append(r.nextInt(10));
    }
    return buf.toString();
}

From source file:Main.java

private static String makeIndent(int indentOffset) {
    /* 448 */if (indentOffset == 0) {
        /* 449 */return "";
        /*     */}
    /* 451 */StringBuffer sb = new StringBuffer();
    /* 452 */while (indentOffset > 0) {
        /* 453 */sb.append(' ');
        /* 454 */indentOffset--;
        /*     */}
    /* 456 */return sb.toString();
    /*     */}// w w w .  jav a 2  s .c  o  m

From source file:Main.java

private static String padHex(String s, int i) {
    StringBuffer tmpBuffer = new StringBuffer();
    if (s.length() < i) {
        for (int j = 0; j < i - s.length(); j++) {
            tmpBuffer.append('0');
        }/* w w w  .jav a  2  s.c  o  m*/
    }
    return tmpBuffer.toString();
}

From source file:Main.java

/**In order to create a 64 bit binary string, the zero-padding on the left of the value is carried out
 *  @param value the string to pad/*from   w  ww.  j a  va 2 s.  com*/
 *  @return Padded string
 */
public static String padding64(String value) {
    StringBuffer sb = new StringBuffer();
    sb.append(value);

    for (int i = 0; i < 64 - value.length(); i++) {
        sb.insert(0, "0");
    }

    return sb.toString();
}

From source file:Main.java

public static String md5(String s) {
    if (null == digest)
        return "";

    // Create MD5 Hash
    digest.reset();/*from  w w  w. j a v  a2 s . c o  m*/
    digest.update(s.getBytes());
    byte messageDigest[] = digest.digest();

    // Create Hex String
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < messageDigest.length; i++)
        hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
    return hexString.toString();
}

From source file:Main.java

private static String createLog(String log) {
    StringBuffer buffer = new StringBuffer();
    buffer.append(methodName);//from   w  w  w . ja  v  a  2s. c  o  m
    buffer.append("(").append(className).append(":").append(lineNumber).append(")");
    buffer.append(log);
    return buffer.toString();
}