Example usage for java.lang StringBuilder toString

List of usage examples for java.lang StringBuilder toString

Introduction

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

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public String toString() 

Source Link

Usage

From source file:Util.java

/**
 * Pads the string with zeros on the left until it has the requested size.
 *
 * @param binaryNumber//from ww w  .  j ava 2s  .  com
 * @param size
 * @return
 */
public static String padBinaryString(String binaryNumber, int size) {
    int stringSize = binaryNumber.length();
    if (stringSize >= size) {
        return binaryNumber;
    }

    int numZeros = size - stringSize;
    StringBuilder builder = new StringBuilder(numZeros);
    for (int i = 0; i < numZeros; i++) {
        builder.append(ZERO);
    }

    return builder.toString() + binaryNumber;
}

From source file:Main.java

public static ByteBuffer getDataBuffer() {
    String lineSeparator = System.getProperty("line.separator");
    StringBuilder sb = new StringBuilder();
    sb.append("test");
    sb.append(lineSeparator);/*from   w w w.  jav a 2 s . c o m*/
    sb.append("test");
    sb.append(lineSeparator);
    String str = sb.toString();
    Charset cs = Charset.forName("UTF-8");
    ByteBuffer bb = ByteBuffer.wrap(str.getBytes(cs));
    return bb;
}

From source file:Main.java

/**
 * Convert hex string to byte[]/*from  w  ww . j  a v a  2  s.c  o  m*/
 *
 * @param hexString the hex string
 * @return byte[]
 */
public static byte[] hexStringToBytes(String hexString) {
    if (hexString == null || hexString.equals("")) {
        return null;
    }

    if (hexString.length() % 2 != 0) {
        StringBuilder stringBuilder = new StringBuilder(hexString);
        stringBuilder.insert(hexString.length() - 1, "0");
        hexString = stringBuilder.toString();
        System.out.println("new hex string------------------->" + hexString);
    }

    hexString = hexString.toUpperCase();
    int length = hexString.length() / 2;
    char[] hexChars = hexString.toCharArray();
    byte[] d = new byte[length];
    for (int i = 0; i < length; i++) {
        int pos = i * 2;
        d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
    }
    return d;
}

From source file:org.projecthdata.social.api.connect.HDataServiceProvider.java

/**
 * Get the authorization URL, based on the url for an EHR. This will be the
 * host of the EHR with the path /auth/dialog
 * /*from  ww  w .  j  a v a2s .  co m*/
 * @param ehrUrl
 * @return
 */
public static String getAuthorizeUrl(String ehrUrl) {
    StringBuilder builder = getBaseUrl(ehrUrl);
    builder.append(authorizeUrlPath);
    return builder.toString();
}

From source file:Main.java

public static String getStringFromFile(Context context, String fileName) throws IOException {
    InputStream inputStream = context.getAssets().open(fileName);
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    StringBuilder sb = new StringBuilder();
    String line;//from w w w . ja  v  a 2  s.c om
    while ((line = reader.readLine()) != null) {
        sb.append(line).append('\n');
    }
    return sb.toString();
}

From source file:Main.java

public static String formatAmount(int amount, String currency) {
    if ("HUF".equals(currency)) {
        return String.format(Locale.US, "%d " + currency, amount);
    } else {/* ww  w. ja  va2  s  .  co  m*/
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("%d,%02d ");
        stringBuilder.append(currency);
        return String.format(Locale.US, stringBuilder.toString(), amount / 100, amount % 100);
    }
}

From source file:Main.java

public static String randomBytesAsHexString(int byteCount) {
    SecureRandom rng = new SecureRandom();
    byte[] randomData = new byte[byteCount];

    rng.nextBytes(randomData);/*w w w.  j  a  va  2s . co  m*/

    StringBuilder builder = new StringBuilder();

    for (byte byteValue : randomData) {
        builder.append(String.format("%02x", byteValue));
    }

    return builder.toString();
}

From source file:Main.java

static String toHexString(byte[] bytes) {
    if (bytes == null) {
        return null;
    }//from  w  w w  .j  ava 2s.  co m
    StringBuilder sb = new StringBuilder(bytes.length * 2);
    for (byte b : bytes) {
        sb.append(hexDigits[(b >> 4) & 15]).append(hexDigits[b & 15]);
    }
    return sb.toString();
}

From source file:org.geowebcache.diskquota.jdbc.ParametricDataAccessException.java

private static String buildMessage(String sql, Map<String, Object> params) {
    StringBuilder sb = new StringBuilder();
    sb.append("Failed to execute statement " + sql);
    sb.append(" with params: " + params);

    return sb.toString();
}

From source file:Main.java

public static String fromHexString(String hex) {
    StringBuilder str = new StringBuilder();
    for (int i = 0; i < hex.length(); i += 2) {
        str.append((char) Integer.parseInt(hex.substring(i, i + 2), 16));
    }//from w w w  .j a v a2 s  .c  om
    return str.toString();
}