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

/**
 * Get a byte in a printable binary form.
 *
 * @param b The byte to be writen./*from  w w w  . j  a v a2s .  co m*/
 * @return A String representation of the byte.
 */
public static String writeBits(byte b) {
    StringBuffer stringBuffer = new StringBuffer();
    int bit;
    for (int i = 7; i >= 0; i--) {
        bit = (b >>> i) & 0x01;
        stringBuffer.append(bit);
    }
    return stringBuffer.toString();
}

From source file:Main.java

public static String toString(Enumeration/*<String>*/ enumer, String separator) {
    if (separator == null)
        separator = ","; //NOI18N
    StringBuffer buf = new StringBuffer();
    while (enumer.hasMoreElements()) {
        if (buf.length() != 0)
            buf.append(separator);//from  w  ww.ja  v a2 s. c om
        buf.append(enumer.nextElement());
    }
    return buf.toString();
}

From source file:Main.java

private static String readFileAsString(File file) throws IOException {
    String line;/*from  ww w .j a v  a 2  s .c o m*/
    StringBuffer sb = new StringBuffer();
    BufferedReader br = new BufferedReader(new FileReader(file));
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }

    br.close();
    return sb.toString();
}

From source file:Main.java

private static String arrayToString(List<String> arg) {
    int i;/* w w  w  .  ja  v a2s .  c o m*/
    String str = "";
    StringBuffer buf = new StringBuffer();
    for (i = 0; i < arg.size(); i++) {
        if (i != 0) {
            buf.append(",");
        }
        buf.append(arg.get(i));
    }
    str = buf.toString();
    return str;
}

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  ww  .  j  a  va  2s. com*/
    }
    return str_buff.toString();
}

From source file:Main.java

private static String lowerCaseAttributes(String formatted) {
    Matcher m = ID_PATTERN.matcher(formatted);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String text = m.group();//w ww  .j a va2  s. co  m
        m.appendReplacement(sb, Matcher.quoteReplacement(text.toLowerCase()));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:Main.java

public static String getStringToNumber(String value) {
    StringBuffer sbu = new StringBuffer();
    char[] chars = value.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        {//from  w  ww .  ja v a  2s  . c  om
            sbu.append(msg.get("" + chars[i]));
        }
    }
    return sbu.toString();
}

From source file:Main.java

public static String Bcd2Str_0(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));
    }//w  w w .  ja v  a 2 s.c o m

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

From source file:Main.java

public static String readAssetsByName(Context context, String name, String encoding) {
    String text = null;/*from   w ww . ja v a2s  .c  o m*/
    InputStreamReader inputReader = null;
    BufferedReader bufReader = null;
    try {
        inputReader = new InputStreamReader(context.getAssets().open(name));
        bufReader = new BufferedReader(inputReader);
        String line = null;
        StringBuffer buffer = new StringBuffer();
        while ((line = bufReader.readLine()) != null) {
            buffer.append(line);
        }
        text = new String(buffer.toString().getBytes(), encoding);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (bufReader != null) {
                bufReader.close();
            }
            if (inputReader != null) {
                inputReader.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return text;
}

From source file:Main.java

public static String readRawByName(Context context, int id, String encoding) {
    String text = null;/*  ww w.java2s . c om*/
    InputStreamReader inputReader = null;
    BufferedReader bufReader = null;
    try {
        inputReader = new InputStreamReader(context.getResources().openRawResource(id));
        bufReader = new BufferedReader(inputReader);
        String line = null;
        StringBuffer buffer = new StringBuffer();
        while ((line = bufReader.readLine()) != null) {
            buffer.append(line);
        }
        text = new String(buffer.toString().getBytes(), encoding);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (bufReader != null) {
                bufReader.close();
            }
            if (inputReader != null) {
                inputReader.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return text;
}