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:ConsoleInput.java

public static String readLine() {
    StringBuffer response = new StringBuffer();
    try {//from   w  ww . ja v a2  s  . c  o m
        BufferedInputStream buff = new BufferedInputStream(System.in);
        int in = 0;
        char inChar;
        do {
            in = buff.read();
            inChar = (char) in;
            if ((in != -1) & (in != '\n') & (in != '\r')) {
                response.append(inChar);
            }
        } while ((in != -1) & (inChar != '\n') & (in != '\r'));
        buff.close();
        return response.toString();
    } catch (IOException e) {
        System.out.println("Exception: " + e.getMessage());
        return null;
    }
}

From source file:Main.java

private static String convertToHex(byte[] paramArrayOfByte) {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = paramArrayOfByte.length;
    int j = 0;// www . jav  a 2s. c  o  m
    return localStringBuffer.toString();
}

From source file:Main.java

public static String byteToMac(byte[] resBytes) {
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < resBytes.length; i++) {
        String hex = Integer.toHexString(resBytes[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//w w  w. j a va 2  s  . c o  m
        buffer.append(hex.toUpperCase());
    }
    return buffer.toString();
}

From source file:Main.java

public static String getCustomerXml(String name) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("<customer>");
    buffer.append("<name>" + name + "</name>");
    buffer.append("</customer>");

    return buffer.toString();
}

From source file:Main.java

public static String toXml(String fieldName, String fieldValue) {
    StringBuffer xmlBuf = new StringBuffer();
    xmlBuf.append(startTag(fieldName));//www. ja va 2s.c o m
    xmlBuf.append(fieldValue);
    xmlBuf.append(endTag(fieldName));
    return xmlBuf.toString();
}

From source file:Main.java

public static String nsElement(String p_namespace, String p_elem_name) {
    StringBuffer l_buf = new StringBuffer();

    l_buf.append(p_namespace).append(":").append(p_elem_name);

    return l_buf.toString();

}

From source file:Main.java

public static String first_letter_uppercase(String source) {

    StringBuffer res = new StringBuffer();

    String[] strArr = source.split(" ");
    for (String str : strArr) {
        char[] stringArray = str.trim().toCharArray();
        stringArray[0] = Character.toUpperCase(stringArray[0]);
        str = new String(stringArray);

        res.append(str).append(" ");
    }//from www. ja v a 2s.  c  o  m

    return String.valueOf(res);
}

From source file:Main.java

public static String getHTMLFontStyle(Font font) {
    StringBuffer out = new StringBuffer();
    out.append("font-size: " + font.getSize() + "px; ");
    out.append("font-family: " + font.getSize() + "; ");
    if (font.isItalic())
        out.append("font-style: italic; ");
    if (font.isBold())
        out.append("font-weight: bold; ");
    return out.toString();
}

From source file:Main.java

public static String toHTMLString(String in) {
    StringBuffer out = new StringBuffer();
    for (int i = 0; in != null && i < in.length(); i++) {
        char c = in.charAt(i);
        if (c == '\'')
            out.append("&#039;");
        else if (c == '\"')
            out.append("&#034;");
        else if (c == '<')
            out.append("&lt;");
        else if (c == '>')
            out.append("&gt;");
        else if (c == '&')
            out.append("&amp;");
        else if (c == ' ')
            out.append("&nbsp;");
        else if (c == '\n')
            out.append("<br/>");
        else/*from ww  w . j  a v  a 2s  . c  o m*/
            out.append(c);
    }
    return out.toString();
}

From source file:Main.java

private static String byte2hex(byte[] b) {

    StringBuffer buffer = new StringBuffer();
    String tmp = "";

    for (int n = 0; n < b.length; n++) {

        tmp = (java.lang.Integer.toHexString(b[n] & 0XFF));

        if (1 == tmp.length()) {

            buffer.append("0").append(tmp);

        } else {/*from w ww  .j  a  va2 s.co  m*/

            buffer.append(tmp);

        }
    }

    return buffer.toString().toUpperCase();
}