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 fillStringOnTail(String strValue, char ch, int iSign) {
    try {/*from w  ww. j a v a  2  s .co  m*/
        StringBuffer strTemp = new StringBuffer();
        strTemp.append(strValue);
        int iDifference = iSign - strValue.length();
        if (iDifference <= 0)
            return strValue;
        for (int i = 0; i < iDifference; i++)
            strTemp.append(ch);
        return strTemp.toString();
    } catch (Exception ex) {
        return "";
    }
}

From source file:Main.java

public static String fillStringByBytes(String strValue, char ch, int iSign) {
    try {//from   w  w w  .  java2 s  .  c o  m
        StringBuffer strTemp = new StringBuffer();
        int iDifference = iSign - strValue.getBytes().length;
        if (iDifference <= 0)
            return strValue;
        for (int i = 0; i < iDifference; i++)
            strTemp.append(ch);
        strTemp.append(strValue);
        return strTemp.toString();
    } catch (Exception ex) {
        return "";
    }
}

From source file:Main.java

public static String byteArrayToHexString(byte[] array) {
    StringBuffer hexString = new StringBuffer();
    for (byte b : array) {
        int intVal = b & 0xff;
        if (intVal < 0x10)
            hexString.append("0");
        hexString.append(Integer.toHexString(intVal));
    }//from ww w .  j a  va  2 s.c om
    return hexString.toString();
}

From source file:Main.java

public static String mailToXML(String sendTo, String subject, String content, String from) {
    StringBuffer sbRoot = new StringBuffer();
    addReportRootHead(sbRoot);/*from  www .j  a va  2s .co m*/
    addReportRootNode(sbRoot, "msgtype", "email");
    addReportRootNode(sbRoot, "sendTo", sendTo);
    addReportRootNode(sbRoot, "subject", subject);
    addReportRootNode(sbRoot, "content", content);
    addReportRootNode(sbRoot, "from", from);
    addReportRootTail(sbRoot);
    return sbRoot.toString();
}

From source file:Main.java

public static String byteToHexString(byte[] b) {
    StringBuffer hexString = new StringBuffer();
    for (byte b2 : b) {
        String hex = Integer.toHexString(b2 & MotionEventCompat.ACTION_MASK);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//  w  ww .  j  av  a2  s  . c om
        hexString.append(hex.toLowerCase());
    }
    return hexString.toString();
}

From source file:Main.java

public static String getAttAsString(final String name, final String val) {

    StringBuffer sb = new StringBuffer();
    sb.append(" " + name + "=\"" + val + "\"");

    return sb.toString();
}

From source file:Main.java

public static String xmlize(String s) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s.length(); ++i) {
        char c = s.charAt(i);
        switch (c) {
        case '&':
            sb.append("&amp;");
            break;
        case '<':
            sb.append("&laquo;");
            break;
        case '>':
            sb.append("&raquo;");
            break;
        case '"':
            sb.append("&quot;");
            break;
        default://from   w w  w  .  ja  v  a2s  .  com
            sb.append(c);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String getAddressXml(String street, String city, String state, String zip, String phone) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("<address>");
    buffer.append("<street>" + street + "</street>");
    buffer.append("<city>" + city + "</city>");
    buffer.append("<state>" + state + "</state>");
    buffer.append("<zip>" + zip + "</zip>");
    buffer.append("<phone>" + phone + "</phone>");
    buffer.append("</address>");

    return buffer.toString();
}

From source file:Main.java

public static String generateRandomUTDID() {
    StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < 24; i++) {
        stringBuffer.append((char) (random.nextInt(25) + 65));
    }/*from  ww  w.  ja v a2s .co m*/
    return stringBuffer.toString();
}

From source file:Main.java

public static String generateRandomString(int len) {
    String all = "0123456789abcdefghijklmnopqrstuvwxyz";
    StringBuffer s = new StringBuffer();
    for (int i = 0; i < len; i++) {
        s.append(all.charAt(getRandomNum(36)));
    }//from ww  w.j  a  v a  2 s  .  c  o m

    return s.toString();
}