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:com.abiquo.api.spring.security.URLAuthenticator.java

private static String parse(final StringBuffer url, final String baseUri) {
    return StringUtils.substringAfterLast(url.toString(), baseUri);
}

From source file:Main.java

private static String getScalePattern(int scale) {
    StringBuffer sb = new StringBuffer("#0.");
    if (scale <= 0) {
        sb = new StringBuffer("#");
    }/*from ww  w . jav  a2  s.  c  o m*/
    for (int i = 0; i < scale; ++i) {
        sb.append("0");
    }
    return sb.toString();
}

From source file:Main.java

public static String toXml(String json) {
    JsonParser parser = new JsonParser();
    JsonElement rootJson = parser.parse(json);
    StringBuffer buff = new StringBuffer();
    serializeObjectAsXml((JsonObject) rootJson, buff);
    return buff.toString();
}

From source file:Main.java

public static String getCnASCII(String str) {
    StringBuffer sb = new StringBuffer();
    byte[] strByte = str.getBytes();
    for (int i = 0; i < strByte.length; i++) {
        sb.append(Integer.toHexString(strByte[i] & 0xff));
    }/*from w  w  w.j a  v a2s  .co  m*/
    return sb.toString();
}

From source file:Main.java

public static String stringToAscii(String val) {
    StringBuffer stringBuffer = new StringBuffer();
    char[] chars = val.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        stringBuffer.append((int) chars[i]);
    }/*w  ww  .  j a va  2s  .c  om*/

    return stringBuffer.toString();
}

From source file:Main.java

public static String generateRandomUTDID() {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0;//  ww  w . j  ava  2s .c  o  m
    while (i < 24) {
        localStringBuffer.append((char) (random.nextInt(25) + 65));
        i += 1;
    }
    return localStringBuffer.toString();
}

From source file:Main.java

public static String getCnASCII(String cnStr) {
    StringBuffer strBuf = new StringBuffer();
    byte[] bGBK = cnStr.getBytes();
    for (int i = 0; i < bGBK.length; i++) {
        strBuf.append(Integer.toHexString(bGBK[i] & 0xff));
    }//from  ww w. jav a2  s  .  com
    return strBuf.toString();
}

From source file:Main.java

public static String encode(String code) {
    MessageDigest md;/* ww w  .j a va 2 s .com*/
    try {
        md = MessageDigest.getInstance("MD5");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    md.update(code.getBytes());

    byte[] buffer = md.digest();
    StringBuffer hexString = new StringBuffer(2 * buffer.length);

    for (int i = 0; i < buffer.length; i++) {
        appendHexPair(buffer[i], hexString);
    }
    return hexString.toString();
}

From source file:com.mmj.app.common.util.SerialNumGenerator.java

public static String RandomNum(int length) {
    String str = "0123456789";
    Random random = new Random();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < length; i++) {
        int num = random.nextInt(10);
        buf.append(str.charAt(num));/*from ww w. j av  a2s .  c o  m*/
    }
    return buf.toString();
}

From source file:Main.java

private static String computeHash(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    digest.reset();//from   w  ww.j a  v a 2 s.c  o  m

    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();
}