Example usage for java.lang StringBuilder StringBuilder

List of usage examples for java.lang StringBuilder StringBuilder

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public StringBuilder() 

Source Link

Document

Constructs a string builder with no characters in it and an initial capacity of 16 characters.

Usage

From source file:Main.java

public static String bytes2Bits(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (byte aByte : bytes) {
        for (int j = 7; j >= 0; --j) {
            sb.append(((aByte >> j) & 0x01) == 0 ? '0' : '1');
        }/*  w  ww  .  ja v  a 2  s.co m*/
    }
    return sb.toString();
}

From source file:Main.java

public static String buildMessageHtml(String message) {
    StringBuilder sb = new StringBuilder();
    sb.append("<article><section><div class=\"align-center\"><p class=\"text-x-small\">").append(message)
            .append("</p></div></section></article>");
    return sb.toString();
}

From source file:Main.java

public static String hexToString(String hex) {
    StringBuilder sb = new StringBuilder();
    char[] hexData = hex.toCharArray();
    for (int count = 0; count < hexData.length - 1; count += 2) {
        int firstDigit = Character.digit(hexData[count], 16);
        int lastDigit = Character.digit(hexData[count + 1], 16);
        int decimal = firstDigit * 16 + lastDigit;
        sb.append((char) decimal);
    }/*w w w  .ja v a  2  s. co  m*/
    return sb.toString();
}

From source file:Main.java

public static String escapeXml(String payload) {
    StringBuilder out = new StringBuilder();
    for (int i = 0; i < payload.length(); i++) {
        char c = payload.charAt(i);
        if ((c == 0x9) || (c == 0xA) || (c == 0xD) || ((c >= 0x20) && (c <= 0xD7FF))
                || ((c >= 0xE000) && (c <= 0xFFFD)) || ((c >= 0x10000) && (c <= 0x10FFFF)))
            out.append(c);/*  w ww  .j  av a2  s.  c om*/
    }
    return out.toString();
}

From source file:Main.java

public static String tohex(byte[] buffer) {
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < buffer.length; ++i)
        result.append(hexToAscii((buffer[i] >>> 4) & 0xF)).append(hexToAscii(buffer[i] & 0x0F));
    return result.toString();
}

From source file:Main.java

public static String makeSplitParams(long... ids) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < ids.length; i++) {
        sb.append(ids[i]);/* ww  w  .  ja va  2s  .  c  o m*/
        if (!(i == ids.length - 1))
            sb.append(",");
    }
    return sb.toString();
}

From source file:Main.java

public static StringBuilder m820a(byte b) {
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < 8; i++) {
        stringBuilder.append((b >> (8 - (i + 1))) & 1);
    }/*from ww  w  .  ja  v a 2 s. c om*/
    stringBuilder.trimToSize();
    return stringBuilder;
}

From source file:Main.java

private static String byte2hex(byte[] bytes) {
    StringBuilder sign = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        String hex = Integer.toHexString(bytes[i] & 0xFF);
        if (hex.length() == 1) {
            sign.append("0");
        }/*from   w w w. j  a  v  a2s. c  o m*/
        sign.append(hex.toUpperCase());
    }
    return sign.toString();
}

From source file:Main.java

public static String bytesToHexString(byte[] data) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < data.length; ++i) {
        int val = data[i] & 0xFF;
        sb.append(String.format("%02x", val));
    }/* w w w .  j  av a 2  s .  c  om*/
    return sb.toString();
}

From source file:Main.java

public static String hexToAscii(String hexValue) {
    StringBuilder output = new StringBuilder();
    for (int i = 0; i < hexValue.length(); i += 2) {
        String str = hexValue.substring(i, i + 2);
        output.append((char) Integer.parseInt(str, 16));
    }/*ww  w .  j a  v  a2 s.c  o m*/
    return output.toString();
}