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

private static String createLog(String log) {
    StringBuffer buffer = new StringBuffer();
    buffer.append(methodName);//from  w  w  w .j a  v  a2s . com
    buffer.append("(").append(className).append(":").append(lineNumber).append(")");
    buffer.append(log);
    return buffer.toString();
}

From source file:Main.java

public static String parseMillisecond(long millisecond) {
    StringBuffer sb = new StringBuffer();
    int hour = (int) (millisecond / 3600000);
    if (hour >= 10) {
        sb.append(hour);/*from  w  ww .  j a  v  a  2s  . c  o  m*/
    } else {
        sb.append("0" + hour);
    }
    sb.append(":");
    int min = (int) ((millisecond - hour * 3600000) / 60000);
    if (min >= 10) {
        sb.append(min);
    } else {
        sb.append("0" + min);
    }
    sb.append(":");
    int second = (int) ((millisecond - hour * 3600000 - min * 60000) / 1000);
    if (second >= 10) {
        sb.append(second);
    } else {
        sb.append("0" + second);
    }
    sb.append(".");
    int milli = (int) (millisecond % 1000);
    if (milli >= 100) {
        sb.append(milli);
    } else if (milli >= 10) {
        sb.append("0" + milli);
    } else {
        sb.append("00" + milli);
    }
    return sb.toString();
}

From source file:Main.java

protected static String getURL(String ipaddr, String path, String params) {
    StringBuffer sb = new StringBuffer();
    sb.append("http://");
    sb.append(ipaddr);/*from w w w . j a v a2  s .c om*/
    sb.append(":");
    sb.append(String.valueOf(WebServerPort));
    sb.append(path);
    if (params != null) {
        sb.append("?");
        sb.append(params);
    }
    return sb.toString();
}

From source file:Main.java

@SuppressLint("DefaultLocale")
public static String parseByte2HexStr(byte buf[]) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < buf.length; i++) {
        String hex = Integer.toHexString(buf[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }//  w  w  w. ja va 2 s.c  om
        sb.append(hex.toUpperCase());
    }
    return sb.toString();
}

From source file:Main.java

private static String arrayToString(JSONArray ar) throws JSONException {
    StringBuffer bfr = new StringBuffer();
    for (int i = 0; i < ar.length(); i++) {
        bfr.append(ar.getString(i));/*from  www  .ja v  a  2  s . co  m*/
        if (i != ar.length() - 1)
            bfr.append(",");
    }
    return bfr.toString();
}

From source file:Main.java

public static String filterWhiteSpace(char ch[], int start, int length) {
    int end = start + length - 1;
    StringBuffer buf = new StringBuffer();
    char cur_char;
    int index = start;
    while (index <= end) {
        cur_char = ch[index];
        switch (cur_char) {
        case '\n':
        case '\r':
        case '\t':
        case '\f':
        case ' ':
            break;
        default://w w w. j a v  a  2 s. c o m
            buf.append(cur_char);
            break;
        }
        index++;
    }
    return buf.toString();
}

From source file:Main.java

public static String string2Json(String s) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        switch (c) {
        case '\\':
            sb.append("\\\\");
            break;
        case '/':
            sb.append("\\/");
            break;
        case '\b':
            sb.append("\\b");
            break;
        case '\f':
            sb.append("\\f");
            break;
        case '\n':
            sb.append("\\n");
            break;
        case '\r':
            sb.append("\\r");
            break;
        case '\t':
            sb.append("\\t");
            break;
        default://from  ww w  .  j a  v a 2  s.  c  o m
            sb.append(c);
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String generateRandomUTDID() {
    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0;//from  w w w .ja v a2  s.c  om
    while (i < 24) {
        localStringBuffer.append((char) (random.nextInt(25) + 65));
        i += 1;
    }
    return localStringBuffer.toString();
}

From source file:esg.security.yadis.XrdsDoc.java

/**
 * TODO: move this test harness to unit tests
 * @param args//from  w ww .  j  av a  2  s  .c  om
 * @throws IOException 
 * @throws SAXException 
 * @throws ParserConfigurationException 
 * @throws XPathExpressionException 
 * @throws XrdsParseException 
 */
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException,
        XPathExpressionException, XrdsParseException {

    String yadisDocFilePath = "/home/pjkersha/workspace/EsgYadisParser/data/yadis.xml";
    XrdsDoc yadisParser = new XrdsDoc();
    StringBuffer contents = new StringBuffer();

    FileReader fileReader = new FileReader(yadisDocFilePath);
    BufferedReader in = new BufferedReader(fileReader);
    try {
        String text = null;

        while ((text = in.readLine()) != null) {
            contents.append(text);
            contents.append(System.getProperty("line.separator"));
        }
        in.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    String yadisDocContent = contents.toString();
    yadisParser.parse(yadisDocContent);
}

From source file:Main.java

/**
 * Generate a random message-id header for locally-generated messages.
 *///  w w  w . j av  a2s. c o  m
public static String generateMessageId() {
    StringBuffer sb = new StringBuffer();
    sb.append("<");
    for (int i = 0; i < 24; i++) {
        sb.append(Integer.toString((int) (Math.random() * 35), 36));
    }
    sb.append(".");
    sb.append(Long.toString(System.currentTimeMillis()));
    sb.append("@email.android.com>");
    return sb.toString();
}