Example usage for java.lang StringBuffer toString

List of usage examples for java.lang StringBuffer toString

Introduction

In this page you can find the example usage for java.lang StringBuffer toString.

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public synchronized String toString() 

Source Link

Usage

From source file:Main.java

public static String getColorString(Color color) {
    StringBuffer buffer = new StringBuffer("#"); //$NON-NLS-1$
    appendComponent(buffer, color.getRed());
    appendComponent(buffer, color.getGreen());
    appendComponent(buffer, color.getBlue());
    return buffer.toString();
}

From source file:Main.java

/** @deprecated */
public static String join(String delim, Object[] col) {
    if (col == null || col.length == 0)
        return "";
    StringBuffer b = new StringBuffer("");

    for (int x = 0; x < col.length; x++) {
        b.append("" + col[x]);
        if (x < (col.length - 1))
            b.append(delim);//ww w . j  a  v a 2 s  . com
    }
    return b.toString();
}

From source file:Main.java

/**
 * 7 => 00000111//w  w w.  java 2s.c  om
 *
 * @param src
 * @return
 */
public static String getBinaryString(byte src) {
    String binaryString = Integer.toBinaryString(src);
    if (binaryString.length() > Byte.SIZE) {
        binaryString = binaryString.substring(binaryString.length() - Byte.SIZE);
    } else {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < Byte.SIZE - binaryString.length(); i++) {
            sb.append("0");
        }
        binaryString = sb.toString() + binaryString;
    }
    return binaryString;
}

From source file:Main.java

/**
 * Slurps a Reader into a String and strips the character 0.
 * @param in//from w  ww .j av  a2 s .c o  m
 * @throws IOException
 */
public static String readerToPrintableCharString(final Reader in) throws IOException {
    StringBuffer out = new StringBuffer();
    int n;
    while ((n = in.read()) != -1) {
        if (n != 0) {
            char c = (char) n;
            out.append(c);
        }
    }
    return out.toString();
}

From source file:Main.java

public static String encode(String s) {
    int length = s.length();
    StringBuffer buffer = new StringBuffer(length * 2);
    for (int i = 0; i < length; i++) {
        char c = s.charAt(i);
        buffer.append(encode(c));// w ww.  j  a  v a  2s.  c om
    }

    return buffer.toString();
}

From source file:Main.java

public static String bcd2Str(byte[] bytes) {
    StringBuffer temp = new StringBuffer(bytes.length * 2);
    for (int i = 0; i < bytes.length; i++) {
        temp.append((byte) ((bytes[i] & 0xf0) >>> 4));
        temp.append((byte) (bytes[i] & 0x0f));
    }/*ww  w.  j av a  2s .  c o  m*/
    return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1)
            : temp.toString();
}

From source file:Main.java

public static String Bcd2Str(byte[] bytes) {
    StringBuffer temp = new StringBuffer(bytes.length * 2);

    for (int i = 0; i < bytes.length; i++) {
        temp.append((byte) ((bytes[i] & 0xf0) >>> 4));
        temp.append((byte) (bytes[i] & 0x0f));
    }//from ww  w. ja  va 2 s.co  m
    return temp.toString();
}

From source file:com.impetus.kundera.graph.ObjectGraphUtils.java

/**
 * /*from   w  w w .java 2s . c  o m*/
 * @param pk
 * @param objectClass
 * @return
 */
public static String getNodeId(Object pk, Class<?> objectClass) {
    StringBuffer strBuffer = new StringBuffer(objectClass.getName());
    strBuffer.append(Constants.NODE_ID_SEPARATOR);
    strBuffer.append(pk);
    return strBuffer.toString();
}

From source file:Main.java

public static String getOddOrEvenString(String src, int type) {
    if (src == null || src.length() <= 0) {
        return "";
    }// w w w  .j  a  v  a2 s . c om
    StringBuffer sb = new StringBuffer();
    int sbLength = src.length();
    for (int i = 0; i < sbLength; i++) {
        if (i % 2 == type) {
            sb.append(src.charAt(i));
        }
    }
    return sb.toString();
}

From source file:Main.java

public static String bcd2StrIn(byte[] bytes) {
    StringBuffer temp = new StringBuffer(bytes.length * 2);

    for (int i = 0; i < bytes.length; i++) {
        temp.append((byte) ((bytes[i] & 0xf0) >>> 4));
        temp.append((byte) (bytes[i] & 0x0f));
    }/*from   w w w  .  j  av  a2 s  .c om*/
    return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1)
            : temp.toString();
}