Example usage for java.lang StringBuffer StringBuffer

List of usage examples for java.lang StringBuffer StringBuffer

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public StringBuffer() 

Source Link

Document

Constructs a string buffer with no characters in it and an initial capacity of 16 characters.

Usage

From source file:Main.java

public static String binaryToHexString(byte[] messageDigest) {
    // Create Hex String
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < messageDigest.length; i++) {
        int by = 0xFF & messageDigest[i];
        if (by < 0x10) {
            hexString.append("0").append(Integer.toHexString(by));
        } else if (by >= 0x10) {
            hexString.append(Integer.toHexString(by));
        }/*from   www . java 2  s  .com*/
    }
    return hexString.toString();
}

From source file:Main.java

public static String lpad(String str, int length, String ch) {
    str = (str == null) ? "" : str;
    StringBuffer buf = new StringBuffer();
    int idx = str.length();
    while (idx < length) {
        buf.append(ch);/*from w  w w.j  a  v  a 2 s  . com*/
        idx++;
    }
    buf.append(str);
    return buf.toString();
}

From source file:Main.java

public static String inputStreamToString(InputStream in) throws Exception {
    StringBuffer out = new StringBuffer();
    byte[] b = new byte[4096];
    for (int n; (n = in.read(b)) != -1;) {
        out.append(new String(b, 0, n));
    }/*  w  ww .j a va2 s  . com*/
    return out.toString();
}

From source file:Main.java

public static String formatFaces(String emojiName) {
    //System.out.println("emojiName=="+emojiName);
    StringBuffer sb = new StringBuffer();
    sb.append("<img src=\"emoji_");
    sb.append(emojiName);//from   w w w.jav a2  s  . co  m
    sb.append("\">");
    return sb.toString();
}

From source file:Main.java

public static String getStringByLength(String string, int length) {
    StringBuffer stringBuffer = new StringBuffer();

    int valueLength = 0;
    String chinese = "[\u4e00-\u9fa5]";

    for (int i = 0; i < string.length(); i++) {

        String temp = string.substring(i, i + 1);
        if (temp.matches(chinese)) {
            if (valueLength >= (length - 1))
                break;
            valueLength += 2;/*w  w w.  j  a  v a 2 s. com*/

        } else {
            if (valueLength >= length)
                break;
            valueLength += 1;

        }
        stringBuffer.append(temp);
    }
    return stringBuffer.toString();
}

From source file:Main.java

static private String toHexString(byte[] block) {
    StringBuffer buf = new StringBuffer();
    int len = block.length;
    for (int i = 0; i < len; i++) {
        byte2hex(block[i], buf);
        if (i < len - 1) {
            buf.append(":");
        }/*from   w  w w  . j a  va  2s . c om*/
    }
    return buf.toString();
}

From source file:Main.java

public static String getStringByStringBuffer(String... strings) {
    StringBuffer builder = new StringBuffer();
    for (String string : strings) {
        builder.append(string);//from   www. j a va2 s. c  o m
    }
    return builder.toString();
}

From source file:Main.java

private static String getNumericPrefix(String string) {
    StringBuffer numeric = new StringBuffer();

    if (string != null) {
        string = string.trim();/* w w  w .ja  v a  2  s.co m*/

        if (string.length() > 0) {

            StringBuffer buffer = new StringBuffer(string);
            char first = buffer.charAt(0);

            if (Character.isDigit(first)) {
                numeric.append(first);

                for (int i = 1; i < buffer.length(); i++) {
                    Character next = buffer.charAt(i);

                    if (Character.isDigit(next)) {
                        numeric.append(next);

                        // skip commas within numbers
                    } else if (next.equals(',')) {
                        continue;

                    } else {
                        break;
                    }
                }
            }
        }
    }

    return numeric.length() == 0 ? null : numeric.toString();
}

From source file:Main.java

public static String replaceByPosition(String str, String replaceStr, String expressStr, int position) {
    StringBuffer sb = new StringBuffer();
    String[] c = str.split(expressStr);
    for (int i = 0; c != null && i < c.length; i++) {
        if (i == position) {
            c[i] = str;/* w  ww  .  j  av a 2  s . com*/
        }
        sb.append(c[i]);
    }
    return sb.toString();
}

From source file:Main.java

public static String stripNonValidXMLCharacters(String in) {
    StringBuffer out = new StringBuffer(); // Used to hold the output.
    char current; // Used to reference the current character.

    if (in == null || ("".equals(in)))
        return ""; // vacancy test.
    for (int i = 0; i < in.length(); i++) {
        current = in.charAt(i); // NOTE: No IndexOutOfBoundsException caught here; it should not happen.
        if ((current == 0x9) || (current == 0xA) || (current == 0xD)
                || ((current >= 0x20) && (current <= 0xD7FF)) || ((current >= 0xE000) && (current <= 0xFFFD))
                || ((current >= 0x10000) && (current <= 0x10FFFF))) {

            out.append(current);/* w w  w  .  j a  v a 2  s  . c  o  m*/
        } else {
            Log.e("Falmarri", "Not a valid character " + new Character(current));
        }
    }
    return out.toString();
}