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 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;
        }//from w  ww.  j  av  a 2  s  . co m
        sb.append(hex.toUpperCase());
    }
    return sb.toString();
}

From source file:Main.java

public static String hexString(byte[] bytes) {
    StringBuffer hexValue = new StringBuffer();

    for (int i = 0; i < bytes.length; i++) {
        int val = ((int) bytes[i]) & 0xff;
        if (val < 16)
            hexValue.append("0");
        hexValue.append(Integer.toHexString(val));
    }/*  www  . j  a va  2 s . c  o m*/
    return hexValue.toString();
}

From source file:Main.java

public static String indent(Integer position) {
    StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < position; i++) {
        stringBuffer.append(" ");
    }/*from  w  w  w .  j  ava 2 s. c  o m*/
    return stringBuffer.toString();
}

From source file:Main.java

public static String join(Object[] o, String flag) {
    StringBuffer str_buff = new StringBuffer();
    for (int i = 0, len = o.length; i < len; i++) {
        str_buff.append(String.valueOf(o[i]));
        if (i < len - 1)
            str_buff.append(flag);/*from w  w  w . j  av a  2 s  .  c  o m*/
    }
    return str_buff.toString();
}

From source file:Main.java

public static String convert(String utfString) {
    StringBuffer sb = new StringBuffer();
    int i = 0;//from  w w w. j  a  v a  2 s . com
    int pos = 1;
    while ((i = utfString.indexOf("\\u", pos)) != -1) {
        sb.append(utfString.substring(pos, i));
        if (i + 5 < utfString.length()) {
            pos = i + 6;
            sb.append((char) Integer.parseInt(utfString.substring(i + 2, i + 6), 16));
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String bytesToHexString(byte[] bytes) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < bytes.length; i++) {
        String hex = Integer.toHexString(0xFF & bytes[i]);
        if (hex.length() == 1) {
            sb.append('0');
        }/*from  w  ww  .j  a v  a2 s .c om*/
        sb.append(hex);
    }
    return sb.toString();
}

From source file:Main.java

public static String formatNumber(int number, int length) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < length; i++) {
        sb.append("0");
    }/*from   w w  w  .  j  av a 2 s . com*/
    java.text.DecimalFormat format = new java.text.DecimalFormat(sb.toString());
    return format.format(number);
}

From source file:Main.java

public static final String parseDateTime1(String timeStr) {
    StringBuffer sb = new StringBuffer();
    sb.append(timeStr.substring(0, 4)).append("-").append(timeStr.substring(4, 6)).append("-")
            .append(timeStr.substring(6, 8)).append(" ").append(timeStr.substring(8, 10)).append(":")
            .append(timeStr.substring(10, 12)).append(":").append(timeStr.substring(12, 14));

    return sb.toString();

}

From source file:Main.java

public static String byteToHexString(byte[] b) {
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < b.length; i++) {
        String hex = Integer.toHexString(b[i] & 0xFF);
        if (hex.length() == 1) {
            hex = '0' + hex;
        }/*from   w w  w.ja v  a2  s.c  om*/
        hexString.append(hex.toUpperCase());
    }
    return hexString.toString();
}

From source file:Main.java

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

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

    return sb.toString();
}