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 generateCommentID(String title, String date) {
    start++;//from w  w  w .java 2  s  .  c o m
    StringBuffer result = new StringBuffer();
    result.append(title).append(date).append(start);
    return result.toString();
}

From source file:Main.java

public static String getCreditPaymentXml(String cardHolder, String cardNum, String cardSec, String cardExp) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("<payment>");
    buffer.append("<type>Credit</type>");
    buffer.append("<cardHolder>" + cardHolder + "</cardHolder>");
    buffer.append("<cardNum>" + cardNum + "</cardNum>");
    buffer.append("<cardSec>" + cardSec + "</cardSec>");
    buffer.append("<cardExp>" + cardExp + "</cardExp>");
    buffer.append("</payment>");

    return buffer.toString();
}

From source file:Main.java

public static String getMobileInfo() {
    StringBuffer sb = new StringBuffer();
    try {/*from  w w  w.jav a2  s .  c o m*/

        Field[] fields = Build.class.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            String name = field.getName();
            String value = field.get(null).toString();
            sb.append(name + "=" + value);
            sb.append("\n");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return sb.toString();
}

From source file:Main.java

static String makeXMLOpenElement(String elementName, String[][] attributes) {
    StringBuffer sb = new StringBuffer();
    sb.append("<");
    sb.append(elementName);//from   ww  w  .j  a va  2s .c o  m
    if (attributes != null) {
        for (int pos = 0; pos < attributes.length; pos++) {
            if (attributes[pos][1] != null) {
                sb.append(" ");
                sb.append(attributes[pos][0]);
                sb.append("=\"");
                sb.append(toXMLString(attributes[pos][1]));
                sb.append("\"");
            }
        }
    }
    sb.append(">");
    return sb.toString();
}

From source file:Main.java

public static String mergeAllElements(Collection<String> collection) {
    StringBuffer stringBuffer = new StringBuffer();
    Object[] str = collection.toArray();

    for (int i = 0; i < str.length; i++) {
        if (i == str.length - 1) {
            stringBuffer.append(str[i].toString());
        } else {//from  ww w.ja v a 2  s .c o  m
            stringBuffer.append(str[i].toString()).append(",");
        }
    }

    return stringBuffer.toString();
}

From source file:Main.java

public static String getReqPama(Map<String, String> params) {
    StringBuffer sBuffer = new StringBuffer();
    Iterator<?> iterator = params.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        sBuffer.append(key + "=" + params.get(key) + "&");
    }/*ww w .  j  a  va2 s .c om*/
    String reqString = sBuffer.toString();
    return reqString.substring(0, reqString.length() - 1);
}

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 va2 s. c  om
    return sb.toString();
}

From source file:Main.java

private static StringBuffer breakUpFFox(String str, int chars) {
    StringBuffer sb = new StringBuffer();
    int z = 0;/*from   w w  w.ja  v  a  2 s. c om*/
    for (int i = 0; i < str.length(); i++) {
        switch (str.charAt(i)) {
        case ' ':
            z = 0;
            sb.append(str.charAt(i));
            break;
        /*case '-':
          sb.append(str.charAt(i));
          int q = str.indexOf(" ", i);
          int p = str.indexOf("-", i);
          if (q == -1 && p == -1) {
        sb.append("&#8203;");
        z = 0;
          } else if (q > (chars - z) && p > (chars - z)) {
        sb.append("&#8203;");
        z = 0;
          } else {
        z++;
          }
          break;*/
        case '&':
            sb.append("&");
            if (str.length() > i + 4 && !str.substring(i + 1, i + 4).equals("amp;")) {
                sb.append("amp;");
            }
            z++;
            break;
        default:
            sb.append(str.charAt(i));
            z++;
        }
        if (z > 0 && z % chars == 0) {
            sb.append(" ");
        }
    }
    return sb;
}

From source file:Main.java

private static String unEscape(String s) {
    StringBuffer sbuf = new StringBuffer();
    int l = s.length();
    int ch = -1;/*from  w  w w . j a v a  2s . c o m*/
    int b, sumb = 0;
    for (int i = 0, more = -1; i < l; i++) {
        /* Get next byte b from URL segment s */
        switch (ch = s.charAt(i)) {
        case '%':
            ch = s.charAt(++i);
            int hb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
                    & 0xF;
            ch = s.charAt(++i);
            int lb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
                    & 0xF;
            b = (hb << 4) | lb;
            break;
        case '+':
            b = ' ';
            break;
        default:
            b = ch;
        }
        /* Decode byte b as UTF-8, sumb collects incomplete chars */
        if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
            sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
            if (--more == 0)
                sbuf.append((char) sumb); // Add char to sbuf
        } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
            sbuf.append((char) b); // Store in sbuf
        } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
            sumb = b & 0x1f;
            more = 1; // Expect 1 more byte
        } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
            sumb = b & 0x0f;
            more = 2; // Expect 2 more bytes
        } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
            sumb = b & 0x07;
            more = 3; // Expect 3 more bytes
        } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
            sumb = b & 0x03;
            more = 4; // Expect 4 more bytes
        } else /* if ((b & 0xfe) == 0xfc) */ { // 1111110x (yields 1 bit)
            sumb = b & 0x01;
            more = 5; // Expect 5 more bytes
        }
        /* We don't test if the UTF-8 encoding is well-formed */
    }
    return sbuf.toString();
}

From source file:Main.java

public static String readIt(InputStream stream) throws IOException {
    StringBuffer out = new StringBuffer();
    byte[] b = new byte[4096];
    for (int n; (n = stream.read(b)) != -1;) {
        out.append(new String(b, 0, n));
    }/*  w  w  w  . j  av  a 2s. c  o  m*/
    return out.toString();
}