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 generateString(int length) {
    StringBuffer sb = new StringBuffer();
    Random random = new Random();
    for (int i = 0; i < length; i++) {
        sb.append(random.nextInt());//from www . jav  a  2  s  .  co m
    }
    return sb.toString();
}

From source file:Main.java

/**
 * prints the passed array/*from  www  . j  av a2s.c om*/
 * @param _tag the tag for the print
 * @param arr the array to print
 */
public static void printArray(String _tag, double[] arr) {
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < arr.length; i++) {
        sb.append(arr[i]);
        sb.append("\n");
    }
    Log.e(_tag, sb.toString());
    Log.e(_tag, "--------------------");
}

From source file:Main.java

private static String generateNonce(int length) {
    Random random = new Random(System.currentTimeMillis());
    if (length < 10)
        length = 10;// ww w .  j a v  a  2  s . c o m

    int MAX_LEN = NONCE_SAMPLE.length();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < length; i++) {
        buf.append(NONCE_SAMPLE.charAt(random.nextInt(MAX_LEN)));
    }
    return buf.toString();
}

From source file:Main.java

public static String getClassNameFromTableName(String tableName) {
    Pattern p = Pattern.compile("(_+|^)(\\w?)");
    Matcher m = p.matcher(tableName);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, m.group(2).toUpperCase());
    }/*from  w w w . j  a v a2s. c  o m*/
    m.appendTail(sb);

    return sb.toString();
}

From source file:Main.java

private static int getLength(int from, int to) {
    int newLength = to - from;
    if (newLength < 0) {
        StringBuffer sb = new StringBuffer(from);
        sb.append(" > ").append(to);
        throw new IllegalArgumentException(sb.toString());
    }//ww w.  j  ava 2 s  .  com
    return newLength;
}

From source file:Main.java

private static String genRandomString(int pLength) {
    Random r = new Random();
    String letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < pLength; i++) {
        sb.append(letter.charAt(r.nextInt(1000000) % (letter.length())));
    }/*from   w ww.ja va  2  s . com*/
    return sb.toString();
}

From source file:Main.java

/**
 * Escapes specified string (that is, <tt>'&lt;'</tt> is replaced by "<tt>&amp;#60</tt>;",
 * <tt>'&amp;'</tt> is replaced by "<tt>&amp;#38;</tt>", etc).
 * //from   w  ww.  ja  v  a  2 s  .co m
 * @param string string to be escaped
 * @return escaped string
 */
public static final String escapeXML(String string) {
    StringBuffer escaped = new StringBuffer();
    escapeXML(string, escaped);
    return escaped.toString();
}

From source file:Main.java

public static String makeDeviceID(byte[] bytes) {
    if (bytes.length < 12)
        return "";
    StringBuffer sb = new StringBuffer();
    for (byte b : bytes) {
        sb.append(Integer.toHexString((b & 0xFF) | 0xFFFFFF00).substring(6).toUpperCase());
    }// w w  w  . j ava 2 s .  c om
    return sb.toString();
}

From source file:Main.java

public static <K, V> String mapToString(Map<K, V> map, String seperator) {
    StringBuffer sb = new StringBuffer();
    for (Entry<K, V> entry : map.entrySet()) {
        sb.append(entry.getKey() + seperator + entry.getValue() + "\n");
    }/*from w  w  w.ja v  a 2s  . c o m*/
    return sb.toString();
}

From source file:Main.java

/**
 * Escape invalid control characters from a text to be included in XML.
 * String types may contain C0 control characters that are not legal in XML.
 * This method convert these to the Unicode replacement character 0xFFFD.
 * //from  ww w .j  a  v  a  2 s  .  c om
 * @param text
 *            the text to be escaped.
 * @return the escaped text.
 */
public static String escapeInvalidXmlChars(String text) {
    StringBuffer ret = new StringBuffer();

    for (int i = 0; i < text.length(); i++) {
        ret.append(escapeChar(text.charAt(i)));
    }

    return ret.toString();
}