Example usage for java.lang StringBuffer append

List of usage examples for java.lang StringBuffer append

Introduction

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

Prototype

@Override
    public synchronized StringBuffer append(double d) 

Source Link

Usage

From source file:Main.java

public static String getSizeText(Context context, long currentBytes, long totalBytes) {
    StringBuffer sizeText = new StringBuffer();
    if (totalBytes > 0) {
        sizeText.append(Formatter.formatFileSize(context, currentBytes));
        sizeText.append("/");
        sizeText.append(Formatter.formatFileSize(context, totalBytes));
    }/*from   w  w w  . ja v  a  2s  . c  om*/
    return sizeText.toString();
}

From source file:Main.java

/**
 * /*from  www. j  a va 2  s  .  c  o  m*/
 * Get a valid xPath string to enable retrieval of an Element by ORing
 * attributes name and their corresponding value. note that the full tag
 * path must also be stated
 * 
 * @param tagPath
 *            example: /calls/step
 * @param attrNames
 *            example: call_step
 * @param attrValues
 *            example: Call failed
 * 
 * @return A valid xPath string
 */
public static String getXpathOR(String tagPath, String[] attrNames, String[] attrValues) {
    StringBuffer buf = new StringBuffer();

    buf.append(tagPath);
    buf.append("[");
    for (int i = 0; i < attrValues.length; i++) {
        buf.append("@");
        buf.append(attrNames[i]);
        buf.append("=");
        buf.append("'");
        buf.append(attrValues[i]);
        buf.append("'");
        if (i != (attrValues.length - 1))
            buf.append(" or ");
    }
    buf.append("]");

    // System.out.println("Xpath generated: " + (retStr = buf.toString()));

    return buf.toString();

}

From source file:Main.java

public static String repeat(String str, int times) {
    StringBuffer sbf = new StringBuffer();
    for (int i = 0; i < times; i++) {
        sbf.append(str);
    }//  w w  w.  ja v a2 s.co m
    return sbf.toString();
}

From source file:Main.java

public static int queryCount(SQLiteDatabase db, String tableName, String where, String[] whereArgs) {
    StringBuffer stringBuffer = new StringBuffer("select count(*) from ");
    stringBuffer.append(tableName);
    if (where != null) {
        stringBuffer.append(" where ");
        stringBuffer.append(where);/*from w  w w .j  a  v a2s. co  m*/
    }
    Cursor cursor = db.rawQuery(stringBuffer.toString(), whereArgs);
    cursor.moveToFirst();
    int count = cursor.getInt(0);
    cursor.close();
    return count;
}

From source file:Main.java

/**
 * Generate a unicast MAC address./* w w w. j  a  v a  2  s.  c  o  m*/
 * A unicast MAC address is the one with an even second hex.
 * i.e. x[0,2,4,6,8,A,C,E]:xx:xx:xx:xx:xx
 * 
 * @return Unicast MAC address
 */
public static String generateRandomMACAddress() {
    Random r = new Random();
    StringBuffer sb = new StringBuffer();
    sb.append(Integer.toHexString(r.nextInt(16)));
    int i = r.nextInt(16);
    while (i % 2 != 0)
        i = r.nextInt(16);
    sb.append(Integer.toHexString(i));
    while (sb.length() <= 12)
        sb.append(Integer.toHexString(r.nextInt()));
    String address = prepareMACAddress(sb.subSequence(0, 12).toString());
    if (address.equals("ff:ff:ff:ff:ff:ff"))
        return generateRandomMACAddress();
    return address;
}

From source file:Main.java

public static String ipToString(int addr, String sep) {
    //myLog.l(Log.DEBUG, "IP as int: " + addr);
    if (addr > 0) {
        StringBuffer buf = new StringBuffer();
        buf.append(byteOfInt(addr, 0)).append(sep).append(byteOfInt(addr, 1)).append(sep)
                .append(byteOfInt(addr, 2)).append(sep).append(byteOfInt(addr, 3));

        return buf.toString();
    } else {/* w  ww .  j a  va2  s  .co m*/
        return null;
    }
}

From source file:Main.java

static String makeXMLOpenElement(String elementName, String[][] attributes) {
    StringBuffer sb = new StringBuffer();
    sb.append("<");
    sb.append(elementName);//from ww  w  .jav  a 2  s .  c om
    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 toString(Field field) {
    StringBuffer sb = new StringBuffer(field.getName());
    sb.append("(").append(field.getName()).append(")");
    return sb.toString();
}

From source file:Main.java

private static String getString(byte[] b) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < b.length; i++) {
        sb.append(b[i]);
    }/*from   w  w w .  ja  va  2s .  c o m*/
    return sb.toString();
}

From source file:Main.java

static String bytesToString(byte[] bytes) {
    StringBuffer sb = new StringBuffer();
    for (byte b : bytes) {
        sb.append(String.format("%02x ", b & 0xFF));
    }//from www.ja  va2 s.  c o  m
    return sb.toString();
}