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:edu.mit.media.funf.IOUtils.java

public static String httpGet(String uri, HttpParams params) {
    String responseBody = null;/*from  w  ww .  j  av a2  s. co m*/
    HttpClient httpclient = new DefaultHttpClient();
    StringBuilder uriBuilder = new StringBuilder(uri);
    HttpGet httpget = new HttpGet(uriBuilder.toString());
    if (params != null) {
        httpget.setParams(params);
    }
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        responseBody = httpclient.execute(httpget, responseHandler);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "HttpGet Error: ", e);
        responseBody = null;
    } catch (IOException e) {
        Log.e(TAG, "HttpGet Error: ", e);
        responseBody = null;
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
    return responseBody;
}

From source file:Main.java

/**
 * Combines strings into a string using {@link StringBuilder}. The default
 * capacity of the StringBuilder is 100. <br>
 * <br>//w ww . j a  v  a2s.c  o m
 * Use this method when make shell script, test case list and etc..
 * 
 * @param strings
 *            the strings to be combined into one
 * @return the combined string
 */
public static String combineStrings(String... strings) {
    StringBuilder stringBuilder = new StringBuilder(100);
    for (String string : strings) {
        stringBuilder.append(string);
    }
    return stringBuilder.toString();
}

From source file:Main.java

public static String bytesToHex(byte[] b) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < b.length; i++) {
        sb.append(byteToHex(b[i])).append(" ");
    }//  w  ww. j ava 2s.  co  m
    return sb.toString();
}

From source file:Main.java

public static String collectionToStr(Collection<?> collection) {
    if (collection != null) {
        StringBuilder sb = new StringBuilder();
        for (Object obj : collection) {
            sb.append(obj.toString());//from ww w . ja v  a2 s . co  m
        }
        return sb.toString();
    } else {
        return "";
    }
}

From source file:Main.java

public static String getRandomString(int length) {
    String retVal = "1234567890";
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < length; i++)
        sb.append(retVal.charAt(random.nextInt(retVal.length())));
    return sb.toString();
}

From source file:MD5StringUtil.java

public static String md5StringFor(String s) {
    final byte[] hash = digest.digest(s.getBytes());
    final StringBuilder builder = new StringBuilder();
    for (byte b : hash) {
        builder.append(Integer.toString(b & 0xFF, 16));
    }/* w ww  . j a  v a  2 s . c o  m*/
    return builder.toString();
}

From source file:Main.java

/**
 * Converts a byte[] to a hex string/*  ww  w  .  j  ava  2  s .c  o m*/
 *
 * @param byteArray Array to be converted
 * @return Array as a hex string
 */
public static String byteArrayToHexString(byte[] byteArray) {
    final StringBuilder builder = new StringBuilder();
    for (byte b : byteArray) {
        builder.append(String.format("%02x", b));
    }
    return builder.toString();
}

From source file:Main.java

/**
 *
 * @param data/*from ww w.  ja v  a  2  s . com*/
 * @return
 */
public static String toUnifyId(byte[] data) {
    if (data == null || data.length == 0) {
        return "";
    }

    StringBuilder result = new StringBuilder();

    for (byte b : data) {
        result.append(String.format("%02X", b));
    }

    return result.toString();
}

From source file:com.espertech.esper.pattern.EvalStateNodePrinterVisitor.java

private static String indent(int level) {
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < level; i++) {
        buffer.append("  ");
    }/*from   w w  w  .  j a va  2 s .c  o  m*/
    return buffer.toString();
}

From source file:Main.java

public static String getStrings(Context c, int... id) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < id.length; i++)
        sb.append(c.getResources().getString(id[i]) + " ");
    return sb.toString();
}