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 asciiToString(byte[] arrayList) {
    StringBuffer sbu = new StringBuffer();
    for (int i = 0; i < arrayList.length; i++) {
        sbu.append((char) arrayList[i]);
    }/* w  ww .j  ava  2 s . c  o  m*/
    return sbu.toString();
}

From source file:Main.java

public static String toHexString(byte[] b) {
    StringBuffer buffer = new StringBuffer();
    if (b != null)
        for (int i = 0; i < b.length; ++i) {
            String s = Integer.toHexString(b[i] & 0xFF);
            if (s.length() == 1) {
                s = "0" + s;
            }//from   w  w w .j a v  a  2 s .c  o  m
            buffer.append(s + " ");
        }
    return buffer.toString();
}

From source file:Main.java

private static String padHex(String s, int i) {
    StringBuffer tmpBuffer = new StringBuffer();
    if (s.length() < i) {
        for (int j = 0; j < i - s.length(); j++) {
            tmpBuffer.append('0');
        }/*from   w ww . ja v a 2  s  .  c o  m*/
    }
    return tmpBuffer.toString();
}

From source file:Main.java

private static String getHexString(byte[] b) {
    StringBuffer strb = new StringBuffer();
    int temp;/*  w  w w.j a  va2s. c  o  m*/
    for (int i = 0; i < b.length; i++) {
        temp = 0xFF & b[i];
        if (temp <= 0xF) {
            strb.append('0');
        }
        strb.append(b[i]);
    }
    return strb.toString();
}

From source file:Main.java

public static String string2Unicode(String string) {
    StringBuffer unicode = new StringBuffer();
    for (int i = 0; i < string.length(); i++) {
        char c = string.charAt(i);
        unicode.append("\\" + "u" + Integer.toHexString(c));
    }/*w ww.  j  av  a2  s. c  o m*/
    return unicode.toString();
}

From source file:Main.java

public static String addGetString(String fieldName) {
    StringBuffer sb = new StringBuffer();
    if (fieldName.startsWith("is")) {
        return fieldName;
    }// w  ww  . ja  v  a2  s  . c  o  m
    sb.append("get");
    sb.append(fieldName.substring(0, 1).toUpperCase());
    sb.append(fieldName.substring(1));
    return sb.toString();
}

From source file:Main.java

public static String getASCII(int begin, int end) {
    StringBuffer sb = new StringBuffer();
    for (int i = begin; i < end; i++) {
        sb.append(i).append(":").append((char) i).append("/t");
        // sb.append((char) i).append("/t");  
        if (i % 10 == 0) {
            sb.append("/n");
        }//from  w w w.j  a v a  2  s  .co m
    }
    return sb.toString();
}

From source file:Main.java

public static final String arrayToString(byte[] bytes) {
    StringBuffer buff = new StringBuffer();
    for (int i = 0; i < bytes.length; i++) {
        buff.append(bytes[i] + " ");
    }//from w  w w.j  av  a  2 s  .com
    return buff.toString();
}

From source file:Main.java

public static String colorFont(String src, String color) {
    StringBuffer strBuf = new StringBuffer();

    strBuf.append("<font color=").append(color).append(">").append(src).append("</font>");
    return strBuf.toString();
}

From source file:Main.java

public static String toString(byte[] theByteArray) {
    StringBuffer out = new StringBuffer();
    for (int i = 0; i < theByteArray.length; i++) {
        String s = Integer.toHexString(theByteArray[i] & 0xff);
        if (s.length() < 2) {
            out.append('0');
        }/*from  www  .j av a 2 s  . c om*/
        out.append(s).append(' ');
    }
    return out.toString();
}