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 byteToChar(byte[] ucPtr) {
    final StringBuffer sb = new StringBuffer();
    for (int i = 0; i < ucPtr.length; ++i) {
        char c = (char) ucPtr[i];
        sb.append(String.valueOf(c));
    }//from   www.  j a  v a  2  s .c  o  m
    return sb.toString();
}

From source file:Main.java

public static String toHexString(byte[] bytes) {
    StringBuffer buffer = new StringBuffer();
    for (byte i : bytes) {
        buffer.append(Character.forDigit((i >> 4) & 0xF, 16));
        buffer.append(Character.forDigit((i & 0xF), 16));
    }//from w w  w  . ja  v  a 2s.c  o m

    return buffer.toString();
}

From source file:Main.java

public static String getByteArray(byte[] data) {
    final StringBuffer sb = new StringBuffer();
    for (int i = 0; i < data.length; i++) {
        sb.append(data[i] + ",");
    }//from  w w  w. j av a  2  s .c o  m

    return sb.toString().substring(0, sb.length() - 1);
}

From source file:Main.java

public static String byte2String(byte[] bytes) {
    StringBuffer buff = new StringBuffer();
    for (int i = 0; i < bytes.length; ++i) {
        if (i != 0) {
            buff.append(", ");
        }/* w ww  .j av  a  2 s . c  o m*/
        buff.append(bytes[i]);
    }
    return buff.toString();
}

From source file:Main.java

public static String insertSpace(String str) {
    String chr;/*from   w w  w.java2  s . co  m*/
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
        chr = String.valueOf(str.charAt(i));
        if ((i > 0) && (chr.matches("[A-Z]")))
            buffer.append(" ");
        buffer.append(chr);
    }
    return buffer.toString();
}

From source file:Main.java

public static String getHexString(byte[] messageid) {
    StringBuffer sb = new StringBuffer();
    if (messageid.length > 0) {
        for (byte b : messageid) {
            sb.append(String.format("%02X", b));
        }/*from w  ww  .j a va  2  s  . c om*/
    }
    return sb.toString();
}

From source file:Main.java

public static String makeTimeString(long milliSecs) {
    StringBuffer sb = new StringBuffer();
    long m = milliSecs / (60 * 1000);
    sb.append(m < 10 ? "0" + m : m);
    sb.append(":");
    long s = (milliSecs % (60 * 1000)) / 1000;
    sb.append(s < 10 ? "0" + s : s);
    return sb.toString();
}

From source file:Main.java

public static String toHexString(final byte[] src) {
    StringBuffer buf = new StringBuffer();
    for (byte b : src) {
        String s = String.format("%02x", b & 0xff);
        buf.append(s).append(",");
    }/*from w  ww . ja va 2  s.c  o  m*/
    return buf.toString();
}

From source file:Main.java

public static String toHex(byte[] buf) {
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < buf.length; i++) {
        String h = Integer.toHexString(0xFF & buf[i]);
        while (h.length() < 2)
            h = "0" + h;

        hexString.append(h);/*  w  w  w.jav a  2s  .c o m*/
    }

    return hexString.toString();
}

From source file:Main.java

public static String toString(Object array[]) {
    StringBuffer sb = new StringBuffer();
    sb.append("[");
    for (int i = 0; i < array.length; i++) {
        sb.append(array[i]);//from   www.  j  a v a 2 s  .  c  o m
        if (i < array.length - 1)
            sb.append(",");
    }

    sb.append("]");
    return sb.toString();
}